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 /**
151 * Setter for the date picker
152 *
153 * @param datePicker
154 */
155 public void setDatePicker(DatePicker datePicker) {
156 this.datePicker = datePicker;
157 }
158
159 /**
160 * Gets the watermark text for this TextControl.
161 *
162 * <p>
163 * A watermark typically appears as light gray text within the text input element whenever the
164 * element is empty and does not have focus. This provides a hint to the user as to what the input
165 * is used for, or the type of input that is required.
166 * </p>
167 *
168 * @return the watermarkText
169 */
170 public String getWatermarkText() {
171 return this.watermarkText;
172 }
173
174 /**
175 * Sets the watermark text for this TextControl
176 *
177 * @param watermarkText the watermarkText to set
178 */
179 public void setWatermarkText(String watermarkText) {
180 //to avoid users from putting in the same value as the watermark adding some spaces here
181 //see watermark troubleshooting for more info
182 if (StringUtils.isNotEmpty(watermarkText)) {
183 watermarkText = watermarkText + " ";
184 }
185 this.watermarkText = watermarkText;
186 }
187
188 /**
189 * If set to true, this control will have a button which can be clicked to expand the text area through
190 * a popup window so the user has more space to type and see the data they are entering in this text field.
191 *
192 * @return the textExpand
193 */
194 public boolean isTextExpand() {
195 return this.textExpand;
196 }
197
198 /**
199 * Sets whether this control will have a button to expand the text area through a popup window.
200 *
201 * @param textExpand the textExpand to set
202 */
203 public void setTextExpand(boolean textExpand) {
204 this.textExpand = textExpand;
205 }
206
207
208 }