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

knowledgepixels / nanodash / 17580410679

09 Sep 2025 10:58AM UTC coverage: 13.608% (-0.02%) from 13.623%
17580410679

push

github

tkuhn
Generalize lazy loading of ItemListPanel

406 of 3854 branches covered (10.53%)

Branch coverage included in aggregate %.

1071 of 7000 relevant lines covered (15.3%)

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.HashMap;
5
import java.util.List;
6
import java.util.function.Function;
7

8
import org.apache.wicket.Component;
9
import org.apache.wicket.MarkupContainer;
10
import org.apache.wicket.ajax.markup.html.navigation.paging.AjaxPagingNavigator;
11
import org.apache.wicket.extensions.markup.html.repeater.data.table.NavigatorLabel;
12
import org.apache.wicket.markup.html.WebMarkupContainer;
13
import org.apache.wicket.markup.html.basic.Label;
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.nanopub.extra.services.ApiResponse;
19

20
import com.knowledgepixels.nanodash.ApiCache;
21

22
public class ItemListPanel<T extends Serializable> extends Panel {
23

24
    public ItemListPanel(String id, String title, List<T> items, ComponentProvider<T> compProvider) {
25
        super(id);
×
26
        setOutputMarkupId(true);
×
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
        DataView<T> dataView = new DataView<T>("itemlist", new ListDataProvider<T>(items)) {
×
37

38
            @Override
39
            protected void populateItem(Item<T> item) {
40
                item.add(compProvider.apply(item.getModelObject()));
×
41
            }
×
42

43
        };
44
        dataView.setItemsPerPage(10);
×
45
        dataView.setOutputMarkupId(true);
×
46
        add(dataView);
×
47

48
        WebMarkupContainer navigation = new WebMarkupContainer("navigation");
×
49
        navigation.add(new NavigatorLabel("navigatorLabel", dataView));
×
50
        AjaxPagingNavigator pagingNavigator = new AjaxPagingNavigator("navigator", dataView);
×
51
        navigation.setVisible(dataView.getPageCount() > 1);
×
52
        navigation.add(pagingNavigator);
×
53
        add(navigation);
×
54
    }
×
55

56
    public static interface ComponentProvider<T> extends Function<T, Component>, Serializable {
57
    }
58

59
    public static interface ApiResultListProvider<T> extends Function<ApiResponse, List<T>>, Serializable {
60
    }
61

62
    public static class LazyLoad<T extends Serializable> implements Serializable {
63

64
        private String markupId;
65
        private String queryName;
66
        private HashMap<String, String> params;
67
        private ApiResultListProvider<T> resultListProvider;
68
        private String title;
69
        private ComponentProvider<T> compProvider;
70

71
        public LazyLoad(String markupId, String title, String queryName, HashMap<String, String> params, ApiResultListProvider<T> resultListProvider, ComponentProvider<T> compProvider) {
×
72
            this.markupId = markupId;
×
73
            this.queryName = queryName;
×
74
            this.params = params;
×
75
            this.resultListProvider = resultListProvider;
×
76
            this.title = title;
×
77
            this.compProvider = compProvider;
×
78
        }
×
79

80
        public MarkupContainer getContainer() {
81
            ApiResponse qResponse = ApiCache.retrieveResponse(queryName, params);
×
82
            if (qResponse != null) {
×
83
                return new ItemListPanel<T>(markupId, title, resultListProvider.apply(qResponse), compProvider);
×
84
            } else {
85
                return new ApiResultComponent(markupId, queryName, params) {
×
86

87
                    @Override
88
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
89
                        return new ItemListPanel<T>(markupId, title, resultListProvider.apply(response), compProvider);
×
90
                    }
91
                };
92

93
            }
94
        }
95
        
96
    }
97

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