Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TextControl |
|
| 1.2666666666666666;1.267 |
1 | /** | |
2 | * Copyright 2005-2011 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 | 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.component.ComponentBase#getComponentsForLifecycle() | |
49 | */ | |
50 | @Override | |
51 | public List<Component> getComponentsForLifecycle() { | |
52 | 0 | List<Component> components = super.getComponentsForLifecycle(); |
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.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 | 0 | super.performFinalize(view, model, parent); |
72 | ||
73 | 0 | if (parent instanceof InputField) { |
74 | 0 | InputField field = (InputField) 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 | * @see org.kuali.rice.krad.uif.control.SizedControl#getSize() | |
87 | */ | |
88 | public int getSize() { | |
89 | 0 | 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 | 0 | this.size = size; |
97 | 0 | } |
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 | 0 | 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 | 0 | this.maxLength = maxLength; |
117 | 0 | } |
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 | 0 | return minLength; |
128 | } | |
129 | ||
130 | /** | |
131 | * Setter for the min number of input characters | |
132 | * | |
133 | * @param maxLength | |
134 | */ | |
135 | public void setMinLength(Integer minLength) { | |
136 | 0 | this.minLength = minLength; |
137 | 0 | } |
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 | 0 | return this.datePicker; |
148 | } | |
149 | ||
150 | public void setDatePicker(DatePicker datePicker) { | |
151 | 0 | this.datePicker = datePicker; |
152 | 0 | } |
153 | ||
154 | /** | |
155 | * @return the watermarkText | |
156 | */ | |
157 | public String getWatermarkText() { | |
158 | 0 | return this.watermarkText; |
159 | } | |
160 | ||
161 | /** | |
162 | * @param watermarkText the watermarkText to set | |
163 | */ | |
164 | public void setWatermarkText(String watermarkText) { | |
165 | //to avoid users from putting in the same value as the watermark adding some spaces here | |
166 | //see watermark troubleshooting for more info | |
167 | 0 | if (StringUtils.isNotEmpty(watermarkText)) { |
168 | 0 | watermarkText = watermarkText + " "; |
169 | } | |
170 | 0 | this.watermarkText = watermarkText; |
171 | 0 | } |
172 | ||
173 | /** | |
174 | * If set to true, this control will have a button which can be clicked to expand the text area through | |
175 | * a popup window so the user has more space to type and see the data they are entering in this text field | |
176 | * | |
177 | * @return the textExpand | |
178 | */ | |
179 | public boolean isTextExpand() { | |
180 | 0 | return this.textExpand; |
181 | } | |
182 | ||
183 | /** | |
184 | * @param textExpand the textExpand to set | |
185 | */ | |
186 | public void setTextExpand(boolean textExpand) { | |
187 | 0 | this.textExpand = textExpand; |
188 | 0 | } |
189 | ||
190 | ||
191 | } |