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

knowledgepixels / nanodash / 27739803358

18 Jun 2026 05:55AM UTC coverage: 26.658% (-0.3%) from 26.963%
27739803358

Pull #484

github

web-flow
Merge 9d6502630 into 0f6281554
Pull Request #484: Space-ref disambiguation: conflict notice, claimants overview, ref-pinned pages

1545 of 6821 branches covered (22.65%)

Branch coverage included in aggregate %.

3414 of 11781 relevant lines covered (28.98%)

4.26 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/ResourceTabs.java
1
package com.knowledgepixels.nanodash.component;
2

3
import com.knowledgepixels.nanodash.page.ExplorePage;
4
import com.knowledgepixels.nanodash.page.MaintainedResourcePage;
5
import com.knowledgepixels.nanodash.page.ResourcePartPage;
6
import com.knowledgepixels.nanodash.page.SpacePage;
7
import com.knowledgepixels.nanodash.page.UserPage;
8
import org.apache.wicket.behavior.AttributeAppender;
9
import org.apache.wicket.markup.html.WebMarkupContainer;
10
import org.apache.wicket.markup.html.WebPage;
11
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
12
import org.apache.wicket.markup.html.panel.Panel;
13
import org.apache.wicket.request.mapper.parameter.PageParameters;
14

15
/**
16
 * Tab strip shown at the top of a resource's page, switching between the
17
 * <b>Content</b> tab (the rendered view displays), the <b>About</b> tab (the
18
 * listing of roles/presets/view displays), the <b>Explore</b> tab (the generic
19
 * exploration panels and references), and the <b>Raw</b> tab (the downloadable
20
 * RDF of all nanopubs on the page).
21
 *
22
 * <p>All tabs are the same page, selected via the {@code tab} query parameter
23
 * ({@code content} is the default and carries no parameter). Parts
24
 * ({@code type == "part"}) have no About tab.</p>
25
 */
