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

knowledgepixels / nanodash / 17912021155

22 Sep 2025 10:12AM UTC coverage: 13.577% (-0.004%) from 13.581%
17912021155

push

github

tkuhn
feat: inline list panels

435 of 4040 branches covered (10.77%)

Branch coverage included in aggregate %.

1115 of 7376 relevant lines covered (15.12%)

0.67 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.ArrayList;
5
import java.util.List;
6
import java.util.function.Function;
7
import java.util.function.Supplier;
8

9
import org.apache.wicket.Component;
10
import org.apache.wicket.behavior.AttributeAppender;
11
import org.apache.wicket.markup.html.basic.Label;
12
import org.apache.wicket.markup.html.link.AbstractLink;
13
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
14
import org.apache.wicket.markup.html.panel.Panel;
15
import org.apache.wicket.markup.repeater.Item;
16
import org.apache.wicket.markup.repeater.data.DataView;
17
import org.apache.wicket.markup.repeater.data.ListDataProvider;
18
import org.apache.wicket.model.Model;
19
import org.apache.wicket.request.mapper.parameter.PageParameters;
20
import org.nanopub.extra.services.ApiResponse;
21
import org.nanopub.extra.services.QueryRef;
22

23
import com.knowledgepixels.nanodash.ApiCache;
24
import com.knowledgepixels.nanodash.page.NanodashPage;
25

26
public class ItemListPanel<T extends Serializable> extends Panel {
27

28
    private String description;
29
    private List<AbstractLink> buttons = new ArrayList<>();
×
30
    private boolean finalized = false;
×
31

32
    private ItemListPanel(String markupId, String title) {
33
        super(markupId);
×
34
        setOutputMarkupId(true);
×
35

36
        add(new Label("title", title));
×
37
    }
×
38
    
39
    public ItemListPanel(String markupId, String title, List<T> items, ComponentProvider<T> compProvider) {
40
        this(markupId, title);
×
41

42
        add(new ItemList<T>("itemlist", items, compProvider));
×
43
    }
×
44

45
    public ItemListPanel(String markupId, String title, QueryRef queryRef, ApiResultListProvider<T> resultListProvider, ComponentProvider<T> compProvider) {
46
        this(markupId, title);
×
47

48
        ApiResponse qResponse = ApiCache.retrieveResponse(queryRef);
×
49
        if (qResponse != null) {
×
50
            add(new ItemList<T>("itemlist", resultListProvider.apply(qResponse), compProvider));
×
51
        } else {
52
            add(new ApiResultComponent("itemlist", queryRef) {
×
53

54
                @Override
55
                public Component getApiResultComponent(String markupId, ApiResponse response) {
56
                    return new ItemList<T>(markupId, resultListProvider.apply(response), compProvider);
×
57
                }
58
            });
59

60
        }
61
    }
×
62

63
    public ItemListPanel(String markupId, String title, ReadyFunction readyFunction, ResultFunction<List<T>> resultFunction, ComponentProvider<T> compProvider) {
64
        this(markupId, title);
×
65

66
        if (readyFunction.get()) {
×
67
            add(new ItemList<T>("itemlist", resultFunction.get(), compProvider));
×
68
        } else {
69
            add(new MethodResultComponent<List<T>>("itemlist", readyFunction, resultFunction) {
×
70
                @Override
71
                public Component getResultComponent(String markupId, List<T> result) {
72
                    return new ItemList<T>(markupId, resultFunction.get(), compProvider);
×
73
                }
74
            });
75
        }
76
    }
×
77

78
    public ItemListPanel<T> setDescription(String description) {
79
        this.description = description;
×
80
        return this;
×
81
    }
82

83
    public ItemListPanel<T> makeInline() {
84
        add(new AttributeAppender("class", " inline"));
×
85
        return this;
×
86
    }
87

88
    public ItemListPanel<T> addButton(String label, Class<? extends NanodashPage> pageClass, PageParameters parameters) {
89
        if (parameters == null) parameters = new PageParameters();
×
90
        AbstractLink button = new BookmarkablePageLink<NanodashPage>("button", pageClass, parameters);
×
91
        button.setBody(Model.of(label));
×
92
        buttons.add(button);
×
93
        return this;
×
94
    }
95

96
    @Override
97
    protected void onBeforeRender() {
98
        if (!finalized) {
×
99
            add(new Label("description", description).setVisible(description != null));
×
100
            if (buttons.isEmpty()) {
×
101
                add(new Label("buttons").setVisible(false));
×
102
            } else {
103
                add(new DataView<AbstractLink>("buttons", new ListDataProvider<AbstractLink>(buttons)) {
×
104
    
105
                    @Override
106
                    protected void populateItem(Item<AbstractLink> item) {
107
                        item.add(item.getModelObject());
×
108
                    }
×
109
                    
110
                });
111
            }
112
            finalized = true;
×
113
        }
114
        super.onBeforeRender();
×
115
    }
×
116

117

118
    public abstract class MethodResultComponent<R> extends ResultComponent {
119

120
        private final transient Supplier<Boolean> readyFunction;
121
        private final transient Supplier<R> resultFunction;
122

123
        public MethodResultComponent(String id, ReadyFunction readyFunction, ResultFunction<R> resultFunction) {
×
124
            super(id);
×
125
            setOutputMarkupId(true);
×
126
            this.readyFunction = readyFunction;
×
127
            this.resultFunction = resultFunction;
×
128
        }
×
129

130
        /**
131
         * {@inheritDoc}
132
         */
133
        @Override
134
        protected boolean isContentReady() {
135
            return readyFunction.get();
×
136
        }
137

138
        /**
139
         * {@inheritDoc}
140
         */
141
        @Override
142
        public Component getLazyLoadComponent(String markupId) {
143
            R result = resultFunction.get();
×
144
            return getResultComponent(markupId, result);
×
145
        }
146

147
        public abstract Component getResultComponent(String markupId, R result);
148

149
    }
150

151
    public static interface ComponentProvider<T> extends Function<T, Component>, Serializable {
152
    }
153

154
    public static interface ApiResultListProvider<T> extends Function<ApiResponse, List<T>>, Serializable {
155
    }
156

157
    public static interface ReadyFunction extends Supplier<Boolean>, Serializable {
158
    }
159

160
    public static interface ResultFunction<X> extends Supplier<X>, Serializable {
161
    }
162

163
}
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