Coverage Report - org.kuali.rice.kns.uif.container.LookupView
 
Classes in this File Line Coverage Branch Coverage Complexity
LookupView
0%
0/76
0%
0/60
2.077
 
 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.UifPropertyPaths;
 24  
 import org.kuali.rice.kns.uif.UifConstants.ViewType;
 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.field.AttributeField;
 28  
 import org.kuali.rice.kns.uif.field.Field;
 29  
 import org.kuali.rice.kns.uif.service.LookupViewHelperService;
 30  
 import org.kuali.rice.kns.uif.util.LookupInquiryUtils;
 31  
 
 32  
 /**
 33  
  * TODO delyea: Fill in javadocs here
 34  
  * 
 35  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 36  
  */
 37  
 public class LookupView extends FormView {
 38  
         private static final long serialVersionUID = 716926008488403616L;
 39  
 
 40  
         private Class<?> dataObjectClassName;
 41  
 
 42  
         private Group criteriaGroup;
 43  
         private CollectionGroup resultsGroup;
 44  
         private Field resultsActionsField;
 45  
         private Field resultsReturnField;
 46  
 
 47  
         private List<Component> criteriaFields;
 48  
         private List<Component> resultFields;
 49  
         private List<String> defaultSortAttributeNames;
 50  0
         protected boolean sortAscending = true;
 51  
 
 52  
         public LookupView() {
 53  0
                 super();
 54  0
                 setViewTypeName(ViewType.LOOKUP);
 55  0
         }
 56  
 
 57  
         /**
 58  
          * <p>
 59  
          * The following initialization is performed:
 60  
          * <ul>
 61  
          * <li>Set the abstractTypeClasses map for the lookup object path</li>
 62  
          * </ul>
 63  
          * </p>
 64  
          * 
 65  
          * @see org.kuali.rice.kns.uif.container.ContainerBase#performInitialization(org.kuali.rice.kns.uif.container.View)
 66  
          */
 67  
         @Override
 68  
         public void performInitialization(View view) {
 69  0
                 initializeGroups();
 70  0
                 if (getItems().isEmpty()) {
 71  0
                         setItems(Arrays.asList(getCriteriaGroup(), getResultsGroup()));
 72  
                 }
 73  0
                 super.performInitialization(view);
 74  
 
 75  0
         getAbstractTypeClasses().put(UifPropertyPaths.CRITERIA_FIELDS, getDataObjectClassName());
 76  0
         if (StringUtils.isNotBlank(getDefaultBindingObjectPath())) {
 77  0
             getAbstractTypeClasses().put(getDefaultBindingObjectPath(), getDataObjectClassName());
 78  
         }
 79  0
         }
 80  
 
 81  
         protected void initializeGroups() {
 82  0
                 if ((getCriteriaGroup() != null) && (getCriteriaGroup().getItems().isEmpty())) {
 83  0
                         getCriteriaGroup().setItems(getCriteriaFields());
 84  
                 }
 85  0
                 if (getResultsGroup() != null) {
 86  0
                         if ( (getResultsGroup().getItems().isEmpty()) && (getResultFields() != null) ) {
 87  0
                                 getResultsGroup().setItems(getResultFields());
 88  
                         }
 89  0
                         if (getResultsGroup().getCollectionObjectClass() == null) {
 90  0
                                 getResultsGroup().setCollectionObjectClass(getDataObjectClassName());
 91  
                         }
 92  
                 }
 93  0
         }
 94  
 
 95  
         /**
 96  
      * @see org.kuali.rice.kns.uif.container.ContainerBase#performApplyModel(org.kuali.rice.kns.uif.container.View, java.lang.Object)
 97  
      */
 98  
     @Override
 99  
     public void performApplyModel(View view, Object model) {
 100  0
             if (isRenderActionsFields()) {
 101  0
                 ((List<Field>)getResultsGroup().getItems()).add(0, getResultsActionsField());
 102  
             }
 103  0
             if (isRenderReturnFields()) {
 104  0
                 ((List<Field>)getResultsGroup().getItems()).add(0, getResultsReturnField());
 105  
             }
 106  0
             applyConditionalLogicForFieldDisplay();
 107  0
             super.performApplyModel(view, model);
 108  0
     }
 109  
 
 110  
         public void applyConditionalLogicForFieldDisplay() {
 111  0
             LookupViewHelperService lookupViewHelperService = (LookupViewHelperService) getViewHelperService();
 112  0
                 Set<String> readOnlyFields = lookupViewHelperService.getConditionallyReadOnlyPropertyNames();
 113  0
                 Set<String> requiredFields = lookupViewHelperService.getConditionallyRequiredPropertyNames();
 114  0
                 Set<String> hiddenFields = lookupViewHelperService.getConditionallyHiddenPropertyNames();
 115  0
                 if ( (readOnlyFields != null && !readOnlyFields.isEmpty()) ||
 116  
                          (requiredFields != null && !requiredFields.isEmpty()) ||
 117  
                          (hiddenFields != null && !hiddenFields.isEmpty()) 
 118  
                         ) {
 119  0
                         for (Field field : getResultsGroup().getItems()) {
 120  0
                                 if (AttributeField.class.isAssignableFrom(field.getClass())) {
 121  0
                                         AttributeField attributeField = (AttributeField) field;
 122  0
                                         if (readOnlyFields != null && readOnlyFields.contains(attributeField.getBindingInfo().getBindingName())) {
 123  0
                                                 attributeField.setReadOnly(true);
 124  
                                         }
 125  0
                                         if (requiredFields != null && requiredFields.contains(attributeField.getBindingInfo().getBindingName())) {
 126  0
                                                 attributeField.setRequired(Boolean.TRUE);
 127  
                                         }
 128  0
                                         if (hiddenFields != null && hiddenFields.contains(attributeField.getBindingInfo().getBindingName())) {
 129  0
                                                 attributeField.setControl(LookupInquiryUtils.generateCustomLookupControlFromExisting(HiddenControl.class, null));
 130  
                                         }
 131  0
                                 }
 132  
                 }
 133  
                 }
 134  0
         }
 135  
 
 136  
         /**
 137  
      * @see org.kuali.rice.kns.uif.container.View#performFinalize(org.kuali.rice.kns.uif.container.View, java.lang.Object)
 138  
      */
 139  
         @SuppressWarnings("unchecked")
 140  
         @Override
 141  
     public void performFinalize(View view, Object model, Component parent) {
 142  0
             super.performFinalize(view, model, parent);
 143  
 //            if (isRenderActionsFields()) {
 144  
 //                ((List<Field>)getResultsGroup().getItems()).add(0, getResultsActionsField());
 145  
 //            }
 146  
 //            if (isRenderReturnFields()) {
 147  
 //                ((List<Field>)getResultsGroup().getItems()).add(0, getResultsReturnField());
 148  
 //            }
 149  0
     }
 150  
 
 151  
         public boolean isRenderActionsFields(){
 152  
                 /* if - 
 153  
                  *   KualiForm.actionUrlsExist = true
 154  
                  *   KualiForm.suppressActions != true
 155  
                  *   !KualiForm.multipleValues
 156  
                  *   KualiForm.showMaintenanceLinks = true
 157  
                  *   
 158  
                  *  if - 
 159  
                  *   row.actionsUrls != ''
 160  
                  */
 161  0
                 LookupViewHelperService lookupHelperService = (LookupViewHelperService) getViewHelperService();
 162  0
                 return ( (lookupHelperService.isAtLeastOneRowHasActions()) &&
 163  
                                  (!lookupHelperService.isSuppressActions()) &&
 164  
                                  (lookupHelperService.isShowMaintenanceLinks())
 165  
                                 );
 166  
     }
 167  
         
 168  
         public boolean isRenderReturnFields(){
 169  
                 /* if - 
 170  
                  *   KualiForm.formKey != ''
 171  
                  *   KualiForm.hideReturnLink = false
 172  
                  *   !KualiForm.multipleValues   
 173  
                  *   KualiForm.backLocation is not empty
 174  
                  *   
 175  
                  *  if -
 176  
                  *   row.rowReturnable
 177  
                  */
 178  0
                 LookupViewHelperService lookupHelperService = (LookupViewHelperService) getViewHelperService();
 179  0
                 return ( (StringUtils.isNotBlank(lookupHelperService.getReturnFormKey())) &&
 180  
                                  (StringUtils.isNotBlank(lookupHelperService.getReturnLocation())) &&
 181  
                                  (!lookupHelperService.isHideReturnLink())
 182  
                                 );
 183  
                 /* if - 
 184  
                  *   KualiForm.formKey != ''   ----   @see LookupViewHelperService#getDocFormKey()
 185  
                  *   KualiForm.hideReturnLink = false   ----   
 186  
                  *   !KualiForm.multipleValues   ----   
 187  
                  *   KualiForm.backLocation is not empty   ----   
 188  
                  *   
 189  
                  *  if -
 190  
                  *   row.rowReturnable   ----   @see LookupViewHelperService#getActionUrlsFromField
 191  
                  */
 192  
         }
 193  
         /**
 194  
          * Class name for the object the lookup applies to
 195  
          * 
 196  
          * <p>
 197  
          * The object class name is used to pick up a dictionary entry which will
 198  
          * feed the attribute field definitions and other configuration. In addition
 199  
          * it is to configure the <code>Lookupable</code> which will carry out the
 200  
          * lookup action
 201  
          * </p>
 202  
          * 
 203  
          * @return Class<?> lookup data object class
 204  
          */
 205  
         public Class<?> getDataObjectClassName() {
 206  0
                 return this.dataObjectClassName;
 207  
         }
 208  
 
 209  
         /**
 210  
          * Setter for the object class name
 211  
          * 
 212  
          * @param dataObjectClassName
 213  
          */
 214  
         public void setDataObjectClassName(Class<?> dataObjectClassName) {
 215  0
                 this.dataObjectClassName = dataObjectClassName;
 216  0
         }
 217  
 
 218  
         /**
 219  
      * @return the resultsActionsField
 220  
      */
 221  
     public Field getResultsActionsField() {
 222  0
             return this.resultsActionsField;
 223  
     }
 224  
 
 225  
         /**
 226  
      * @param resultsActionsField the resultsActionsField to set
 227  
      */
 228  
     public void setResultsActionsField(Field resultsActionsField) {
 229  0
             this.resultsActionsField = resultsActionsField;
 230  0
     }
 231  
 
 232  
         /**
 233  
      * @return the resultsReturnField
 234  
      */
 235  
     public Field getResultsReturnField() {
 236  0
             return this.resultsReturnField;
 237  
     }
 238  
 
 239  
         /**
 240  
      * @param resultsReturnField the resultsReturnField to set
 241  
      */
 242  
     public void setResultsReturnField(Field resultsReturnField) {
 243  0
             this.resultsReturnField = resultsReturnField;
 244  0
     }
 245  
 
 246  
         public Group getCriteriaGroup() {
 247  0
                 return this.criteriaGroup;
 248  
         }
 249  
 
 250  
         public void setCriteriaGroup(Group criteriaGroup) {
 251  0
                 this.criteriaGroup = criteriaGroup;
 252  0
         }
 253  
 
 254  
         public CollectionGroup getResultsGroup() {
 255  0
                 return this.resultsGroup;
 256  
         }
 257  
 
 258  
         public void setResultsGroup(CollectionGroup resultsGroup) {
 259  0
                 this.resultsGroup = resultsGroup;
 260  0
         }
 261  
 
 262  
         public List<Component> getCriteriaFields() {
 263  0
                 return this.criteriaFields;
 264  
         }
 265  
 
 266  
         public void setCriteriaFields(List<Component> criteriaFields) {
 267  0
                 this.criteriaFields = criteriaFields;
 268  0
         }
 269  
 
 270  
         public List<Component> getResultFields() {
 271  0
                 return this.resultFields;
 272  
         }
 273  
 
 274  
         public void setResultFields(List<Component> resultFields) {
 275  0
                 this.resultFields = resultFields;
 276  0
         }
 277  
 
 278  
         public List<String> getDefaultSortAttributeNames() {
 279  0
             return this.defaultSortAttributeNames;
 280  
     }
 281  
 
 282  
         public void setDefaultSortAttributeNames(List<String> defaultSortAttributeNames) {
 283  0
             this.defaultSortAttributeNames = defaultSortAttributeNames;
 284  0
     }
 285  
 
 286  
         public boolean isSortAscending() {
 287  0
             return this.sortAscending;
 288  
     }
 289  
 
 290  
         public void setSortAscending(boolean sortAscending) {
 291  0
             this.sortAscending = sortAscending;
 292  0
     }
 293  
 
 294  
 }