Coverage Report - org.kuali.rice.kns.uif.container.LookupView
 
Classes in this File Line Coverage Branch Coverage Complexity
LookupView
0%
0/95
0%
0/60
1.875
 
 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.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  
  * TODO delyea: Fill in javadocs here
 35  
  * 
 36  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  
          * <p>
 75  
          * The following initialization is performed:
 76  
          * <ul>
 77  
          * <li>Set the abstractTypeClasses map for the lookup object path</li>
 78  
          * </ul>
 79  
          * </p>
 80  
          * 
 81  
          * @see org.kuali.rice.kns.uif.container.ContainerBase#performInitialization(org.kuali.rice.kns.uif.container.View)
 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  
      * @see org.kuali.rice.kns.uif.container.ContainerBase#performApplyModel(org.kuali.rice.kns.uif.container.View, java.lang.Object)
 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  
      * @see org.kuali.rice.kns.uif.container.View#performFinalize(org.kuali.rice.kns.uif.container.View, java.lang.Object)
 154  
      */
 155  
         @SuppressWarnings("unchecked")
 156  
         @Override
 157  
     public void performFinalize(View view, Object model, Component parent) {
 158  0
             super.performFinalize(view, model, parent);
 159  
 //            if (isRenderActionsFields()) {
 160  
 //                ((List<Field>)getResultsGroup().getItems()).add(0, getResultsActionsField());
 161  
 //            }
 162  
 //            if (isRenderReturnFields()) {
 163  
 //                ((List<Field>)getResultsGroup().getItems()).add(0, getResultsReturnField());
 164  
 //            }
 165  0
     }
 166  
 
 167  
         public boolean isRenderActionsFields(){
 168  
                 /* if - 
 169  
                  *   KualiForm.actionUrlsExist = true
 170  
                  *   KualiForm.suppressActions != true
 171  
                  *   !KualiForm.multipleValues
 172  
                  *   KualiForm.showMaintenanceLinks = true
 173  
                  *   
 174  
                  *  if - 
 175  
                  *   row.actionsUrls != ''
 176  
                  */
 177  0
                 LookupViewHelperService lookupHelperService = (LookupViewHelperService) getViewHelperService();
 178  0
                 return ( (lookupHelperService.isAtLeastOneRowHasActions()) &&
 179  
                                  (!isSuppressActions()) &&
 180  
                                  (isShowMaintenanceLinks())
 181  
                                 );
 182  
     }
 183  
         
 184  
         public boolean isRenderReturnFields(){
 185  
                 /* if - 
 186  
                  *   KualiForm.formKey != ''
 187  
                  *   KualiForm.hideReturnLink = false
 188  
                  *   !KualiForm.multipleValues   
 189  
                  *   KualiForm.backLocation is not empty
 190  
                  *   
 191  
                  *  if -
 192  
                  *   row.rowReturnable
 193  
                  */
 194  0
                 LookupViewHelperService lookupHelperService = (LookupViewHelperService) getViewHelperService();
 195  0
                 return ( (StringUtils.isNotBlank(lookupHelperService.getReturnFormKey())) &&
 196  
                                  (StringUtils.isNotBlank(lookupHelperService.getReturnLocation())) &&
 197  
                                  (!isHideReturnLinks())
 198  
                                 );
 199  
                 /* if - 
 200  
                  *   KualiForm.formKey != ''   ----   @see LookupViewHelperService#getDocFormKey()
 201  
                  *   KualiForm.hideReturnLink = false   ----   
 202  
                  *   !KualiForm.multipleValues   ----   
 203  
                  *   KualiForm.backLocation is not empty   ----   
 204  
                  *   
 205  
                  *  if -
 206  
                  *   row.rowReturnable   ----   @see LookupViewHelperService#getActionUrlsFromField
 207  
                  */
 208  
         }
 209  
 
 210  
         /**
 211  
          * Class name for the object the lookup applies to
 212  
          * 
 213  
          * <p>
 214  
          * The object class name is used to pick up a dictionary entry which will
 215  
          * feed the attribute field definitions and other configuration. In addition
 216  
          * it is to configure the <code>Lookupable</code> which will carry out the
 217  
          * lookup action
 218  
          * </p>
 219  
          * 
 220  
          * @return Class<?> lookup data object class
 221  
          */
 222  
         public Class<?> getDataObjectClassName() {
 223  0
                 return this.dataObjectClassName;
 224  
         }
 225  
 
 226  
         /**
 227  
          * Setter for the object class name
 228  
          * 
 229  
          * @param dataObjectClassName
 230  
          */
 231  
         public void setDataObjectClassName(Class<?> dataObjectClassName) {
 232  0
                 this.dataObjectClassName = dataObjectClassName;
 233  0
         }
 234  
 
 235  
         /**
 236  
          * @return the hideReturnLinks
 237  
          */
 238  
         public boolean isHideReturnLinks() {
 239  0
                 return this.hideReturnLinks;
 240  
         }
 241  
 
 242  
         /**
 243  
          * @param hideReturnLinks the hideReturnLinks to set
 244  
          */
 245  
         public void setHideReturnLinks(boolean hideReturnLinks) {
 246  0
                 this.hideReturnLinks = hideReturnLinks;
 247  0
         }
 248  
 
 249  
         /**
 250  
          * @return the suppressActions
 251  
          */
 252  
         public boolean isSuppressActions() {
 253  0
                 return this.suppressActions;
 254  
         }
 255  
 
 256  
         /**
 257  
          * @param suppressActions the suppressActions to set
 258  
          */
 259  
         public void setSuppressActions(boolean suppressActions) {
 260  0
                 this.suppressActions = suppressActions;
 261  0
         }
 262  
 
 263  
         /**
 264  
          * @return the showMaintenanceLinks
 265  
          */
 266  
         public boolean isShowMaintenanceLinks() {
 267  0
                 return this.showMaintenanceLinks;
 268  
         }
 269  
 
 270  
         /**
 271  
          * @param showMaintenanceLinks the showMaintenanceLinks to set
 272  
          */
 273  
         public void setShowMaintenanceLinks(boolean showMaintenanceLinks) {
 274  0
                 this.showMaintenanceLinks = showMaintenanceLinks;
 275  0
         }
 276  
 
 277  
         /**
 278  
      * @return the resultsActionsField
 279  
      */
 280  
     public Field getResultsActionsField() {
 281  0
             return this.resultsActionsField;
 282  
     }
 283  
 
 284  
         /**
 285  
      * @param resultsActionsField the resultsActionsField to set
 286  
      */
 287  
     public void setResultsActionsField(Field resultsActionsField) {
 288  0
             this.resultsActionsField = resultsActionsField;
 289  0
     }
 290  
 
 291  
         /**
 292  
      * @return the resultsReturnField
 293  
      */
 294  
     public Field getResultsReturnField() {
 295  0
             return this.resultsReturnField;
 296  
     }
 297  
 
 298  
         /**
 299  
      * @param resultsReturnField the resultsReturnField to set
 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  
 }