26
public class ResourceTabs extends Panel {
27

28
    /**
29
     * Which tab is currently shown (rendered as the selected tab).
30
     */
31
    public enum Tab {CONTENT, ABOUT, EXPLORE, RAW}
×
32

33
    /**
34
     * Maps the {@code tab} query parameter to a {@link Tab} (defaulting to
35
     * {@link Tab#CONTENT}). Used by the resource pages to pick which tab body to
36
     * render and which tab to mark active.
37
     *
38
     * @param parameters the page parameters
39
     * @return the selected tab
40
     */
41
    public static Tab activeFromParam(PageParameters parameters) {
42
        switch (parameters.get("tab").toString("content")) {
×
43
            case "about":
44
                return Tab.ABOUT;
×
45
            case "explore":
46
                return Tab.EXPLORE;
×
47
            case "raw":
48
                return Tab.RAW;
×
49
            default:
50
                return Tab.CONTENT;
×
51
        }
52
    }
53

54
    /**
55
     * Constructs the tab strip for a top-level resource (space, user, resource).
56
     *
57
     * @param id         the Wicket markup id
58
     * @param type       the resource kind: {@code "space"}, {@code "user"}, or {@code "resource"}
59
     * @param resourceId the resource IRI
60
     * @param active     the tab to mark as selected
61
     */
62
    public ResourceTabs(String id, String type, String resourceId, Tab active) {
63
        this(id, type, resourceId, null, active);
×
64
    }
×
65

66
    /**
67
     * Constructs the tab strip, optionally for a part (which carries a context).
68
     *
69
     * @param id         the Wicket markup id
70
     * @param type       the resource kind: {@code "space"}, {@code "user"}, {@code "resource"}, or {@code "part"}
71
     * @param resourceId the resource (or part) IRI
72
     * @param contextId  the context resource IRI (for parts), or {@code null}
73
     * @param active     the tab to mark as selected
74
     */
75
    public ResourceTabs(String id, String type, String resourceId, String contextId, Tab active) {
76
        this(id, type, resourceId, contextId, active, null);
×
77
    }
×
78

79
    /**
80
     * Constructs the tab strip, optionally pinned to a specific space ref via {@code root}.
81
     *
82
     * @param id         the Wicket markup id
83
     * @param type       the resource kind
84
     * @param resourceId the resource (or part) IRI
85
     * @param contextId  the context resource IRI (for parts), or {@code null}
86
     * @param active     the tab to mark as selected
87
     * @param root       the space ref's root nanopub to carry across tab switches, or {@code null}
88
     */
89
    public ResourceTabs(String id, String type, String resourceId, String contextId, Tab active, String root) {
90
        super(id);
×
91

92
        Class<? extends WebPage> pageClass;
93
        boolean hasAbout;
94
        switch (type) {
×
95
            case "space":
96
                pageClass = SpacePage.class;
×
97
                hasAbout = true;
×
98
                break;
×
99
            case "user":
100
                pageClass = UserPage.class;
×
101
                hasAbout = true;
×
102
                break;
×
103
            case "resource":
104
                pageClass = MaintainedResourcePage.class;
×
105
                hasAbout = true;
×
106
                break;
×
107
            case "part":
108
                pageClass = ResourcePartPage.class;
×
109
                hasAbout = true;
×
110
                break;
×
111
            default:
112
                throw new IllegalArgumentException("Unknown resource type: " + type);
×
113
        }
114

115
        add(tabLink("content-tab", pageClass, params(resourceId, contextId, null, root), active == Tab.CONTENT));
×
116
        if (hasAbout) {
×
117
            add(tabLink("about-tab", pageClass, params(resourceId, contextId, "about", root), active == Tab.ABOUT));
×
118
        } else {
119
            add(new WebMarkupContainer("about-tab").setVisible(false));
×
120
        }
121
        add(tabLink("explore-tab", pageClass, params(resourceId, contextId, "explore", root), active == Tab.EXPLORE));
×
122
        add(tabLink("raw-tab", pageClass, params(resourceId, contextId, "raw", root), active == Tab.RAW));
×
123
    }
×
124

125
    /**
126
     * Constructs a two-tab strip (<b>Content</b> | <b>Explore</b>) for the
127
     * standalone {@link ExplorePage}. Unlike the resource variants this carries
128
     * the page's full parameter set (minus {@code tab}) across tab switches so
129
     * the resolved id, context and label are preserved, and it has neither an
130
     * About nor a Raw tab.
131
     *
132
     * @param id         the Wicket markup id
133
     * @param baseParams the explore page's parameters to preserve across tabs
134
     * @param active     the tab to mark as selected
135
     */
136
    public ResourceTabs(String id, PageParameters baseParams, Tab active) {
137
        super(id);
×
138

139
        PageParameters contentParams = new PageParameters(baseParams);
×
140
        contentParams.remove("tab");
×
141
        PageParameters exploreParams = new PageParameters(contentParams);
×
142
        exploreParams.set("tab", "explore");
×
143

144
        add(tabLink("content-tab", ExplorePage.class, contentParams, active == Tab.CONTENT));
×
145
        add(new WebMarkupContainer("about-tab").setVisible(false));
×
146
        add(tabLink("explore-tab", ExplorePage.class, exploreParams, active == Tab.EXPLORE));
×
147
        add(new WebMarkupContainer("raw-tab").setVisible(false));
×
148
    }
×
149

150
    /**
151
     * The gray-italic title suffix shown after the resource name on non-content
152
     * tabs (e.g. " – About"); empty for the content tab.
153
     *
154
     * @param tab the active tab
155
     * @return the suffix string (possibly empty)
156
     */
157
    public static String titleSuffix(Tab tab) {
158
        switch (tab) {
×
159
            case ABOUT:
160
                return " – About";
×
161
            case EXPLORE:
162
                return " – Explore";
×
163
            case RAW:
164
                return " – Raw";
×
165
            default:
166
                return "";
×
167
        }
168
    }
169

170
    private PageParameters params(String resourceId, String contextId, String tab, String root) {
171
        PageParameters p = new PageParameters().set("id", resourceId);
×
172
        if (contextId != null) p.set("context", contextId);
×
173
        if (tab != null) p.set("tab", tab);
×
174
        if (root != null) p.set("root", root);
×
175
        return p;
×
176
    }
177

178
    private BookmarkablePageLink<Void> tabLink(String id, Class<? extends WebPage> pageClass, PageParameters params, boolean selected) {
179
        BookmarkablePageLink<Void> link = new BookmarkablePageLink<>(id, pageClass, params);
×
180
        if (selected) {
×
181
            link.add(new AttributeAppender("class", " selected"));
×
182
        }
183
        return link;
×
184
    }
185

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