1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.uif.container; |
17 | |
|
18 | |
import java.util.Arrays; |
19 | |
import java.util.List; |
20 | |
import java.util.Set; |
21 | |
|
22 | |
import org.apache.commons.lang.StringUtils; |
23 | |
import org.kuali.rice.kns.uif.UifConstants.ViewType; |
24 | |
import org.kuali.rice.kns.uif.UifPropertyPaths; |
25 | |
import org.kuali.rice.kns.uif.control.HiddenControl; |
26 | |
import org.kuali.rice.kns.uif.core.Component; |
27 | |
import org.kuali.rice.kns.uif.core.RequestParameter; |
28 | |
import org.kuali.rice.kns.uif.field.AttributeField; |
29 | |
import org.kuali.rice.kns.uif.field.Field; |
30 | |
import org.kuali.rice.kns.uif.service.LookupViewHelperService; |
31 | |
import org.kuali.rice.kns.uif.util.LookupInquiryUtils; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class LookupView extends FormView { |
39 | |
private static final long serialVersionUID = 716926008488403616L; |
40 | |
|
41 | |
private Class<?> dataObjectClassName; |
42 | |
|
43 | |
private Group criteriaGroup; |
44 | |
private CollectionGroup resultsGroup; |
45 | |
private Field resultsActionsField; |
46 | |
private Field resultsReturnField; |
47 | |
|
48 | |
private List<Component> criteriaFields; |
49 | |
private List<Component> resultFields; |
50 | |
private List<String> defaultSortAttributeNames; |
51 | 0 | protected boolean sortAscending = true; |
52 | |
|
53 | 0 | @RequestParameter |
54 | |
private boolean hideReturnLinks = false; |
55 | 0 | @RequestParameter |
56 | |
private boolean suppressActions = false; |
57 | 0 | @RequestParameter |
58 | |
private boolean showMaintenanceLinks = false; |
59 | |
|
60 | 0 | private boolean multipleValues = false; |
61 | 0 | private boolean lookupCriteriaEnabled = true; |
62 | 0 | private boolean supplementalActionsEnabled = false; |
63 | 0 | private boolean ddExtraButton = false; |
64 | 0 | private boolean headerBarEnabled = true; |
65 | 0 | private boolean disableSearchButtons = false; |
66 | |
|
67 | |
public LookupView() { |
68 | 0 | super(); |
69 | 0 | setViewTypeName(ViewType.LOOKUP); |
70 | 0 | setValidateDirty(false); |
71 | 0 | } |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
@Override |
84 | |
public void performInitialization(View view) { |
85 | 0 | initializeGroups(); |
86 | 0 | if (getItems().isEmpty()) { |
87 | 0 | setItems(Arrays.asList(getCriteriaGroup(), getResultsGroup())); |
88 | |
} |
89 | 0 | super.performInitialization(view); |
90 | |
|
91 | 0 | getAbstractTypeClasses().put(UifPropertyPaths.CRITERIA_FIELDS, getDataObjectClassName()); |
92 | 0 | if (StringUtils.isNotBlank(getDefaultBindingObjectPath())) { |
93 | 0 | getAbstractTypeClasses().put(getDefaultBindingObjectPath(), getDataObjectClassName()); |
94 | |
} |
95 | 0 | } |
96 | |
|
97 | |
protected void initializeGroups() { |
98 | 0 | if ((getCriteriaGroup() != null) && (getCriteriaGroup().getItems().isEmpty())) { |
99 | 0 | getCriteriaGroup().setItems(getCriteriaFields()); |
100 | |
} |
101 | 0 | if (getResultsGroup() != null) { |
102 | 0 | if ( (getResultsGroup().getItems().isEmpty()) && (getResultFields() != null) ) { |
103 | 0 | getResultsGroup().setItems(getResultFields()); |
104 | |
} |
105 | 0 | if (getResultsGroup().getCollectionObjectClass() == null) { |
106 | 0 | getResultsGroup().setCollectionObjectClass(getDataObjectClassName()); |
107 | |
} |
108 | |
} |
109 | 0 | } |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
@Override |
115 | |
public void performApplyModel(View view, Object model) { |
116 | 0 | if (isRenderActionsFields()) { |
117 | 0 | ((List<Field>)getResultsGroup().getItems()).add(0, getResultsActionsField()); |
118 | |
} |
119 | 0 | if (isRenderReturnFields()) { |
120 | 0 | ((List<Field>)getResultsGroup().getItems()).add(0, getResultsReturnField()); |
121 | |
} |
122 | 0 | applyConditionalLogicForFieldDisplay(); |
123 | 0 | super.performApplyModel(view, model); |
124 | 0 | } |
125 | |
|
126 | |
public void applyConditionalLogicForFieldDisplay() { |
127 | 0 | LookupViewHelperService lookupViewHelperService = (LookupViewHelperService) getViewHelperService(); |
128 | 0 | Set<String> readOnlyFields = lookupViewHelperService.getConditionallyReadOnlyPropertyNames(); |
129 | 0 | Set<String> requiredFields = lookupViewHelperService.getConditionallyRequiredPropertyNames(); |
130 | 0 | Set<String> hiddenFields = lookupViewHelperService.getConditionallyHiddenPropertyNames(); |
131 | 0 | if ( (readOnlyFields != null && !readOnlyFields.isEmpty()) || |
132 | |
(requiredFields != null && !requiredFields.isEmpty()) || |
133 | |
(hiddenFields != null && !hiddenFields.isEmpty()) |
134 | |
) { |
135 | 0 | for (Field field : getResultsGroup().getItems()) { |
136 | 0 | if (AttributeField.class.isAssignableFrom(field.getClass())) { |
137 | 0 | AttributeField attributeField = (AttributeField) field; |
138 | 0 | if (readOnlyFields != null && readOnlyFields.contains(attributeField.getBindingInfo().getBindingName())) { |
139 | 0 | attributeField.setReadOnly(true); |
140 | |
} |
141 | 0 | if (requiredFields != null && requiredFields.contains(attributeField.getBindingInfo().getBindingName())) { |
142 | 0 | attributeField.setRequired(Boolean.TRUE); |
143 | |
} |
144 | 0 | if (hiddenFields != null && hiddenFields.contains(attributeField.getBindingInfo().getBindingName())) { |
145 | 0 | attributeField.setControl(LookupInquiryUtils.generateCustomLookupControlFromExisting(HiddenControl.class, null)); |
146 | |
} |
147 | 0 | } |
148 | |
} |
149 | |
} |
150 | 0 | } |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
@SuppressWarnings("unchecked") |
156 | |
@Override |
157 | |
public void performFinalize(View view, Object model, Component parent) { |
158 | 0 | super.performFinalize(view, model, parent); |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | 0 | } |
166 | |
|
167 | |
public boolean isRenderActionsFields(){ |
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | 0 | LookupViewHelperService lookupHelperService = (LookupViewHelperService) getViewHelperService(); |
178 | 0 | return ( (lookupHelperService.isAtLeastOneRowHasActions()) && |
179 | |
(!isSuppressActions()) && |
180 | |
(isShowMaintenanceLinks()) |
181 | |
); |
182 | |
} |
183 | |
|
184 | |
public boolean isRenderReturnFields(){ |
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | 0 | LookupViewHelperService lookupHelperService = (LookupViewHelperService) getViewHelperService(); |
195 | 0 | return ( (StringUtils.isNotBlank(lookupHelperService.getReturnFormKey())) && |
196 | |
(StringUtils.isNotBlank(lookupHelperService.getReturnLocation())) && |
197 | |
(!isHideReturnLinks()) |
198 | |
); |
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
} |
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
public Class<?> getDataObjectClassName() { |
223 | 0 | return this.dataObjectClassName; |
224 | |
} |
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
public void setDataObjectClassName(Class<?> dataObjectClassName) { |
232 | 0 | this.dataObjectClassName = dataObjectClassName; |
233 | 0 | } |
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
public boolean isHideReturnLinks() { |
239 | 0 | return this.hideReturnLinks; |
240 | |
} |
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
public void setHideReturnLinks(boolean hideReturnLinks) { |
246 | 0 | this.hideReturnLinks = hideReturnLinks; |
247 | 0 | } |
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
public boolean isSuppressActions() { |
253 | 0 | return this.suppressActions; |
254 | |
} |
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
public void setSuppressActions(boolean suppressActions) { |
260 | 0 | this.suppressActions = suppressActions; |
261 | 0 | } |
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
public boolean isShowMaintenanceLinks() { |
267 | 0 | return this.showMaintenanceLinks; |
268 | |
} |
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
public void setShowMaintenanceLinks(boolean showMaintenanceLinks) { |
274 | 0 | this.showMaintenanceLinks = showMaintenanceLinks; |
275 | 0 | } |
276 | |
|
277 | |
|
278 | |
|
279 | |
|
280 | |
public Field getResultsActionsField() { |
281 | 0 | return this.resultsActionsField; |
282 | |
} |
283 | |
|
284 | |
|
285 | |
|
286 | |
|
287 | |
public void setResultsActionsField(Field resultsActionsField) { |
288 | 0 | this.resultsActionsField = resultsActionsField; |
289 | 0 | } |
290 | |
|
291 | |
|
292 | |
|
293 | |
|
294 | |
public Field getResultsReturnField() { |
295 | 0 | return this.resultsReturnField; |
296 | |
} |
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
public void setResultsReturnField(Field resultsReturnField) { |
302 | 0 | this.resultsReturnField = resultsReturnField; |
303 | 0 | } |
304 | |
|
305 | |
public Group getCriteriaGroup() { |
306 | 0 | return this.criteriaGroup; |
307 | |
} |
308 | |
|
309 | |
public void setCriteriaGroup(Group criteriaGroup) { |
310 | 0 | this.criteriaGroup = criteriaGroup; |
311 | 0 | } |
312 | |
|
313 | |
public CollectionGroup getResultsGroup() { |
314 | 0 | return this.resultsGroup; |
315 | |
} |
316 | |
|
317 | |
public void setResultsGroup(CollectionGroup resultsGroup) { |
318 | 0 | this.resultsGroup = resultsGroup; |
319 | 0 | } |
320 | |
|
321 | |
public List<Component> getCriteriaFields() { |
322 | 0 | return this.criteriaFields; |
323 | |
} |
324 | |
|
325 | |
public void setCriteriaFields(List<Component> criteriaFields) { |
326 | 0 | this.criteriaFields = criteriaFields; |
327 | 0 | } |
328 | |
|
329 | |
public List<Component> getResultFields() { |
330 | 0 | return this.resultFields; |
331 | |
} |
332 | |
|
333 | |
public void setResultFields(List<Component> resultFields) { |
334 | 0 | this.resultFields = resultFields; |
335 | 0 | } |
336 | |
|
337 | |
public List<String> getDefaultSortAttributeNames() { |
338 | 0 | return this.defaultSortAttributeNames; |
339 | |
} |
340 | |
|
341 | |
public void setDefaultSortAttributeNames(List<String> defaultSortAttributeNames) { |
342 | 0 | this.defaultSortAttributeNames = defaultSortAttributeNames; |
343 | 0 | } |
344 | |
|
345 | |
public boolean isSortAscending() { |
346 | 0 | return this.sortAscending; |
347 | |
} |
348 | |
|
349 | |
public void setSortAscending(boolean sortAscending) { |
350 | 0 | this.sortAscending = sortAscending; |
351 | 0 | } |
352 | |
|
353 | |
} |