• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

knowledgepixels / nanodash / 17605273807

10 Sep 2025 06:30AM UTC coverage: 13.688% (+0.02%) from 13.666%
17605273807

push

github

tkuhn
Incorporate MethodResultComponent into ItemListPanel

414 of 3898 branches covered (10.62%)

Branch coverage included in aggregate %.

1088 of 7075 relevant lines covered (15.38%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
src/main/java/com/knowledgepixels/nanodash/component/ItemListPanel.java
1
package com.knowledgepixels.nanodash.component;
2

3
import java.io.Serializable;
4
import java.util.List;
5
import java.util.function.Function;
6
import java.util.function.Supplier;
7

8
import org.apache.wicket.Component;
9
import org.apache.wicket.behavior.AttributeAppender;
10
import org.apache.wicket.markup.html.basic.Label;
11
import org.apache.wicket.markup.html.panel.Panel;
12
import org.nanopub.extra.services.ApiResponse;
13

14
import com.knowledgepixels.nanodash.ApiCache;
15
import com.knowledgepixels.nanodash.QueryRef;
16

17
public class ItemListPanel<T extends Serializable> extends Panel {
18

19
    public ItemListPanel(String markupId, String title, List<T> items, ComponentProvider<T> compProvider) {
20
        super(markupId);
×
21
        setOutputMarkupId(true);
×
22

23
        if (markupId.endsWith("-users")) {
×
24
            add(new AttributeAppender("class", " users"));
×
25
        }
26

27
        if (title.contains("  ")) {
×
28
            add(new Label("description", title.replaceFirst("^.*  ", "")));
×
29
            title = title.replaceFirst("  .*$", "");
×
30
        } else {
31
            add(new Label("description").setVisible(false));
×
32
        }
33
        add(new Label("title", title));
×
34
        add(new Label("button").setVisible(false));
×
35

36
        add(new ItemList<T>("itemlist", items, compProvider));
×
37
    }
×
38

39
    public ItemListPanel(String markupId, String title, QueryRef queryRef, ApiResultListProvider<T> resultListProvider, ComponentProvider<T> compProvider) {
40
        super(markupId);
×
41
        setOutputMarkupId(true);
×
42

43
        if (markupId.endsWith("-users")) {
×
44
            add(new AttributeAppender("class", " users"));
×
45
        }
46

47
        if (title.contains("  ")) {
×
48
            add(new Label("description", title.replaceFirst("^.*  ", "")));
×
49
            title = title.replaceFirst("  .*$", "");
×
50
        } else {
51
            add(new Label("description").setVisible(false));
×
52
        }
53
        add(new Label("title", title));
×
54
        add(new Label("button").setVisible(false));
×
55

56
        ApiResponse qResponse = ApiCache.retrieveResponse(queryRef);
×
57
        if (qResponse != null) {
×
58
            add(new ItemList<T>("itemlist", resultListProvider.apply(qResponse), compProvider));
×
59
        } else {
60
            add(new ApiResultComponent("itemlist", queryRef) {
×
61

62
                @Override
63
                public Component getApiResultComponent(String markupId, ApiResponse response) {
64
                    return new ItemList<T>(markupId, resultListProvider.apply(response), compProvider);
×
65
                }
66
            });
67

68
        }
69
    }
×
70

71
    public ItemListPanel(String markupId, String title, ReadyFunction readyFunction, ResultFunction<List<T>> resultFunction, ComponentProvider<T> compProvider) {
72
        super(markupId);
×
73
        setOutputMarkupId(true);
×
74

75
        if (markupId.endsWith("-users")) {
×
76
            add(new AttributeAppender("class", " users"));
×
77
        }
78

79
        if (title.contains("  ")) {
×
80
            add(new Label("description", title.replaceFirst("^.*  ", "")));
×
81
            title = title.replaceFirst("  .*$", "");
×
82
        } else {
83
            add(new Label("description").setVisible(false));
×
84
        }
85
        add(new Label("title", title));
×
86
        add(new Label("button").setVisible(false));
×
87

88
        if (readyFunction.get()) {
×
89
            add(new ItemList<T>("itemlist", resultFunction.get(), compProvider));
×
90
        } else {
91
            add(new MethodResultComponent<List<T>>("itemlist", readyFunction, resultFunction) {
×
92
                @Override
93
                public Component getResultComponent(String markupId, List<T> result) {
94
                    return new ItemList<T>(markupId, resultFunction.get(), compProvider);
×
95
                }
96
            });
97
        }
98
    }
×
99

100
    public abstract class MethodResultComponent<R> extends ResultComponent {
101

102
        private final transient Supplier<Boolean> readyFunction;
103
        private final transient Supplier<R> resultFunction;
104

105
        public MethodResultComponent(String id, ReadyFunction readyFunction, ResultFunction<R> resultFunction) {
×
106
            super(id);
×
107
            setOutputMarkupId(true);
×
108
            this.readyFunction = readyFunction;
×
109
            this.resultFunction = resultFunction;
×
110
        }
×
111

112
        /**
113
         * {@inheritDoc}
114
         */
115
        @Override
116
        protected boolean isContentReady() {
117
            return readyFunction.get();
×
118
        }
119

120
        /**
121
         * {@inheritDoc}
122
         */
123
        @Override
124
        public Component getLazyLoadComponent(String markupId) {
125
            R result = resultFunction.get();
×
126
            return getResultComponent(markupId, result);
×
127
        }
128

129
        public abstract Component getResultComponent(String markupId, R result);
130

131
    }
132

133
    public static interface ComponentProvider<T> extends Function<T, Component>, Serializable {
134
    }
135

136
    public static interface ApiResultListProvider<T> extends Function<ApiResponse, List<T>>, Serializable {
137
    }
138

139
    public static interface ReadyFunction extends Supplier<Boolean>, Serializable {
140
    }
141

142
    public static interface ResultFunction<X> extends Supplier<X>, Serializable {
143
    }
144

145
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc