View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.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/ecl2.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.datadictionary.parse.BeanTag;
20  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21  import org.kuali.rice.krad.datadictionary.parse.BeanTags;
22  import org.kuali.rice.krad.uif.component.Component;
23  import org.kuali.rice.krad.uif.field.InputField;
24  import org.kuali.rice.krad.uif.util.LifecycleElement;
25  import org.kuali.rice.krad.uif.widget.DatePicker;
26  
27  /**
28   * Represents a HTML Text control, generally rendered as a input field of type
29   * 'text'. This can display and receive a single value
30   *
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  @BeanTags({@BeanTag(name = "textControl", parent = "Uif-TextControl"),
34          @BeanTag(name = "smallTextControl", parent = "Uif-SmallTextControl"),
35          @BeanTag(name = "mediumTextControl", parent = "Uif-MediumTextControl"),
36          @BeanTag(name = "largeTextControl", parent = "Uif-LargeTextControl"),
37          @BeanTag(name = "currencyTextControl", parent = "Uif-CurrencyTextControl"),
38          @BeanTag(name = "dateControl", parent = "Uif-DateControl")})
39  public class TextControlBase extends ControlBase implements TextControl, SizedControl {
40      private static final long serialVersionUID = -8267606288443759880L;
41  
42      private int size;
43      private Integer maxLength;
44      private Integer minLength;
45  
46      private DatePicker datePicker;
47      private String watermarkText = StringUtils.EMPTY;
48      private boolean textExpand;
49  
50      public TextControlBase() {
51          super();
52      }
53  
54      /**
55       * The following actions are performed:
56       *
57       * <ul>
58       * <li>Defaults maxLength, minLength (if not set) to maxLength of parent field</li>
59       * </ul>
60       *
61       * {@inheritDoc}
62       */
63      @Override
64      public void performFinalize(Object model, LifecycleElement parent) {
65          super.performFinalize(model, parent);
66  
67          if (parent instanceof InputField) {
68              InputField field = (InputField) parent;
69              if (getMaxLength() == null) {
70                  setMaxLength(field.getMaxLength());
71              }
72  
73              if (getMinLength() == null) {
74                  setMinLength(field.getMinLength());
75              }
76  
77              if (textExpand || (datePicker != null && datePicker.isRender())) {
78                  field.setRenderInputAddonGroup(true);
79              }
80          }
81      }
82  
83      /**
84       * {@inheritDoc}
85       */
86      @Override
87      @BeanTagAttribute
88      public int getSize() {
89          return this.size;
90      }
91  
92      /**
93       * @see TextControlBase#getSize()
94       */
95      @Override
96      public void setSize(int size) {
97          this.size = size;
98      }
99  
100     /**
101      * {@inheritDoc}
102      */
103     @Override
104     @BeanTagAttribute
105     public Integer getMaxLength() {
106         return maxLength;
107     }
108 
109     /**
110      * @see TextControlBase#getMaxLength()
111      */
112     @Override
113     public void setMaxLength(Integer maxLength) {
114         this.maxLength = maxLength;
115     }
116 
117     /**
118      * {@inheritDoc}
119      */
120     @Override
121     @BeanTagAttribute
122     public Integer getMinLength() {
123         return minLength;
124     }
125 
126     /**
127      * @see TextControlBase#getMinLength()
128      */
129     @Override
130     public void setMinLength(Integer minLength) {
131         this.minLength = minLength;
132     }
133 
134     /**
135      * {@inheritDoc}
136      */
137     @Override
138     @BeanTagAttribute(type = BeanTagAttribute.AttributeType.DIRECTORBYTYPE)
139     public DatePicker getDatePicker() {
140         return this.datePicker;
141     }
142 
143     /**
144      * @see TextControlBase#getDatePicker()
145      */
146     @Override
147     public void setDatePicker(DatePicker datePicker) {
148         this.datePicker = datePicker;
149     }
150 
151     /**
152      * {@inheritDoc}
153      */
154     @Override
155     @BeanTagAttribute
156     public boolean isTextExpand() {
157         return this.textExpand;
158     }
159 
160     /**
161      * @see TextControlBase#isTextExpand()
162      */
163     @Override
164     public void setTextExpand(boolean textExpand) {
165         this.textExpand = textExpand;
166     }
167 
168     /**
169      * {@inheritDoc}
170      */
171     @Override
172     @BeanTagAttribute(name = "watermarkText")
173     public String getWatermarkText() {
174         return this.watermarkText;
175     }
176 
177     /**
178      * @see TextControlBase#getWatermarkText()
179      */
180     @Override
181     public void setWatermarkText(String watermarkText) {
182         //to avoid users from putting in the same value as the watermark adding some spaces here
183         //see watermark troubleshooting for more info
184         if (StringUtils.isNotEmpty(watermarkText)) {
185             watermarkText = watermarkText + "   ";
186         }
187 
188         this.watermarkText = watermarkText;
189     }
190 }