View Javadoc

1   /**
2    * Copyright 2005-2012 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.uif.field.InputField;
20  import org.kuali.rice.krad.uif.view.View;
21  import org.kuali.rice.krad.uif.component.Component;
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 implements SizedControl {
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  	private String watermarkText = StringUtils.EMPTY;
41  	private boolean textExpand;
42  	
43  	public TextControl() {
44  		super();
45  	}
46  
47  	/**
48  	 * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle()
49  	 */
50  	@Override
51  	public List<Component> getComponentsForLifecycle() {
52  		List<Component> components = super.getComponentsForLifecycle();
53  
54  		components.add(datePicker);
55  
56  		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.component.ComponentBase#performFinalize(org.kuali.rice.krad.uif.view.View,
67       *      java.lang.Object, org.kuali.rice.krad.uif.component.Component)
68       */
69      @Override
70      public void performFinalize(View view, Object model, Component parent) {
71          super.performFinalize(view, model, parent);
72  
73          if (parent instanceof InputField) {
74              InputField field = (InputField) parent;
75              if (getMaxLength() == null) {
76                  setMaxLength(field.getMaxLength());
77              }
78  
79              if (getMinLength() == null) {
80                  setMinLength(field.getMinLength());
81              }
82          }
83      }
84  
85      /**
86  	 * @see org.kuali.rice.krad.uif.control.SizedControl#getSize()
87  	 */
88  	public int getSize() {
89  		return this.size;
90  	}
91  
92      /**
93       * @see org.kuali.rice.krad.uif.control.SizedControl#setSize(int)
94       */
95      public void setSize(int size) {
96          this.size = size;
97      }
98  
99      /**
100      * Maximum number of characters that can be inputted
101      *
102      * <p>If not set on control, max length of field will be used</p>
103      *
104      * @return int max number of characters
105      */
106     public Integer getMaxLength() {
107         return maxLength;
108     }
109 
110     /**
111      * Setter for the max number of input characters
112      *
113      * @param maxLength
114      */
115     public void setMaxLength(Integer maxLength) {
116         this.maxLength = maxLength;
117     }
118 
119     /**
120      * Minimum number of characters that can be inputted
121      *
122      * <p>If not set on control, min length of field will be used</p>
123      *
124      * @return int max number of characters
125      */
126     public Integer getMinLength() {
127         return minLength;
128     }
129 
130     /**
131      * Setter for the min number of input characters
132      *
133      * @param minLength
134      */
135     public void setMinLength(Integer minLength) {
136         this.minLength = minLength;
137     }
138 
139     /**
140 	 * Renders a calendar that can be used to select a date value for the text
141 	 * control. The <code>Calendar</code> instance contains configuration such
142 	 * as the date format string
143 	 * 
144 	 * @return Calendar
145 	 */
146 	public DatePicker getDatePicker() {
147 		return this.datePicker;
148 	}
149 
150 	public void setDatePicker(DatePicker datePicker) {
151 		this.datePicker = datePicker;
152 	}
153 
154 	/**
155      * Gets the watermark text for this TextControl.
156      * <p>
157      * A watermark typically appears as light gray text within the text input element whenever the
158      * element is empty and does not have focus. This provides a hint to the user as to what the input
159      * is used for, or the type of input that is required.
160      * </p>
161 	 * @return the watermarkText
162 	 */
163 	public String getWatermarkText() {
164 		return this.watermarkText;
165 	}
166 
167 	/**
168      * Sets the watermark text for this TextControl
169 	 * @param watermarkText the watermarkText to set
170 	 */
171 	public void setWatermarkText(String watermarkText) {
172 		//to avoid users from putting in the same value as the watermark adding some spaces here
173 		//see watermark troubleshooting for more info
174 		if (StringUtils.isNotEmpty(watermarkText)) {
175 			watermarkText = watermarkText + "   ";
176 		}
177 		this.watermarkText = watermarkText;
178 	}
179 
180     /**
181      * If set to true, this control will have a button which can be clicked to expand the text area through
182      * a popup window so the user has more space to type and see the data they are entering in this text field.
183      *
184      * @return the textExpand
185      */
186     public boolean isTextExpand() {
187         return this.textExpand;
188     }
189 
190     /**
191      * Sets whether this control will have a button to expand the text area through a popup window.
192      * @param textExpand the textExpand to set
193      */
194     public void setTextExpand(boolean textExpand) {
195         this.textExpand = textExpand;
196     }
197 	
198 	
199 }