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.LinkedHashMap; |
20 | |
import java.util.List; |
21 | |
import java.util.Map; |
22 | |
import java.util.Map.Entry; |
23 | |
|
24 | |
import org.kuali.student.common.assembly.data.LookupMetadata; |
25 | |
import org.kuali.student.common.assembly.data.LookupParamMetadata; |
26 | |
import org.kuali.student.common.search.dto.SearchParam; |
27 | |
import org.kuali.student.common.search.dto.SearchRequest; |
28 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
29 | |
import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel; |
30 | |
import org.kuali.student.common.ui.client.widgets.search.SelectedResults; |
31 | |
import org.kuali.student.common.ui.client.widgets.searchtable.ResultRow; |
32 | |
|
33 | |
import com.google.gwt.event.dom.client.ClickEvent; |
34 | |
import com.google.gwt.event.dom.client.ClickHandler; |
35 | |
import com.google.gwt.user.client.ui.Composite; |
36 | |
import com.google.gwt.user.client.ui.FlowPanel; |
37 | |
|
38 | |
public class BrowsePanel extends Composite |
39 | |
{ |
40 | |
|
41 | |
|
42 | |
private FlowPanel layout; |
43 | |
private FlowPanel tablePanel; |
44 | 0 | private LookupMetadata lookupMetadata = null; |
45 | 0 | private SearchBackedTable searchBackedTable = null; |
46 | 0 | private boolean multiSelect = false; |
47 | |
|
48 | |
public interface OnSelectedCallback |
49 | |
{ |
50 | |
|
51 | |
public void selected (List<String> selectedIds); |
52 | |
|
53 | |
} |
54 | |
private OnSelectedCallback onSelectectedCallback; |
55 | |
|
56 | |
public BrowsePanel (LookupMetadata lookupMetadata) |
57 | 0 | { |
58 | 0 | this.lookupMetadata = lookupMetadata; |
59 | 0 | layout = new FlowPanel (); |
60 | 0 | layout.addStyleName ("KS-Picker-Border"); |
61 | 0 | layout.addStyleName ("KS-Advanced-Search-Panel"); |
62 | 0 | tablePanel = new FlowPanel (); |
63 | 0 | this.initWidget (layout); |
64 | 0 | } |
65 | |
|
66 | |
public Map<String, Object> parameters; |
67 | |
|
68 | |
public Map<String, Object> getParameters () |
69 | |
{ |
70 | 0 | if (parameters == null) |
71 | |
{ |
72 | 0 | parameters = new LinkedHashMap<String, Object> (); |
73 | |
} |
74 | 0 | return parameters; |
75 | |
} |
76 | |
|
77 | |
public void setParameters (Map<String, Object> parameters) |
78 | |
{ |
79 | 0 | this.parameters = parameters; |
80 | 0 | } |
81 | |
|
82 | |
private Map<String, Object> getDefaultParameters () |
83 | |
{ |
84 | 0 | Map<String, Object> defParms = new LinkedHashMap<String, Object> (); |
85 | 0 | for (LookupParamMetadata paramMeta : lookupMetadata.getParams ()) |
86 | |
{ |
87 | 0 | if (paramMeta.getDefaultValueString () != null) |
88 | |
{ |
89 | 0 | defParms.put (paramMeta.getKey (), paramMeta.getDefaultValueString ()); |
90 | 0 | continue; |
91 | |
} |
92 | 0 | if (paramMeta.getDefaultValueList () != null) |
93 | |
{ |
94 | 0 | defParms.put (paramMeta.getKey (), paramMeta.getDefaultValueList ()); |
95 | |
} |
96 | |
} |
97 | 0 | return defParms; |
98 | |
} |
99 | |
|
100 | |
public OnSelectedCallback getOnSelectectedCallback () |
101 | |
{ |
102 | 0 | return onSelectectedCallback; |
103 | |
} |
104 | |
|
105 | |
public void setOnSelectectedCallback (OnSelectedCallback onSelectectedCallback) |
106 | |
{ |
107 | 0 | this.onSelectectedCallback = onSelectectedCallback; |
108 | 0 | } |
109 | |
|
110 | |
private class SelectButtonClickHandler implements ClickHandler |
111 | |
{ |
112 | |
|
113 | |
private OnSelectedCallback callback; |
114 | |
private SearchBackedTable searchBackedTable; |
115 | |
|
116 | |
public SelectButtonClickHandler (OnSelectedCallback callback, |
117 | |
SearchBackedTable searchBackedTable) |
118 | 0 | { |
119 | 0 | this.callback = callback; |
120 | 0 | this.searchBackedTable = searchBackedTable; |
121 | 0 | } |
122 | |
|
123 | |
@Override |
124 | |
public void onClick (ClickEvent event) |
125 | |
{ |
126 | 0 | this.callback.selected (this.searchBackedTable.getSelectedIds ()); |
127 | 0 | } |
128 | |
|
129 | |
} |
130 | |
|
131 | |
|
132 | |
@SuppressWarnings("unchecked") |
133 | |
public void executeSearch () |
134 | |
{ |
135 | |
|
136 | 0 | tablePanel.clear (); |
137 | 0 | layout.clear (); |
138 | 0 | tablePanel.setVisible (false); |
139 | 0 | layout.add (tablePanel); |
140 | |
|
141 | |
|
142 | 0 | searchBackedTable = new SearchBackedTable (); |
143 | 0 | searchBackedTable.addStyleName ("KS-Advanced-Search-Results-Table"); |
144 | 0 | KSButton selectButton = |
145 | |
new KSButton ("Select", |
146 | |
new SelectButtonClickHandler (this.onSelectectedCallback, |
147 | |
this.searchBackedTable)); |
148 | 0 | tablePanel.add (searchBackedTable); |
149 | 0 | tablePanel.add (selectButton); |
150 | 0 | tablePanel.setVisible (false); |
151 | |
|
152 | 0 | SearchRequest searchRequest = new SearchRequest (); |
153 | 0 | List<SearchParam> searchParams = new ArrayList<SearchParam> (); |
154 | 0 | Map<String, Object> parms = getDefaultParameters (); |
155 | 0 | parms.putAll (getParameters ()); |
156 | 0 | for (Entry<String, Object> entry : parms.entrySet()) |
157 | |
{ |
158 | 0 | Object value = entry.getValue(); |
159 | 0 | SearchParam searchParam = new SearchParam (); |
160 | 0 | searchParam.setKey (entry.getKey()); |
161 | 0 | if (value instanceof String){ |
162 | 0 | searchParam.setValue ((String) value); |
163 | |
} else { |
164 | 0 | searchParam.setValue ((List<String>) value); |
165 | |
} |
166 | 0 | searchParams.add (searchParam); |
167 | 0 | } |
168 | 0 | searchRequest.setParams (searchParams); |
169 | 0 | searchRequest.setSearchKey (lookupMetadata.getSearchTypeId ()); |
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | 0 | searchBackedTable.performSearch (searchRequest, lookupMetadata.getResults (), lookupMetadata. |
189 | |
getResultReturnKey ()); |
190 | 0 | tablePanel.setVisible (true); |
191 | 0 | layout.setVisible (true); |
192 | 0 | } |
193 | |
|
194 | |
public List<String> getSelectedIds () |
195 | |
{ |
196 | 0 | List<String> ids = new ArrayList<String> (); |
197 | 0 | if (searchBackedTable != null) |
198 | |
{ |
199 | 0 | ids = searchBackedTable.getSelectedIds (); |
200 | |
} |
201 | 0 | return ids; |
202 | |
} |
203 | |
|
204 | |
public List<SelectedResults> getSelectedValues () |
205 | |
{ |
206 | |
|
207 | 0 | List<SelectedResults> selectedValues = new ArrayList<SelectedResults> (); |
208 | 0 | if (searchBackedTable != null) |
209 | |
{ |
210 | 0 | List<ResultRow> selectedRows = searchBackedTable.getSelectedRows (); |
211 | 0 | for (ResultRow row : selectedRows) |
212 | |
{ |
213 | 0 | String displayKey = row.getValue (lookupMetadata.getResultDisplayKey ()); |
214 | 0 | String returnKey = row.getValue (lookupMetadata.getResultReturnKey ()); |
215 | 0 | selectedValues.add (new SelectedResults (displayKey, returnKey)); |
216 | 0 | if (multiSelect == false) |
217 | |
{ |
218 | 0 | break; |
219 | |
} |
220 | 0 | } |
221 | |
} |
222 | |
|
223 | 0 | return selectedValues; |
224 | |
} |
225 | |
|
226 | |
public boolean isMultiSelect () |
227 | |
{ |
228 | 0 | return multiSelect; |
229 | |
} |
230 | |
|
231 | |
public void setMultiSelect (boolean multiSelect) |
232 | |
{ |
233 | 0 | this.multiSelect = multiSelect; |
234 | 0 | } |
235 | |
|
236 | |
} |