-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathQueryResult.java
More file actions
129 lines (116 loc) · 4.59 KB
/
QueryResult.java
File metadata and controls
129 lines (116 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package com.knowledgepixels.nanodash;
import com.knowledgepixels.nanodash.component.ButtonList;
import com.knowledgepixels.nanodash.component.menu.ViewDisplayMenu;
import com.knowledgepixels.nanodash.domain.AbstractResourceWithProfile;
import com.knowledgepixels.nanodash.domain.IndividualAgent;
import com.knowledgepixels.nanodash.page.NanodashPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.AbstractLink;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.nanopub.extra.services.ApiResponse;
import org.nanopub.extra.services.QueryRef;
import java.util.ArrayList;
import java.util.List;
/**
* Abstract base class for displaying query results in different formats.
*/
public abstract class QueryResult extends Panel {
protected final List<AbstractLink> buttons = new ArrayList<>();
protected String contextId;
protected String partId;
protected boolean finalized = false;
protected final QueryRef queryRef;
protected final ViewDisplay viewDisplay;
protected final ApiResponse response;
protected AbstractResourceWithProfile resourceWithProfile;
protected AbstractResourceWithProfile pageResource;
protected boolean showViewDisplayMenu = true;
protected final GrlcQuery grlcQuery;
/**
* Constructor for QueryResult.
*
* @param markupId the markup ID
* @param queryRef the query reference
* @param response the API response
* @param viewDisplay the view display
*/
public QueryResult(String markupId, QueryRef queryRef, ApiResponse response, ViewDisplay viewDisplay) {
super(markupId);
this.queryRef = queryRef;
this.viewDisplay = viewDisplay;
this.response = response;
this.grlcQuery = GrlcQuery.get(queryRef);
}
@Override
protected void onBeforeRender() {
if (!finalized) {
if (!buttons.isEmpty()) {
// TODO: Add more flexible ways to restrict button visibility (e.g. per-view or per-action permissions)
if (resourceWithProfile instanceof IndividualAgent) {
add(new ButtonList("buttons", resourceWithProfile, null, null, buttons));
} else {
add(new ButtonList("buttons", resourceWithProfile, buttons, null, null));
}
} else {
add(new Label("buttons").setVisible(false));
}
if (showViewDisplayMenu) {
if (viewDisplay.getNanopubId() != null) {
add(new ViewDisplayMenu("np", viewDisplay, queryRef, pageResource));
} else {
add(new Label("np").setVisible(false));
}
}
finalized = true;
}
super.onBeforeRender();
}
/**
* Set the resource with profile for this component.
*
* @param resourceWithProfile The resource with profile to set.
*/
public void setResourceWithProfile(AbstractResourceWithProfile resourceWithProfile) {
this.resourceWithProfile = resourceWithProfile;
}
public void setPageResource(AbstractResourceWithProfile pageResource) {
this.pageResource = pageResource;
}
/**
* Set the context ID for this component.
*
* @param contextId The context ID to set.
*/
public void setContextId(String contextId) {
this.contextId = contextId;
}
/**
* Set the part ID when this view is shown on a part page (e.g. paper collection).
* Used for redirect-after-publish to return to the part page.
*
* @param partId The part ID to set, or null when on the main context page.
*/
public void setPartId(String partId) {
this.partId = partId;
}
// TODO button adding method copied and adjusted from ItemListPanel
// TODO Improve this (member/admin) button handling:
public void addButton(String label, Class<? extends NanodashPage> pageClass, PageParameters parameters) {
if (parameters == null) {
parameters = new PageParameters();
}
if (contextId != null) {
parameters.set("context", contextId);
}
AbstractLink button = new BookmarkablePageLink<NanodashPage>("button", pageClass, parameters);
button.setBody(Model.of(label));
buttons.add(button);
}
/**
* Populate the component with the query results.
*/
protected abstract void populateComponent();
}