Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
LookupView |
|
| 1.40625;1.406 |
1 | /* | |
2 | * Copyright 2007 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 1.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl1.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.kuali.rice.krad.uif.container; | |
17 | ||
18 | import org.apache.commons.lang.StringUtils; | |
19 | import org.kuali.rice.krad.uif.UifConstants.ViewType; | |
20 | import org.kuali.rice.krad.uif.UifPropertyPaths; | |
21 | import org.kuali.rice.krad.uif.core.Component; | |
22 | import org.kuali.rice.krad.uif.core.RequestParameter; | |
23 | import org.kuali.rice.krad.uif.field.Field; | |
24 | import org.kuali.rice.krad.web.form.LookupForm; | |
25 | ||
26 | import java.util.Arrays; | |
27 | import java.util.List; | |
28 | ||
29 | /** | |
30 | * View type for Maintenance documents | |
31 | * | |
32 | * <p> | |
33 | * Supports doing a search against a data object class or performing a more advanced query. The view | |
34 | * type is primarily made up of two groups, the search (or criteria) group and the results group. Many | |
35 | * options are supported on the view to enable/disable certain features, like what actions are available | |
36 | * on the search results. | |
37 | * </p> | |
38 | * | |
39 | * <p> | |
40 | * Works in conjunction with <code>LookupableImpl</code> which customizes the view and carries out the | |
41 | * business functionality | |
42 | * </p> | |
43 | * | |
44 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
45 | */ | |
46 | public class LookupView extends FormView { | |
47 | private static final long serialVersionUID = 716926008488403616L; | |
48 | ||
49 | private Class<?> dataObjectClassName; | |
50 | ||
51 | private Group criteriaGroup; | |
52 | private CollectionGroup resultsGroup; | |
53 | ||
54 | private Field resultsActionsField; | |
55 | private Field resultsReturnField; | |
56 | ||
57 | private List<Component> criteriaFields; | |
58 | private List<Component> resultFields; | |
59 | private List<String> defaultSortAttributeNames; | |
60 | ||
61 | 0 | protected boolean sortAscending = true; |
62 | ||
63 | 0 | @RequestParameter |
64 | private boolean hideReturnLinks = false; | |
65 | 0 | @RequestParameter |
66 | private boolean suppressActions = false; | |
67 | 0 | @RequestParameter |
68 | private boolean showMaintenanceLinks = false; | |
69 | ||
70 | 0 | private boolean multipleValues = false; |
71 | 0 | private boolean lookupCriteriaEnabled = true; |
72 | 0 | private boolean supplementalActionsEnabled = false; |
73 | 0 | private boolean disableSearchButtons = false; |
74 | ||
75 | 0 | private Integer resultSetLimit = null; |
76 | ||
77 | public LookupView() { | |
78 | 0 | super(); |
79 | 0 | setViewTypeName(ViewType.LOOKUP); |
80 | 0 | setValidateDirty(false); |
81 | 0 | } |
82 | ||
83 | /** | |
84 | * The following initialization is performed: | |
85 | * | |
86 | * <ul> | |
87 | * <li>Set the abstractTypeClasses map for the lookup object path</li> | |
88 | * </ul> | |
89 | * | |
90 | * @see org.kuali.rice.krad.uif.container.ContainerBase#performInitialization(org.kuali.rice.krad.uif.container.View) | |
91 | */ | |
92 | @Override | |
93 | public void performInitialization(View view) { | |
94 | 0 | initializeGroups(); |
95 | 0 | if (getItems().isEmpty()) { |
96 | 0 | setItems(Arrays.asList(getCriteriaGroup(), getResultsGroup())); |
97 | } | |
98 | 0 | super.performInitialization(view); |
99 | ||
100 | 0 | getAbstractTypeClasses().put(UifPropertyPaths.CRITERIA_FIELDS, getDataObjectClassName()); |
101 | 0 | if (StringUtils.isNotBlank(getDefaultBindingObjectPath())) { |
102 | 0 | getAbstractTypeClasses().put(getDefaultBindingObjectPath(), getDataObjectClassName()); |
103 | } | |
104 | 0 | } |
105 | ||
106 | protected void initializeGroups() { | |
107 | 0 | if ((getCriteriaGroup() != null) && (getCriteriaGroup().getItems().isEmpty())) { |
108 | 0 | getCriteriaGroup().setItems(getCriteriaFields()); |
109 | } | |
110 | 0 | if (getResultsGroup() != null) { |
111 | 0 | if ((getResultsGroup().getItems().isEmpty()) && (getResultFields() != null)) { |
112 | 0 | getResultsGroup().setItems(getResultFields()); |
113 | } | |
114 | 0 | if (getResultsGroup().getCollectionObjectClass() == null) { |
115 | 0 | getResultsGroup().setCollectionObjectClass(getDataObjectClassName()); |
116 | } | |
117 | } | |
118 | 0 | } |
119 | ||
120 | /** | |
121 | * @see org.kuali.rice.krad.uif.container.ContainerBase#performApplyModel(org.kuali.rice.krad.uif.container.View, | |
122 | * java.lang.Object) | |
123 | */ | |
124 | @Override | |
125 | public void performApplyModel(View view, Object model, Component parent) { | |
126 | 0 | LookupForm lookupForm = (LookupForm) model; |
127 | ||
128 | ||
129 | // TODO: need to check lookupForm.isAtLeastOneRowHasActions() somewhere | |
130 | 0 | if (!isSuppressActions() && isShowMaintenanceLinks()) { |
131 | 0 | ((List<Field>) getResultsGroup().getItems()).add(0, getResultsActionsField()); |
132 | } | |
133 | ||
134 | 0 | if (StringUtils.isNotBlank(lookupForm.getReturnFormKey()) && |
135 | StringUtils.isNotBlank(lookupForm.getReturnLocation()) && !isHideReturnLinks()) { | |
136 | 0 | ((List<Field>) getResultsGroup().getItems()).add(0, getResultsReturnField()); |
137 | } | |
138 | ||
139 | 0 | super.performApplyModel(view, model, parent); |
140 | 0 | } |
141 | ||
142 | public void applyConditionalLogicForFieldDisplay() { | |
143 | // TODO: work into view lifecycle | |
144 | // LookupViewHelperService lookupViewHelperService = (LookupViewHelperService) getViewHelperService(); | |
145 | // Set<String> readOnlyFields = lookupViewHelperService.getConditionallyReadOnlyPropertyNames(); | |
146 | // Set<String> requiredFields = lookupViewHelperService.getConditionallyRequiredPropertyNames(); | |
147 | // Set<String> hiddenFields = lookupViewHelperService.getConditionallyHiddenPropertyNames(); | |
148 | // if ( (readOnlyFields != null && !readOnlyFields.isEmpty()) || | |
149 | // (requiredFields != null && !requiredFields.isEmpty()) || | |
150 | // (hiddenFields != null && !hiddenFields.isEmpty()) | |
151 | // ) { | |
152 | // for (Field field : getResultsGroup().getItems()) { | |
153 | // if (AttributeField.class.isAssignableFrom(field.getClass())) { | |
154 | // AttributeField attributeField = (AttributeField) field; | |
155 | // if (readOnlyFields != null && readOnlyFields.contains(attributeField.getBindingInfo().getBindingName())) { | |
156 | // attributeField.setReadOnly(true); | |
157 | // } | |
158 | // if (requiredFields != null && requiredFields.contains(attributeField.getBindingInfo().getBindingName())) { | |
159 | // attributeField.setRequired(Boolean.TRUE); | |
160 | // } | |
161 | // if (hiddenFields != null && hiddenFields.contains(attributeField.getBindingInfo().getBindingName())) { | |
162 | // attributeField.setControl(LookupInquiryUtils.generateCustomLookupControlFromExisting(HiddenControl.class, null)); | |
163 | // } | |
164 | // } | |
165 | // } | |
166 | // } | |
167 | 0 | } |
168 | ||
169 | /** | |
170 | * Class name for the object the lookup applies to | |
171 | * | |
172 | * <p> | |
173 | * The object class name is used to pick up a dictionary entry which will | |
174 | * feed the attribute field definitions and other configuration. In addition | |
175 | * it is to configure the <code>Lookupable</code> which will carry out the | |
176 | * lookup action | |
177 | * </p> | |
178 | * | |
179 | * @return Class<?> lookup data object class | |
180 | */ | |
181 | public Class<?> getDataObjectClassName() { | |
182 | 0 | return this.dataObjectClassName; |
183 | } | |
184 | ||
185 | /** | |
186 | * Setter for the object class name | |
187 | * | |
188 | * @param dataObjectClassName | |
189 | */ | |
190 | public void setDataObjectClassName(Class<?> dataObjectClassName) { | |
191 | 0 | this.dataObjectClassName = dataObjectClassName; |
192 | 0 | } |
193 | ||
194 | /** | |
195 | * @return the hideReturnLinks | |
196 | */ | |
197 | public boolean isHideReturnLinks() { | |
198 | 0 | return this.hideReturnLinks; |
199 | } | |
200 | ||
201 | /** | |
202 | * @param hideReturnLinks the hideReturnLinks to set | |
203 | */ | |
204 | public void setHideReturnLinks(boolean hideReturnLinks) { | |
205 | 0 | this.hideReturnLinks = hideReturnLinks; |
206 | 0 | } |
207 | ||
208 | /** | |
209 | * @return the suppressActions | |
210 | */ | |
211 | public boolean isSuppressActions() { | |
212 | 0 | return this.suppressActions; |
213 | } | |
214 | ||
215 | /** | |
216 | * @param suppressActions the suppressActions to set | |
217 | */ | |
218 | public void setSuppressActions(boolean suppressActions) { | |
219 | 0 | this.suppressActions = suppressActions; |
220 | 0 | } |
221 | ||
222 | /** | |
223 | * @return the showMaintenanceLinks | |
224 | */ | |
225 | public boolean isShowMaintenanceLinks() { | |
226 | 0 | return this.showMaintenanceLinks; |
227 | } | |
228 | ||
229 | /** | |
230 | * @param showMaintenanceLinks the showMaintenanceLinks to set | |
231 | */ | |
232 | public void setShowMaintenanceLinks(boolean showMaintenanceLinks) { | |
233 | 0 | this.showMaintenanceLinks = showMaintenanceLinks; |
234 | 0 | } |
235 | ||
236 | /** | |
237 | * @return the resultsActionsField | |
238 | */ | |
239 | public Field getResultsActionsField() { | |
240 | 0 | return this.resultsActionsField; |
241 | } | |
242 | ||
243 | /** | |
244 | * @param resultsActionsField the resultsActionsField to set | |
245 | */ | |
246 | public void setResultsActionsField(Field resultsActionsField) { | |
247 | 0 | this.resultsActionsField = resultsActionsField; |
248 | 0 | } |
249 | ||
250 | /** | |
251 | * @return the resultsReturnField | |
252 | */ | |
253 | public Field getResultsReturnField() { | |
254 | 0 | return this.resultsReturnField; |
255 | } | |
256 | ||
257 | /** | |
258 | * @param resultsReturnField the resultsReturnField to set | |
259 | */ | |
260 | public void setResultsReturnField(Field resultsReturnField) { | |
261 | 0 | this.resultsReturnField = resultsReturnField; |
262 | 0 | } |
263 | ||
264 | public Group getCriteriaGroup() { | |
265 | 0 | return this.criteriaGroup; |
266 | } | |
267 | ||
268 | public void setCriteriaGroup(Group criteriaGroup) { | |
269 | 0 | this.criteriaGroup = criteriaGroup; |
270 | 0 | } |
271 | ||
272 | public CollectionGroup getResultsGroup() { | |
273 | 0 | return this.resultsGroup; |
274 | } | |
275 | ||
276 | public void setResultsGroup(CollectionGroup resultsGroup) { | |
277 | 0 | this.resultsGroup = resultsGroup; |
278 | 0 | } |
279 | ||
280 | public List<Component> getCriteriaFields() { | |
281 | 0 | return this.criteriaFields; |
282 | } | |
283 | ||
284 | public void setCriteriaFields(List<Component> criteriaFields) { | |
285 | 0 | this.criteriaFields = criteriaFields; |
286 | 0 | } |
287 | ||
288 | public List<Component> getResultFields() { | |
289 | 0 | return this.resultFields; |
290 | } | |
291 | ||
292 | public void setResultFields(List<Component> resultFields) { | |
293 | 0 | this.resultFields = resultFields; |
294 | 0 | } |
295 | ||
296 | public List<String> getDefaultSortAttributeNames() { | |
297 | 0 | return this.defaultSortAttributeNames; |
298 | } | |
299 | ||
300 | public void setDefaultSortAttributeNames(List<String> defaultSortAttributeNames) { | |
301 | 0 | this.defaultSortAttributeNames = defaultSortAttributeNames; |
302 | 0 | } |
303 | ||
304 | public boolean isSortAscending() { | |
305 | 0 | return this.sortAscending; |
306 | } | |
307 | ||
308 | public void setSortAscending(boolean sortAscending) { | |
309 | 0 | this.sortAscending = sortAscending; |
310 | 0 | } |
311 | ||
312 | /** | |
313 | * Retrieves the maximum number of records that will be listed | |
314 | * as a result of the lookup search | |
315 | * | |
316 | * @return Integer result set limit | |
317 | */ | |
318 | public Integer getResultSetLimit() { | |
319 | 0 | return resultSetLimit; |
320 | } | |
321 | ||
322 | /** | |
323 | * Setter for the result list limit | |
324 | * | |
325 | * @param resultSetLimit Integer specifying limit | |
326 | */ | |
327 | public void setResultSetLimit(Integer resultSetLimit) { | |
328 | 0 | this.resultSetLimit = resultSetLimit; |
329 | 0 | } |
330 | ||
331 | /** | |
332 | * Indicates whether a result set limit has been specified for the | |
333 | * view | |
334 | * | |
335 | * @return true if this instance has a result set limit | |
336 | */ | |
337 | public boolean hasResultSetLimit() { | |
338 | 0 | return (resultSetLimit != null); |
339 | } | |
340 | } |