1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.common.ui.client.widgets.search; |
17 |
|
|
18 |
|
import java.util.ArrayList; |
19 |
|
import java.util.List; |
20 |
|
import java.util.Set; |
21 |
|
|
22 |
|
import org.kuali.student.common.assembly.data.LookupResultMetadata; |
23 |
|
import org.kuali.student.common.search.dto.SearchRequest; |
24 |
|
import org.kuali.student.common.search.dto.SearchResult; |
25 |
|
import org.kuali.student.common.search.dto.SearchResultCell; |
26 |
|
import org.kuali.student.common.search.dto.SearchResultRow; |
27 |
|
import org.kuali.student.common.ui.client.application.Application; |
28 |
|
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
29 |
|
import org.kuali.student.common.ui.client.service.CachingSearchService; |
30 |
|
import org.kuali.student.common.ui.client.service.SearchRpcServiceAsync; |
31 |
|
import org.kuali.student.common.ui.client.widgets.pagetable.GenericTableModel; |
32 |
|
import org.kuali.student.common.ui.client.widgets.pagetable.PagingScrollTableBuilder; |
33 |
|
import org.kuali.student.common.ui.client.widgets.searchtable.ResultRow; |
34 |
|
import org.kuali.student.common.ui.client.widgets.searchtable.SearchColumnDefinition; |
35 |
|
|
36 |
|
import com.google.gwt.core.client.GWT; |
37 |
|
import com.google.gwt.gen2.table.client.AbstractColumnDefinition; |
38 |
|
import com.google.gwt.gen2.table.client.PagingOptions; |
39 |
|
import com.google.gwt.gen2.table.client.PagingScrollTable; |
40 |
|
import com.google.gwt.gen2.table.client.AbstractScrollTable.ResizePolicy; |
41 |
|
import com.google.gwt.gen2.table.event.client.RowSelectionHandler; |
42 |
|
import com.google.gwt.user.client.Window; |
43 |
|
import com.google.gwt.user.client.ui.Composite; |
44 |
|
import com.google.gwt.user.client.ui.Label; |
45 |
|
import com.google.gwt.user.client.ui.VerticalPanel; |
46 |
|
|
|
|
| 0% |
Uncovered Elements: 96 (96) |
Complexity: 19 |
Complexity Density: 0.26 |
|
47 |
|
public class TempSearchBackedTable extends Composite{ |
48 |
|
|
49 |
|
private List<ResultRow> resultRows = new ArrayList<ResultRow>(); |
50 |
|
private List<AbstractColumnDefinition<ResultRow, ?>> columnDefs = new ArrayList<AbstractColumnDefinition<ResultRow, ?>>(); |
51 |
|
private GenericTableModel<ResultRow> tableModel = new GenericTableModel<ResultRow>(resultRows); |
52 |
|
private PagingScrollTableBuilder<ResultRow> builder = new PagingScrollTableBuilder<ResultRow>(); |
53 |
|
private String resultIdColumnKey; |
54 |
|
protected PagingScrollTable<ResultRow> pagingScrollTable; |
55 |
|
private VerticalPanel layout = new VerticalPanel(); |
56 |
|
private PagingOptions pagingOptions; |
57 |
|
|
58 |
|
private SearchRpcServiceAsync searchRpcServiceAsync = CachingSearchService.getSearchService(); |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
60 |
0
|
private PagingOptions createPagingOptions(PagingScrollTable<ResultRow> pagingScrollTable) {... |
61 |
0
|
PagingOptions pagingOptions = new PagingOptions(pagingScrollTable); |
62 |
0
|
pagingOptions.setPixelSize(pagingScrollTable.getOffsetWidth(), pagingOptions.getOffsetHeight()); |
63 |
0
|
return pagingOptions; |
64 |
|
} |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
66 |
0
|
public TempSearchBackedTable(){... |
67 |
0
|
super(); |
68 |
0
|
redraw(); |
69 |
0
|
layout.setWidth("100%"); |
70 |
0
|
initWidget(layout); |
71 |
|
} |
72 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
73 |
0
|
public void clearTable(){... |
74 |
0
|
resultRows.clear(); |
75 |
0
|
this.redraw(); |
76 |
|
} |
77 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
78 |
0
|
public void removeSelected(){... |
79 |
0
|
for(ResultRow r: getSelectedRows()){ |
80 |
0
|
resultRows.remove(r); |
81 |
|
} |
82 |
0
|
this.redraw(); |
83 |
|
} |
84 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
85 |
0
|
public void performSearch(SearchRequest searchRequest, List<LookupResultMetadata> listResultMetadata, String resultIdKey){... |
86 |
|
|
87 |
0
|
initializeTable(listResultMetadata, resultIdKey); |
88 |
|
|
89 |
0
|
searchRequest.setNeededTotalResults(false); |
90 |
|
|
91 |
0
|
if(pagingScrollTable != null){ |
92 |
0
|
pagingScrollTable.setEmptyTableWidget(new Label("Processing Search...")); |
93 |
|
} |
94 |
|
|
95 |
0
|
searchRpcServiceAsync.search(searchRequest, new KSAsyncCallback<SearchResult>(){ |
96 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
97 |
0
|
@Override... |
98 |
|
public void handleFailure(Throwable cause) { |
99 |
0
|
GWT.log("Failed to perform search", cause); |
100 |
0
|
Window.alert("Failed to perform search"); |
101 |
|
} |
102 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
103 |
0
|
@Override... |
104 |
|
public void onSuccess(SearchResult results) { |
105 |
|
|
106 |
0
|
resultRows.clear(); |
107 |
0
|
if(results != null){ |
108 |
0
|
for (SearchResultRow r: results.getRows()){ |
109 |
0
|
ResultRow theRow = new ResultRow(); |
110 |
0
|
for(SearchResultCell c: r.getCells()){ |
111 |
0
|
if(c.getKey().equals(resultIdColumnKey)){ |
112 |
0
|
theRow.setId(c.getValue()); |
113 |
|
} |
114 |
0
|
theRow.setValue(c.getKey(), c.getValue()); |
115 |
|
} |
116 |
0
|
resultRows.add(theRow); |
117 |
|
} |
118 |
|
} |
119 |
0
|
redraw(); |
120 |
|
} |
121 |
|
}); |
122 |
|
} |
123 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 3 |
Complexity Density: 0.2 |
|
124 |
0
|
public void initializeTable(List<LookupResultMetadata> listResultMetadata, String resultIdKey) {... |
125 |
0
|
clearTable(); |
126 |
|
|
127 |
0
|
this.resultIdColumnKey = resultIdKey; |
128 |
0
|
builder = new PagingScrollTableBuilder<ResultRow>(); |
129 |
0
|
builder.tablePixelSize(400, 300); |
130 |
|
|
131 |
0
|
columnDefs = new ArrayList<AbstractColumnDefinition<ResultRow, ?>>(); |
132 |
0
|
for (LookupResultMetadata r: listResultMetadata){ |
133 |
0
|
String header = Application.getApplicationContext().getUILabel("", null, null, r.getName()); |
134 |
0
|
String key = r.getKey(); |
135 |
0
|
if(!r.isHidden()){ |
136 |
0
|
columnDefs.add(new SearchColumnDefinition(header, key)); |
137 |
|
} |
138 |
|
} |
139 |
0
|
if(columnDefs.size() == 1){ |
140 |
|
|
141 |
0
|
columnDefs.get(0).setMinimumColumnWidth(370); |
142 |
|
} |
143 |
0
|
builder.columnDefinitions(columnDefs); |
144 |
0
|
tableModel.setColumnDefs(columnDefs); |
145 |
|
|
146 |
0
|
redraw(); |
147 |
|
} |
148 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
149 |
0
|
public void redraw(){... |
150 |
0
|
tableModel.setRows(resultRows); |
151 |
0
|
pagingScrollTable = builder.build(tableModel); |
152 |
0
|
pagingScrollTable.setResizePolicy(ResizePolicy.FILL_WIDTH); |
153 |
0
|
pagingOptions = createPagingOptions(pagingScrollTable); |
154 |
0
|
layout.clear(); |
155 |
0
|
layout.add(pagingOptions); |
156 |
0
|
layout.add(pagingScrollTable); |
157 |
0
|
pagingScrollTable.reloadPage(); |
158 |
0
|
pagingScrollTable.fillWidth(); |
159 |
|
} |
160 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
161 |
0
|
public void addSelectionHandler(RowSelectionHandler selectionHandler){... |
162 |
0
|
pagingScrollTable.getDataTable().addRowSelectionHandler(selectionHandler); |
163 |
|
} |
164 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
165 |
0
|
public List<ResultRow> getSelectedRows(){... |
166 |
0
|
List<ResultRow> rows = new ArrayList<ResultRow>(); |
167 |
0
|
Set<Integer> selectedRows = pagingScrollTable.getDataTable().getSelectedRows(); |
168 |
0
|
for(Integer i: selectedRows){ |
169 |
0
|
rows.add(pagingScrollTable.getRowValue(i)); |
170 |
|
} |
171 |
0
|
return rows; |
172 |
|
} |
173 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
174 |
0
|
public List<String> getSelectedIds(){... |
175 |
0
|
List<String> ids = new ArrayList<String>(); |
176 |
0
|
Set<Integer> selectedRows = pagingScrollTable.getDataTable().getSelectedRows(); |
177 |
0
|
for(Integer i: selectedRows){ |
178 |
0
|
ids.add(pagingScrollTable.getRowValue(i).getId()); |
179 |
|
} |
180 |
0
|
return ids; |
181 |
|
} |
182 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
183 |
0
|
public List<String> getAllIds(){... |
184 |
0
|
List<String> ids = new ArrayList<String>(); |
185 |
0
|
for(ResultRow r: resultRows){ |
186 |
0
|
ids.add(r.getId()); |
187 |
|
} |
188 |
0
|
return ids; |
189 |
|
} |
190 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
191 |
0
|
public List<ResultRow> getAllRows(){... |
192 |
0
|
List<ResultRow> rows = new ArrayList<ResultRow>(); |
193 |
0
|
for(ResultRow r: resultRows){ |
194 |
0
|
rows.add(r); |
195 |
|
} |
196 |
0
|
return rows; |
197 |
|
} |
198 |
|
|
199 |
|
} |