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

knowledgepixels / nanodash / 17666649186

12 Sep 2025 06:35AM UTC coverage: 13.717% (-0.06%) from 13.781%
17666649186

push

github

tkuhn
feat: Unify owner and member lists; minor style refactoring

432 of 3976 branches covered (10.87%)

Branch coverage included in aggregate %.

1105 of 7229 relevant lines covered (15.29%)

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.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.markup.html.basic.Label;
11
import org.apache.wicket.markup.html.link.AbstractLink;
12
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
13
import org.apache.wicket.markup.html.panel.Panel;
14
import org.apache.wicket.markup.repeater.Item;
15
import org.apache.wicket.markup.repeater.data.DataView;
16
import org.apache.wicket.markup.repeater.data.ListDataProvider;
17
import org.apache.wicket.model.Model;
18
import org.apache.wicket.request.mapper.parameter.PageParameters;
19
import org.nanopub.extra.services.ApiResponse;
20

21
import com.knowledgepixels.nanodash.ApiCache;
22
import com.knowledgepixels.nanodash.QueryRef;
23
import com.knowledgepixels.nanodash.page.NanodashPage;
24

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

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

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

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

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

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

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

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

59
        }
60
    }
×
61

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

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

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

82
    public ItemListPanel<T> addButton(String label, Class<? extends NanodashPage> pageClass, PageParameters parameters) {
83
        if (parameters == null) parameters = new PageParameters();
×
84
        AbstractLink button = new BookmarkablePageLink<NanodashPage>("button", pageClass, parameters);
×
85
        button.setBody(Model.of(label));
×
86
        buttons.add(button);
×
87
        return this;
×
88
    }
89

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

111

112
    public abstract class MethodResultComponent<R> extends ResultComponent {
113

114
        private final transient Supplier<Boolean> readyFunction;
115
        private final transient Supplier<R> resultFunction;
116

117
        public MethodResultComponent(String id, ReadyFunction readyFunction, ResultFunction<R> resultFunction) {
×
118
            super(id);
×
119
            setOutputMarkupId(true);
×
120
            this.readyFunction = readyFunction;
×
121
            this.resultFunction = resultFunction;
×
122
        }
×
123

124
        /**
125
         * {@inheritDoc}
126
         */
127
        @Override
128
        protected boolean isContentReady() {
129
            return readyFunction.get();
×
130
        }
131

132
        /**
133
         * {@inheritDoc}
134
         */
135
        @Override
136
        public Component getLazyLoadComponent(String markupId) {
137
            R result = resultFunction.get();
×
138
            return getResultComponent(markupId, result);
×
139
        }
140

141
        public abstract Component getResultComponent(String markupId, R result);
142

143
    }
144

145
    public static interface ComponentProvider<T> extends Function<T, Component>, Serializable {
146
    }
147

148
    public static interface ApiResultListProvider<T> extends Function<ApiResponse, List<T>>, Serializable {
149
    }
150

151
    public static interface ReadyFunction extends Supplier<Boolean>, Serializable {
152
    }
153

154
    public static interface ResultFunction<X> extends Supplier<X>, Serializable {
155
    }
156

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