Coverage Report - org.kuali.rice.krad.uif.control.TextControl
 
Classes in this File Line Coverage Branch Coverage Complexity
TextControl
0%
0/34
0%
0/8
1.267
 
 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.control;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.krad.uif.container.View;
 20  
 import org.kuali.rice.krad.uif.core.Component;
 21  
 import org.kuali.rice.krad.uif.field.AttributeField;
 22  
 import org.kuali.rice.krad.uif.widget.DatePicker;
 23  
 
 24  
 import java.util.List;
 25  
 
 26  
 /**
 27  
  * Represents a HTML Text control, generally rendered as a input field of type
 28  
  * 'text'. This can display and receive a single value
 29  
  * 
 30  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 31  
  */
 32  
 public class TextControl extends ControlBase {
 33  
         private static final long serialVersionUID = -8267606288443759880L;
 34  
 
 35  
         private int size;
 36  
     private Integer maxLength;
 37  
     private Integer minLength;
 38  
 
 39  
         private DatePicker datePicker;
 40  0
         private String watermarkText = StringUtils.EMPTY;
 41  
         private boolean textExpand;
 42  
         
 43  
         public TextControl() {
 44  0
                 super();
 45  0
         }
 46  
 
 47  
         /**
 48  
          * @see org.kuali.rice.krad.uif.core.ComponentBase#getNestedComponents()
 49  
          */
 50  
         @Override
 51  
         public List<Component> getNestedComponents() {
 52  0
                 List<Component> components = super.getNestedComponents();
 53  
 
 54  0
                 components.add(datePicker);
 55  
 
 56  0
                 return components;
 57  
         }
 58  
 
 59  
     /**
 60  
      * The following actions are performed:
 61  
      *
 62  
      * <ul>
 63  
      * <li>Defaults maxLength, minLength (if not set) to maxLength of parent field</li>
 64  
      * </ul>
 65  
      *
 66  
      * @see org.kuali.rice.krad.uif.core.ComponentBase#performFinalize(org.kuali.rice.krad.uif.container.View,
 67  
      *      java.lang.Object, org.kuali.rice.krad.uif.core.Component)
 68  
      */
 69  
     @Override
 70  
     public void performFinalize(View view, Object model, Component parent) {
 71  0
         super.performFinalize(view, model, parent);
 72  
 
 73  0
         if (parent instanceof AttributeField) {
 74  0
             AttributeField field = (AttributeField) parent;
 75  0
             if (getMaxLength() == null) {
 76  0
                 setMaxLength(field.getMaxLength());
 77  
             }
 78  
 
 79  0
             if (getMinLength() == null) {
 80  0
                 setMinLength(field.getMinLength());
 81  
             }
 82  
         }
 83  0
     }
 84  
 
 85  
     /**
 86  
          * Horizontal display size of the control (in number of characters)
 87  
          * 
 88  
          * @return int size
 89  
          */
 90  
         public int getSize() {
 91  0
                 return this.size;
 92  
         }
 93  
 
 94  
     /**
 95  
      * Setter for the horizontal display size
 96  
      *
 97  
      * @param size
 98  
      */
 99  
     public void setSize(int size) {
 100  0
         this.size = size;
 101  0
     }
 102  
 
 103  
     /**
 104  
      * Maximum number of characters that can be inputted
 105  
      *
 106  
      * <p>If not set on control, max length of field will be used</p>
 107  
      *
 108  
      * @return int max number of characters
 109  
      */
 110  
     public Integer getMaxLength() {
 111  0
         return maxLength;
 112  
     }
 113  
 
 114  
     /**
 115  
      * Setter for the max number of input characters
 116  
      *
 117  
      * @param maxLength
 118  
      */
 119  
     public void setMaxLength(Integer maxLength) {
 120  0
         this.maxLength = maxLength;
 121  0
     }
 122  
 
 123  
     /**
 124  
      * Minimum number of characters that can be inputted
 125  
      *
 126  
      * <p>If not set on control, min length of field will be used</p>
 127  
      *
 128  
      * @return int max number of characters
 129  
      */
 130  
     public Integer getMinLength() {
 131  0
         return minLength;
 132  
     }
 133  
 
 134  
     /**
 135  
      * Setter for the min number of input characters
 136  
      *
 137  
      * @param maxLength
 138  
      */
 139  
     public void setMinLength(Integer minLength) {
 140  0
         this.minLength = minLength;
 141  0
     }
 142  
 
 143  
     /**
 144  
          * Renders a calendar that can be used to select a date value for the text
 145  
          * control. The <code>Calendar</code> instance contains configuration such
 146  
          * as the date format string
 147  
          * 
 148  
          * @return Calendar
 149  
          */
 150  
         public DatePicker getDatePicker() {
 151  0
                 return this.datePicker;
 152  
         }
 153  
 
 154  
         public void setDatePicker(DatePicker datePicker) {
 155  0
                 this.datePicker = datePicker;
 156  0
         }
 157  
 
 158  
         /**
 159  
          * @return the watermarkText
 160  
          */
 161  
         public String getWatermarkText() {
 162  0
                 return this.watermarkText;
 163  
         }
 164  
 
 165  
         /**
 166  
          * @param watermarkText the watermarkText to set
 167  
          */
 168  
         public void setWatermarkText(String watermarkText) {
 169  
                 //to avoid users from putting in the same value as the watermark adding some spaces here
 170  
                 //see watermark troubleshooting for more info
 171  0
                 if (StringUtils.isNotEmpty(watermarkText)) {
 172  0
                         watermarkText = watermarkText + "   ";
 173  
                 }
 174  0
                 this.watermarkText = watermarkText;
 175  0
         }
 176  
 
 177  
     /**
 178  
      * If set to true, this control will have a button which can be clicked to expand the text area through
 179  
      * a popup window so the user has more space to type and see the data they are entering in this text field
 180  
      *
 181  
      * @return the textExpand
 182  
      */
 183  
     public boolean isTextExpand() {
 184  0
         return this.textExpand;
 185  
     }
 186  
 
 187  
     /**
 188  
      * @param textExpand the textExpand to set
 189  
      */
 190  
     public void setTextExpand(boolean textExpand) {
 191  0
         this.textExpand = textExpand;
 192  0
     }
 193  
         
 194  
         
 195  
 }