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.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      protected boolean defaultSortAscending = true;
62  
63      @RequestParameter
64      private boolean hideReturnLinks = false;
65      @RequestParameter
66      private boolean suppressActions = false;
67      @RequestParameter
68      private boolean showMaintenanceLinks = false;
69  
70      private boolean multipleValues = false;
71      private boolean lookupCriteriaEnabled = true;
72      private boolean supplementalActionsEnabled = false;
73      private boolean disableSearchButtons = false;
74  
75      private Integer resultSetLimit = null;
76  
77      public LookupView() {
78          super();
79          setViewTypeName(ViewType.LOOKUP);
80          setValidateDirty(false);
81      }
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          initializeGroups();
95          if (getItems().isEmpty()) {
96              setItems(Arrays.asList(getCriteriaGroup(), getResultsGroup()));
97          }
98          super.performInitialization(view);
99  
100         getAbstractTypeClasses().put(UifPropertyPaths.CRITERIA_FIELDS, getDataObjectClassName());
101         if (StringUtils.isNotBlank(getDefaultBindingObjectPath())) {
102             getAbstractTypeClasses().put(getDefaultBindingObjectPath(), getDataObjectClassName());
103         }
104     }
105 
106     protected void initializeGroups() {
107         if ((getCriteriaGroup() != null) && (getCriteriaGroup().getItems().isEmpty())) {
108             getCriteriaGroup().setItems(getCriteriaFields());
109         }
110         if (getResultsGroup() != null) {
111             if ((getResultsGroup().getItems().isEmpty()) && (getResultFields() != null)) {
112                 getResultsGroup().setItems(getResultFields());
113             }
114             if (getResultsGroup().getCollectionObjectClass() == null) {
115                 getResultsGroup().setCollectionObjectClass(getDataObjectClassName());
116             }
117         }
118     }
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         LookupForm lookupForm = (LookupForm) model;
127 
128 
129         // TODO: need to check lookupForm.isAtLeastOneRowHasActions() somewhere
130         if (!isSuppressActions() && isShowMaintenanceLinks()) {
131             ((List<Field>) getResultsGroup().getItems()).add(0, getResultsActionsField());
132         }
133 
134         if (StringUtils.isNotBlank(lookupForm.getReturnFormKey()) &&
135                 StringUtils.isNotBlank(lookupForm.getReturnLocation()) && !isHideReturnLinks()) {
136             ((List<Field>) getResultsGroup().getItems()).add(0, getResultsReturnField());
137         }
138 
139         super.performApplyModel(view, model, parent);
140     }
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     }
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         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         this.dataObjectClassName = dataObjectClassName;
192     }
193 
194     /**
195      * @return the hideReturnLinks
196      */
197     public boolean isHideReturnLinks() {
198         return this.hideReturnLinks;
199     }
200 
201     /**
202      * @param hideReturnLinks the hideReturnLinks to set
203      */
204     public void setHideReturnLinks(boolean hideReturnLinks) {
205         this.hideReturnLinks = hideReturnLinks;
206     }
207 
208     /**
209      * @return the suppressActions
210      */
211     public boolean isSuppressActions() {
212         return this.suppressActions;
213     }
214 
215     /**
216      * @param suppressActions the suppressActions to set
217      */
218     public void setSuppressActions(boolean suppressActions) {
219         this.suppressActions = suppressActions;
220     }
221 
222     /**
223      * @return the showMaintenanceLinks
224      */
225     public boolean isShowMaintenanceLinks() {
226         return this.showMaintenanceLinks;
227     }
228 
229     /**
230      * @param showMaintenanceLinks the showMaintenanceLinks to set
231      */
232     public void setShowMaintenanceLinks(boolean showMaintenanceLinks) {
233         this.showMaintenanceLinks = showMaintenanceLinks;
234     }
235 
236     /**
237      * @return the resultsActionsField
238      */
239     public Field getResultsActionsField() {
240         return this.resultsActionsField;
241     }
242 
243     /**
244      * @param resultsActionsField the resultsActionsField to set
245      */
246     public void setResultsActionsField(Field resultsActionsField) {
247         this.resultsActionsField = resultsActionsField;
248     }
249 
250     /**
251      * @return the resultsReturnField
252      */
253     public Field getResultsReturnField() {
254         return this.resultsReturnField;
255     }
256 
257     /**
258      * @param resultsReturnField the resultsReturnField to set
259      */
260     public void setResultsReturnField(Field resultsReturnField) {
261         this.resultsReturnField = resultsReturnField;
262     }
263 
264     public Group getCriteriaGroup() {
265         return this.criteriaGroup;
266     }
267 
268     public void setCriteriaGroup(Group criteriaGroup) {
269         this.criteriaGroup = criteriaGroup;
270     }
271 
272     public CollectionGroup getResultsGroup() {
273         return this.resultsGroup;
274     }
275 
276     public void setResultsGroup(CollectionGroup resultsGroup) {
277         this.resultsGroup = resultsGroup;
278     }
279 
280     public List<Component> getCriteriaFields() {
281         return this.criteriaFields;
282     }
283 
284     public void setCriteriaFields(List<Component> criteriaFields) {
285         this.criteriaFields = criteriaFields;
286     }
287 
288     public List<Component> getResultFields() {
289         return this.resultFields;
290     }
291 
292     public void setResultFields(List<Component> resultFields) {
293         this.resultFields = resultFields;
294     }
295 
296     public List<String> getDefaultSortAttributeNames() {
297         return this.defaultSortAttributeNames;
298     }
299 
300     public void setDefaultSortAttributeNames(List<String> defaultSortAttributeNames) {
301         this.defaultSortAttributeNames = defaultSortAttributeNames;
302     }
303 
304     public boolean isDefaultSortAscending() {
305         return this.defaultSortAscending;
306     }
307 
308     public void setDefaultSortAscending(boolean defaultSortAscending) {
309         this.defaultSortAscending = defaultSortAscending;
310     }
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         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         this.resultSetLimit = resultSetLimit;
329     }
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         return (resultSetLimit != null);
339     }
340 }