Coverage Report - org.kuali.rice.krad.uif.field.LookupAttributeField
 
Classes in this File Line Coverage Branch Coverage Complexity
LookupAttributeField
0%
0/36
0%
0/20
3.2
 
 1  
 /*
 2  
  * Copyright 2011 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.field;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.util.ConcreteKeyValue;
 20  
 import org.kuali.rice.core.api.util.KeyValue;
 21  
 import org.kuali.rice.krad.datadictionary.AttributeDefinition;
 22  
 import org.kuali.rice.krad.uif.control.CheckboxControl;
 23  
 import org.kuali.rice.krad.uif.control.Control;
 24  
 import org.kuali.rice.krad.uif.control.RadioGroupControl;
 25  
 import org.kuali.rice.krad.uif.control.TextAreaControl;
 26  
 import org.kuali.rice.krad.uif.util.ComponentFactory;
 27  
 import org.kuali.rice.krad.uif.util.ComponentUtils;
 28  
 import org.kuali.rice.krad.util.KRADConstants;
 29  
 import org.kuali.rice.krad.util.KRADPropertyConstants;
 30  
 
 31  
 import java.util.ArrayList;
 32  
 import java.util.List;
 33  
 
 34  
 /**
 35  
  * Custom <code>AttributeField</code> for search fields within a lookup view
 36  
  *
 37  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 38  
  */
 39  
 public class LookupAttributeField extends AttributeField {
 40  
     private static final long serialVersionUID = -8294275596836322699L;
 41  
 
 42  0
     protected boolean treatWildcardsAndOperatorsAsLiteral = false;
 43  
 
 44  
     public LookupAttributeField() {
 45  0
         super();
 46  0
     }
 47  
 
 48  
     /**
 49  
      * @return the treatWildcardsAndOperatorsAsLiteral
 50  
      */
 51  
     public boolean isTreatWildcardsAndOperatorsAsLiteral() {
 52  0
         return this.treatWildcardsAndOperatorsAsLiteral;
 53  
     }
 54  
 
 55  
     /**
 56  
      * @param treatWildcardsAndOperatorsAsLiteral the treatWildcardsAndOperatorsAsLiteral to set
 57  
      */
 58  
     public void setTreatWildcardsAndOperatorsAsLiteral(boolean treatWildcardsAndOperatorsAsLiteral) {
 59  0
         this.treatWildcardsAndOperatorsAsLiteral = treatWildcardsAndOperatorsAsLiteral;
 60  0
     }
 61  
 
 62  
     /**
 63  
      * Override of AttributeField copy to setup properties necessary to make the field usable for inputting
 64  
      * search criteria
 65  
      *
 66  
      * @param attributeDefinition - AttributeDefinition instance the property values should be copied from
 67  
      * @see org.kuali.rice.krad.uif.field.AttributeField#copyFromAttributeDefinition(org.kuali.rice.krad.datadictionary.AttributeDefinition)
 68  
      */
 69  
     @Override
 70  
     public void copyFromAttributeDefinition(AttributeDefinition attributeDefinition) {
 71  
         // label
 72  0
         if (StringUtils.isEmpty(getLabel())) {
 73  0
             setLabel(attributeDefinition.getLabel());
 74  
         }
 75  
 
 76  
         // short label
 77  0
         if (StringUtils.isEmpty(getShortLabel())) {
 78  0
             setShortLabel(attributeDefinition.getShortLabel());
 79  
         }
 80  
 
 81  
         // security
 82  0
         if (getAttributeSecurity() == null) {
 83  0
             setAttributeSecurity(attributeDefinition.getAttributeSecurity());
 84  
         }
 85  
 
 86  
         // options
 87  0
         if (getOptionsFinder() == null) {
 88  0
             setOptionsFinder(attributeDefinition.getOptionsFinder());
 89  
         }
 90  
 
 91  
         // TODO: what about formatter?
 92  
 
 93  
         // use control from dictionary if not specified and convert for searching
 94  0
         if (getControl() == null) {
 95  0
             setControl(convertControlToLookupControl(attributeDefinition));
 96  
         }
 97  
 
 98  
         // overwrite maxLength to allow for wildcards and ranges
 99  0
         setMaxLength(100);
 100  
 
 101  
         // set default value for active field to true
 102  0
         if (StringUtils.isEmpty(getDefaultValue())) {
 103  0
             if ((StringUtils.equals(getPropertyName(), KRADPropertyConstants.ACTIVE))) {
 104  0
                 setDefaultValue(KRADConstants.YES_INDICATOR_VALUE);
 105  
             }
 106  
         }
 107  
 
 108  
         /*
 109  
            * TODO delyea: FieldUtils.createAndPopulateFieldsForLookup used to allow for a set of property names to be passed in via the URL
 110  
            * parameters of the lookup url to set fields as 'read only'
 111  
            */
 112  
 
 113  0
     }
 114  
 
 115  
     /**
 116  
      * If control definition is defined on the given attribute definition, converts to an appropriate control for
 117  
      * searching (if necessary) and returns a copy for setting on the field
 118  
      *
 119  
      * @param attributeDefinition - attribute definition instance to retrieve control from
 120  
      * @return Control instance or null if not found
 121  
      */
 122  
     protected static Control convertControlToLookupControl(AttributeDefinition attributeDefinition) {
 123  0
         if (attributeDefinition.getControlField() == null) {
 124  0
             return null;
 125  
         }
 126  
 
 127  0
         Control newControl = null;
 128  
 
 129  
         // convert checkbox to radio with yes/no/both options
 130  0
         if (CheckboxControl.class.isAssignableFrom(attributeDefinition.getControlField().getClass())) {
 131  0
             newControl = ComponentFactory.getRadioGroupControlHorizontal();
 132  0
             List<KeyValue> options = new ArrayList<KeyValue>();
 133  0
             options.add(new ConcreteKeyValue("Y", "Yes"));
 134  0
             options.add(new ConcreteKeyValue("N", "No"));
 135  0
             options.add(new ConcreteKeyValue("", "Both"));
 136  
 
 137  0
             ((RadioGroupControl) newControl).setOptions(options);
 138  0
         }
 139  
         // text areas get converted to simple text inputs
 140  0
         else if (TextAreaControl.class.isAssignableFrom(attributeDefinition.getControlField().getClass())) {
 141  0
             newControl = ComponentFactory.getTextControl();
 142  
         } else {
 143  0
             newControl = ComponentUtils.copy(attributeDefinition.getControlField(), "");
 144  
         }
 145  
 
 146  0
         return newControl;
 147  
     }
 148  
 }