View Javadoc

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.view;
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.container.CollectionGroup;
22  import org.kuali.rice.krad.uif.container.Group;
23  import org.kuali.rice.krad.uif.component.Component;
24  import org.kuali.rice.krad.uif.component.RequestParameter;
25  import org.kuali.rice.krad.uif.field.Field;
26  import org.kuali.rice.krad.web.form.LookupForm;
27  
28  import java.util.Arrays;
29  import java.util.List;
30  
31  /**
32   * View type for Maintenance documents
33   *
34   * <p>
35   * Supports doing a search against a data object class or performing a more advanced query. The view
36   * type is primarily made up of two groups, the search (or criteria) group and the results group. Many
37   * options are supported on the view to enable/disable certain features, like what actions are available
38   * on the search results.
39   * </p>
40   *
41   * <p>
42   * Works in conjunction with <code>LookupableImpl</code> which customizes the view and carries out the
43   * business functionality
44   * </p>
45   *
46   * @author Kuali Rice Team (rice.collab@kuali.org)
47   */
48  public class LookupView extends FormView {
49      private static final long serialVersionUID = 716926008488403616L;
50  
51      private Class<?> dataObjectClassName;
52  
53      private Group criteriaGroup;
54      private CollectionGroup resultsGroup;
55  
56      private Field resultsActionsField;
57      private Field resultsReturnField;
58  
59      private List<Component> criteriaFields;
60      private List<Component> resultFields;
61      private List<String> defaultSortAttributeNames;
62  
63      protected boolean defaultSortAscending = true;
64  
65      @RequestParameter
66      private boolean hideReturnLinks = false;
67      @RequestParameter
68      private boolean suppressActions = false;
69      @RequestParameter
70      private boolean showMaintenanceLinks = false;
71      @RequestParameter
72      private boolean multipleValuesSelect = false;
73  
74      @RequestParameter
75      private String returnTarget;
76  
77      @RequestParameter
78      private boolean returnByScript;
79  
80      private boolean lookupCriteriaEnabled = true;
81      private boolean supplementalActionsEnabled = false;
82      private boolean disableSearchButtons = false;
83  
84      private Integer resultSetLimit = null;
85  
86      public LookupView() {
87          super();
88          setViewTypeName(ViewType.LOOKUP);
89          setValidateDirty(false);
90      }
91  
92      /**
93       * The following initialization is performed:
94       *
95       * <ul>
96       * <li>Set the abstractTypeClasses map for the lookup object path</li>
97       * </ul>
98       *
99       * @see org.kuali.rice.krad.uif.container.ContainerBase#performInitialization(org.kuali.rice.krad.uif.view.View, java.lang.Object)
100      */
101     @Override
102     public void performInitialization(View view, Object model) {
103         initializeGroups();
104         if (getItems().isEmpty()) {
105             setItems(Arrays.asList(getCriteriaGroup(), getResultsGroup()));
106         }
107         super.performInitialization(view, model);
108 
109         getAbstractTypeClasses().put(UifPropertyPaths.CRITERIA_FIELDS, getDataObjectClassName());
110         if (StringUtils.isNotBlank(getDefaultBindingObjectPath())) {
111             getAbstractTypeClasses().put(getDefaultBindingObjectPath(), getDataObjectClassName());
112         }
113     }
114 
115     protected void initializeGroups() {
116         if ((getCriteriaGroup() != null) && (getCriteriaGroup().getItems().isEmpty())) {
117             getCriteriaGroup().setItems(getCriteriaFields());
118         }
119         if (getResultsGroup() != null) {
120             if ((getResultsGroup().getItems().isEmpty()) && (getResultFields() != null)) {
121                 getResultsGroup().setItems(getResultFields());
122             }
123             if (getResultsGroup().getCollectionObjectClass() == null) {
124                 getResultsGroup().setCollectionObjectClass(getDataObjectClassName());
125             }
126         }
127     }
128 
129     /**
130      * @see org.kuali.rice.krad.uif.container.ContainerBase#performApplyModel(org.kuali.rice.krad.uif.view.View,
131      *      java.lang.Object)
132      */
133     @Override
134     public void performApplyModel(View view, Object model, Component parent) {
135         LookupForm lookupForm = (LookupForm) model;
136 
137         // TODO: need to check lookupForm.isAtLeastOneRowHasActions() somewhere
138         if (!isSuppressActions() && isShowMaintenanceLinks()) {
139             ((List<Field>) getResultsGroup().getItems()).add(0, getResultsActionsField());
140         }
141 
142         if (StringUtils.isNotBlank(lookupForm.getReturnFormKey()) &&
143                 StringUtils.isNotBlank(lookupForm.getReturnLocation()) && !isHideReturnLinks()) {
144             ((List<Field>) getResultsGroup().getItems()).add(0, getResultsReturnField());
145         }
146 
147         super.performApplyModel(view, model, parent);
148     }
149 
150     public void applyConditionalLogicForFieldDisplay() {
151         // TODO: work into view lifecycle
152 //	    LookupViewHelperService lookupViewHelperService = (LookupViewHelperService) getViewHelperService();
153 //		Set<String> readOnlyFields = lookupViewHelperService.getConditionallyReadOnlyPropertyNames();
154 //		Set<String> requiredFields = lookupViewHelperService.getConditionallyRequiredPropertyNames();
155 //		Set<String> hiddenFields = lookupViewHelperService.getConditionallyHiddenPropertyNames();
156 //		if ( (readOnlyFields != null && !readOnlyFields.isEmpty()) ||
157 //			 (requiredFields != null && !requiredFields.isEmpty()) ||
158 //			 (hiddenFields != null && !hiddenFields.isEmpty())
159 //			) {
160 //			for (Field field : getResultsGroup().getItems()) {
161 //				if (AttributeField.class.isAssignableFrom(field.getClass())) {
162 //					AttributeField attributeField = (AttributeField) field;
163 //					if (readOnlyFields != null && readOnlyFields.contains(attributeField.getBindingInfo().getBindingName())) {
164 //						attributeField.setReadOnly(true);
165 //					}
166 //					if (requiredFields != null && requiredFields.contains(attributeField.getBindingInfo().getBindingName())) {
167 //						attributeField.setRequired(Boolean.TRUE);
168 //					}
169 //					if (hiddenFields != null && hiddenFields.contains(attributeField.getBindingInfo().getBindingName())) {
170 //						attributeField.setControl(LookupInquiryUtils.generateCustomLookupControlFromExisting(HiddenControl.class, null));
171 //					}
172 //				}
173 //	        }
174 //		}
175     }
176 
177     /**
178      * Class name for the object the lookup applies to
179      *
180      * <p>
181      * The object class name is used to pick up a dictionary entry which will
182      * feed the attribute field definitions and other configuration. In addition
183      * it is to configure the <code>Lookupable</code> which will carry out the
184      * lookup action
185      * </p>
186      *
187      * @return Class<?> lookup data object class
188      */
189     public Class<?> getDataObjectClassName() {
190         return this.dataObjectClassName;
191     }
192 
193     /**
194      * Setter for the object class name
195      *
196      * @param dataObjectClassName
197      */
198     public void setDataObjectClassName(Class<?> dataObjectClassName) {
199         this.dataObjectClassName = dataObjectClassName;
200     }
201 
202     /**
203      * @return the hideReturnLinks
204      */
205     public boolean isHideReturnLinks() {
206         return this.hideReturnLinks;
207     }
208 
209     /**
210      * @param hideReturnLinks the hideReturnLinks to set
211      */
212     public void setHideReturnLinks(boolean hideReturnLinks) {
213         this.hideReturnLinks = hideReturnLinks;
214     }
215 
216     /**
217      * @return the suppressActions
218      */
219     public boolean isSuppressActions() {
220         return this.suppressActions;
221     }
222 
223     /**
224      * @param suppressActions the suppressActions to set
225      */
226     public void setSuppressActions(boolean suppressActions) {
227         this.suppressActions = suppressActions;
228     }
229 
230     /**
231      * @return the showMaintenanceLinks
232      */
233     public boolean isShowMaintenanceLinks() {
234         return this.showMaintenanceLinks;
235     }
236 
237     /**
238      * @param showMaintenanceLinks the showMaintenanceLinks to set
239      */
240     public void setShowMaintenanceLinks(boolean showMaintenanceLinks) {
241         this.showMaintenanceLinks = showMaintenanceLinks;
242     }
243 
244     /**
245      * Indicates whether multiple values select should be enabled for the lookup
246      *
247      * <p>
248      * When set to true, the select field is enabled for the lookup results group that allows the user
249      * to select one or more rows for returning
250      * </p>
251      *
252      * @return boolean true if multiple values should be enabled, false otherwise
253      */
254     public boolean isMultipleValuesSelect() {
255         return multipleValuesSelect;
256     }
257 
258     /**
259      * Setter for the multiple values select indicator
260      *
261      * @param multipleValuesSelect
262      */
263     public void setMultipleValuesSelect(boolean multipleValuesSelect) {
264         this.multipleValuesSelect = multipleValuesSelect;
265     }
266 
267     /**
268      * @return the resultsActionsField
269      */
270     public Field getResultsActionsField() {
271         return this.resultsActionsField;
272     }
273 
274     /**
275      * @param resultsActionsField the resultsActionsField to set
276      */
277     public void setResultsActionsField(Field resultsActionsField) {
278         this.resultsActionsField = resultsActionsField;
279     }
280 
281     /**
282      * @return the resultsReturnField
283      */
284     public Field getResultsReturnField() {
285         return this.resultsReturnField;
286     }
287 
288     /**
289      * @param resultsReturnField the resultsReturnField to set
290      */
291     public void setResultsReturnField(Field resultsReturnField) {
292         this.resultsReturnField = resultsReturnField;
293     }
294 
295     public Group getCriteriaGroup() {
296         return this.criteriaGroup;
297     }
298 
299     public void setCriteriaGroup(Group criteriaGroup) {
300         this.criteriaGroup = criteriaGroup;
301     }
302 
303     public CollectionGroup getResultsGroup() {
304         return this.resultsGroup;
305     }
306 
307     public void setResultsGroup(CollectionGroup resultsGroup) {
308         this.resultsGroup = resultsGroup;
309     }
310 
311     public List<Component> getCriteriaFields() {
312         return this.criteriaFields;
313     }
314 
315     public void setCriteriaFields(List<Component> criteriaFields) {
316         this.criteriaFields = criteriaFields;
317     }
318 
319     public List<Component> getResultFields() {
320         return this.resultFields;
321     }
322 
323     public void setResultFields(List<Component> resultFields) {
324         this.resultFields = resultFields;
325     }
326 
327     public List<String> getDefaultSortAttributeNames() {
328         return this.defaultSortAttributeNames;
329     }
330 
331     public void setDefaultSortAttributeNames(List<String> defaultSortAttributeNames) {
332         this.defaultSortAttributeNames = defaultSortAttributeNames;
333     }
334 
335     public boolean isDefaultSortAscending() {
336         return this.defaultSortAscending;
337     }
338 
339     public void setDefaultSortAscending(boolean defaultSortAscending) {
340         this.defaultSortAscending = defaultSortAscending;
341     }
342 
343     /**
344      * Retrieves the maximum number of records that will be listed
345      * as a result of the lookup search
346      *
347      * @return Integer result set limit
348      */
349     public Integer getResultSetLimit() {
350         return resultSetLimit;
351     }
352 
353     /**
354      * Setter for the result list limit
355      *
356      * @param resultSetLimit Integer specifying limit
357      */
358     public void setResultSetLimit(Integer resultSetLimit) {
359         this.resultSetLimit = resultSetLimit;
360     }
361 
362     /**
363      * Indicates whether a result set limit has been specified for the
364      * view
365      *
366      * @return true if this instance has a result set limit
367      */
368     public boolean hasResultSetLimit() {
369         return (resultSetLimit != null);
370     }
371 
372     /**
373      * @param returnTarget the returnTarget to set
374      */
375     public void setReturnTarget(String returnTarget) {
376         this.returnTarget = returnTarget;
377     }
378 
379     /**
380      * @return the returnTarget
381      */
382     public String getReturnTarget() {
383         return returnTarget;
384     }
385 
386     /**
387      * @return the returnByScript
388      */
389     public boolean isReturnByScript() {
390         return returnByScript;
391     }
392 
393     /**
394      * Setter for the flag to indicate that lookups will return the value
395      * by script and not a post
396      *
397      * @param returnByScript the returnByScript flag
398      */
399     public void setReturnByScript(boolean returnByScript) {
400         this.returnByScript = returnByScript;
401     }
402 }