1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.lum.lu.ui.tools.client.widgets; |
17 |
|
|
18 |
|
import java.util.ArrayList; |
19 |
|
import java.util.HashMap; |
20 |
|
import java.util.HashSet; |
21 |
|
import java.util.LinkedHashMap; |
22 |
|
import java.util.List; |
23 |
|
import java.util.Map; |
24 |
|
import java.util.Map.Entry; |
25 |
|
|
26 |
|
import org.kuali.student.common.assembly.data.LookupMetadata; |
27 |
|
import org.kuali.student.common.assembly.data.LookupParamMetadata; |
28 |
|
import org.kuali.student.common.search.dto.SearchParam; |
29 |
|
import org.kuali.student.common.search.dto.SearchRequest; |
30 |
|
import org.kuali.student.common.ui.client.mvc.Callback; |
31 |
|
import org.kuali.student.common.ui.client.widgets.KSButton; |
32 |
|
import org.kuali.student.common.ui.client.widgets.search.SelectedResults; |
33 |
|
import org.kuali.student.common.ui.client.widgets.searchtable.ResultRow; |
34 |
|
|
35 |
|
import com.google.gwt.event.dom.client.ClickEvent; |
36 |
|
import com.google.gwt.event.dom.client.ClickHandler; |
37 |
|
import com.google.gwt.gen2.table.client.SelectionGrid.SelectionPolicy; |
38 |
|
import com.google.gwt.user.client.ui.Composite; |
39 |
|
import com.google.gwt.user.client.ui.FlowPanel; |
40 |
|
|
|
|
| 0% |
Uncovered Elements: 134 (134) |
Complexity: 28 |
Complexity Density: 0.29 |
|
41 |
|
public class BrowsePanel extends Composite { |
42 |
|
|
43 |
|
|
44 |
|
private FlowPanel layout; |
45 |
|
private FlowPanel tablePanel; |
46 |
|
private LookupMetadata lookupMetadata = null; |
47 |
|
private SearchBackedTable searchBackedTable = null; |
48 |
|
private boolean multiSelect = false; |
49 |
|
public Map<String, Object> parameters; |
50 |
|
private int tableHeight = 200;; |
51 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
52 |
|
public interface OnSelectedCallback { |
53 |
|
public void selected(List<String> selectedIds); |
54 |
|
} |
55 |
|
|
56 |
|
private OnSelectedCallback onSelectectedCallback; |
57 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
58 |
0
|
public BrowsePanel(LookupMetadata lookupMetadata) {... |
59 |
0
|
this.lookupMetadata = lookupMetadata; |
60 |
0
|
layout = new FlowPanel(); |
61 |
0
|
layout.addStyleName("KS-Picker-Border"); |
62 |
0
|
layout.addStyleName("KS-Advanced-Search-Panel"); |
63 |
0
|
tablePanel = new FlowPanel(); |
64 |
0
|
this.initWidget(layout); |
65 |
|
} |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
67 |
0
|
public BrowsePanel(LookupMetadata lookupMetadata, int tableHeight) {... |
68 |
0
|
this(lookupMetadata); |
69 |
0
|
this.tableHeight = tableHeight; |
70 |
|
} |
71 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
72 |
0
|
public Map<String, Object> getParameters() {... |
73 |
0
|
if (parameters == null) { |
74 |
0
|
parameters = new LinkedHashMap<String, Object>(); |
75 |
|
} |
76 |
0
|
return parameters; |
77 |
|
} |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
0
|
public void setParameters(Map<String, Object> parameters) {... |
80 |
0
|
this.parameters = parameters; |
81 |
|
} |
82 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
83 |
0
|
private Map<String, Object> getDefaultParameters() {... |
84 |
0
|
Map<String, Object> defParms = new LinkedHashMap<String, Object>(); |
85 |
0
|
for (LookupParamMetadata paramMeta : lookupMetadata.getParams()) { |
86 |
0
|
if (paramMeta.getDefaultValueString() != null) { |
87 |
0
|
defParms.put(paramMeta.getKey(), |
88 |
|
paramMeta.getDefaultValueString()); |
89 |
0
|
continue; |
90 |
|
} |
91 |
0
|
if (paramMeta.getDefaultValueList() != null) { |
92 |
0
|
defParms.put(paramMeta.getKey(), |
93 |
|
paramMeta.getDefaultValueList()); |
94 |
|
} |
95 |
|
} |
96 |
0
|
return defParms; |
97 |
|
} |
98 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
99 |
0
|
public OnSelectedCallback getOnSelectectedCallback() {... |
100 |
0
|
return onSelectectedCallback; |
101 |
|
} |
102 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
0
|
public void setOnSelectectedCallback(... |
104 |
|
OnSelectedCallback onSelectectedCallback) { |
105 |
0
|
this.onSelectectedCallback = onSelectectedCallback; |
106 |
|
} |
107 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
108 |
|
private class SelectButtonClickHandler implements ClickHandler { |
109 |
|
|
110 |
|
private OnSelectedCallback callback; |
111 |
|
private SearchBackedTable searchBackedTable; |
112 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
113 |
0
|
public SelectButtonClickHandler(OnSelectedCallback callback,... |
114 |
|
SearchBackedTable searchBackedTable) { |
115 |
0
|
this.callback = callback; |
116 |
0
|
this.searchBackedTable = searchBackedTable; |
117 |
|
} |
118 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
119 |
0
|
@Override... |
120 |
|
public void onClick(ClickEvent event) { |
121 |
0
|
this.callback.selected(this.searchBackedTable.getSelectedIds()); |
122 |
|
} |
123 |
|
|
124 |
|
} |
125 |
|
|
|
|
| 0% |
Uncovered Elements: 33 (33) |
Complexity: 2 |
Complexity Density: 0.06 |
|
126 |
0
|
@SuppressWarnings("unchecked")... |
127 |
|
public void executeSearch(Callback<Boolean> callback) { |
128 |
|
|
129 |
0
|
tablePanel.clear(); |
130 |
0
|
layout.clear(); |
131 |
0
|
tablePanel.setVisible(false); |
132 |
0
|
layout.add(tablePanel); |
133 |
|
|
134 |
|
|
135 |
0
|
searchBackedTable = new SearchBackedTable(tableHeight); |
136 |
0
|
searchBackedTable.addStyleName("KS-Advanced-Search-Results-Table"); |
137 |
0
|
searchBackedTable.setTableStyleName("gwt-PagingScrollTable"); |
138 |
0
|
searchBackedTable.setSelectionPolicy(SelectionPolicy.ONE_ROW); |
139 |
0
|
KSButton selectButton = new KSButton("Select", |
140 |
|
new SelectButtonClickHandler(this.onSelectectedCallback, |
141 |
|
this.searchBackedTable)); |
142 |
0
|
tablePanel.add(searchBackedTable); |
143 |
0
|
tablePanel.add(selectButton); |
144 |
0
|
tablePanel.setVisible(false); |
145 |
|
|
146 |
0
|
SearchRequest searchRequest = new SearchRequest(); |
147 |
0
|
List<SearchParam> searchParams = new ArrayList<SearchParam>(); |
148 |
0
|
Map<String, Object> parms = getDefaultParameters(); |
149 |
0
|
parms.putAll(getParameters()); |
150 |
0
|
for (Entry<String, Object> entry : parms.entrySet()) { |
151 |
0
|
Object value = entry.getValue(); |
152 |
0
|
SearchParam searchParam = new SearchParam(); |
153 |
0
|
searchParam.setKey(entry.getKey()); |
154 |
0
|
if (value instanceof String) { |
155 |
0
|
searchParam.setValue((String) value); |
156 |
|
} else { |
157 |
0
|
searchParam.setValue((List<String>) value); |
158 |
|
} |
159 |
0
|
searchParams.add(searchParam); |
160 |
|
} |
161 |
0
|
searchRequest.setParams(searchParams); |
162 |
0
|
searchRequest.setSearchKey(lookupMetadata.getSearchTypeId()); |
163 |
0
|
searchRequest.setSortColumn(this.lookupMetadata.getResultSortKey()); |
164 |
0
|
searchRequest.setSortDirection(this.lookupMetadata.getSortDirection()); |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
0
|
searchBackedTable.performSearch(searchRequest, |
183 |
|
lookupMetadata.getResults(), |
184 |
|
lookupMetadata.getResultReturnKey(), callback); |
185 |
0
|
tablePanel.setVisible(true); |
186 |
0
|
layout.setVisible(true); |
187 |
|
} |
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 5 |
Complexity Density: 0.28 |
|
194 |
0
|
public Map<String,Integer> getFilterCount()... |
195 |
|
{ |
196 |
0
|
Map<String,Integer> filterCount=new HashMap<String,Integer>(); |
197 |
0
|
for(ResultRow resultRow:getAllResultRows()) |
198 |
|
{ |
199 |
0
|
for(String columnName:resultRow.getColumnValues().keySet()) |
200 |
|
{ |
201 |
0
|
String columnValue=resultRow.getValue(columnName); |
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
0
|
while(columnValue!=null&&columnValue.indexOf("<br/>")!=-1) |
209 |
|
{ |
210 |
0
|
int f=columnValue.indexOf("<br/>"); |
211 |
0
|
if(!filterCount.containsKey(columnValue.substring(0,f))) |
212 |
|
{ |
213 |
0
|
filterCount.put(columnValue.substring(0,f), 1); |
214 |
|
} |
215 |
|
else{ |
216 |
0
|
int a=filterCount.get(columnValue.substring(0,f)).intValue(); |
217 |
0
|
a++; |
218 |
0
|
filterCount.put(columnValue.substring(0,f), a); |
219 |
|
} |
220 |
0
|
columnValue=columnValue.substring(f+5); |
221 |
|
} |
222 |
|
|
223 |
|
|
224 |
0
|
if(!filterCount.containsKey(columnValue)) |
225 |
|
{ |
226 |
0
|
filterCount.put(columnValue, 1); |
227 |
|
} |
228 |
|
else{ |
229 |
0
|
int a=filterCount.get(columnValue).intValue(); |
230 |
0
|
a++; |
231 |
0
|
filterCount.put(columnValue, a); |
232 |
|
} |
233 |
|
} |
234 |
|
} |
235 |
0
|
return filterCount; |
236 |
|
} |
237 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
238 |
0
|
public List<String> getSelectedIds() {... |
239 |
0
|
List<String> ids = new ArrayList<String>(); |
240 |
0
|
if (searchBackedTable != null) { |
241 |
0
|
ids = searchBackedTable.getSelectedIds(); |
242 |
|
} |
243 |
0
|
return ids; |
244 |
|
} |
245 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
246 |
0
|
public List<SelectedResults> getSelectedValues() {... |
247 |
|
|
248 |
0
|
List<SelectedResults> selectedValues = new ArrayList<SelectedResults>(); |
249 |
0
|
if (searchBackedTable != null) { |
250 |
0
|
List<ResultRow> selectedRows = searchBackedTable.getSelectedRows(); |
251 |
0
|
for (ResultRow row : selectedRows) { |
252 |
0
|
String displayKey = row.getValue(lookupMetadata |
253 |
|
.getResultDisplayKey()); |
254 |
0
|
String returnKey = row.getValue(lookupMetadata |
255 |
|
.getResultReturnKey()); |
256 |
0
|
selectedValues.add(new SelectedResults(displayKey, returnKey)); |
257 |
0
|
if (multiSelect == false) { |
258 |
0
|
break; |
259 |
|
} |
260 |
|
} |
261 |
|
} |
262 |
|
|
263 |
0
|
return selectedValues; |
264 |
|
} |
265 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
266 |
0
|
public void showAllRows() {... |
267 |
0
|
searchBackedTable.getResultRows().clear(); |
268 |
0
|
searchBackedTable.getResultRows().addAll( |
269 |
|
searchBackedTable.getAllResults()); |
270 |
0
|
searchBackedTable.redraw(); |
271 |
|
} |
272 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
273 |
0
|
public void showOnlyRows(HashSet<String> rowKeys) {... |
274 |
0
|
searchBackedTable.getResultRows().clear(); |
275 |
0
|
for (ResultRow resultRow : searchBackedTable.getAllResults()) { |
276 |
0
|
if (rowKeys.contains(resultRow.getId())) { |
277 |
0
|
searchBackedTable.getResultRows().add(resultRow); |
278 |
|
} |
279 |
|
} |
280 |
0
|
searchBackedTable.redraw(); |
281 |
|
} |
282 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
283 |
0
|
public List<ResultRow> getAllResultRows() {... |
284 |
0
|
return searchBackedTable.getAllResults(); |
285 |
|
} |
286 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
287 |
0
|
public boolean isMultiSelect() {... |
288 |
0
|
return multiSelect; |
289 |
|
} |
290 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
291 |
0
|
public void setMultiSelect(boolean multiSelect) {... |
292 |
0
|
this.multiSelect = multiSelect; |
293 |
|
} |
294 |
|
|
295 |
|
} |