Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ControlDefinitionBase |
|
| 1.711111111111111;1.711 |
1 | /* | |
2 | * Copyright 2005-2007 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 | ||
17 | package org.kuali.rice.krad.datadictionary.control; | |
18 | ||
19 | import org.apache.commons.lang.ClassUtils; | |
20 | import org.apache.commons.lang.builder.EqualsBuilder; | |
21 | import org.kuali.rice.core.util.ClassLoaderUtils; | |
22 | import org.kuali.rice.krad.bo.BusinessObject; | |
23 | import org.kuali.rice.krad.datadictionary.DataDictionaryDefinitionBase; | |
24 | import org.kuali.rice.krad.datadictionary.exception.ClassValidationException; | |
25 | import org.kuali.rice.krad.datadictionary.exception.CompletionException; | |
26 | import org.kuali.rice.krad.lookup.keyvalues.KeyValuesFinder; | |
27 | ||
28 | /** | |
29 | * A single HTML control definition in the DataDictionary, which contains information relating to the HTML control used to realize a | |
30 | * specific attribute. All types of controls are represented by an instance of this class; you have to call one of the is* methods | |
31 | * to figure out which of the other accessors should return useful values. | |
32 | * | |
33 | * | |
34 | */ | |
35 | public abstract class ControlDefinitionBase extends DataDictionaryDefinitionBase implements ControlDefinition { | |
36 | private static final long serialVersionUID = 4372435175782501152L; | |
37 | ||
38 | protected boolean datePicker; | |
39 | protected boolean expandedTextArea; | |
40 | protected String script; | |
41 | protected String valuesFinderClass; | |
42 | protected String businessObjectClass; | |
43 | protected String keyAttribute; | |
44 | protected String labelAttribute; | |
45 | protected Boolean includeBlankRow; | |
46 | protected Boolean includeKeyInLabel; | |
47 | protected Integer size; | |
48 | protected Integer rows; | |
49 | protected Integer cols; | |
50 | protected boolean ranged; | |
51 | ||
52 | ||
53 | 0 | public ControlDefinitionBase() { |
54 | 0 | ranged = true; |
55 | 0 | } |
56 | ||
57 | public boolean isDatePicker() { | |
58 | 0 | return datePicker; |
59 | } | |
60 | ||
61 | /** Whether this control should have a date picker button next to the field. | |
62 | * Valid for text fields. | |
63 | * | |
64 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#setDatePicker(boolean) | |
65 | */ | |
66 | public void setDatePicker(boolean datePicker) { | |
67 | 0 | this.datePicker=datePicker; |
68 | 0 | } |
69 | ||
70 | public boolean isExpandedTextArea() { | |
71 | 0 | return expandedTextArea; |
72 | } | |
73 | ||
74 | /** Whether this control should have a expanded text area button next to the field. | |
75 | * Valid for textarea fields. | |
76 | * | |
77 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#setExpandedTextArea(boolean) | |
78 | */ | |
79 | public void setExpandedTextArea(boolean eTextArea) { | |
80 | 0 | this.expandedTextArea=eTextArea; |
81 | 0 | } |
82 | ||
83 | /** | |
84 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isCheckbox() | |
85 | */ | |
86 | public boolean isCheckbox() { | |
87 | 0 | return false; |
88 | } | |
89 | ||
90 | /** | |
91 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isHidden() | |
92 | */ | |
93 | public boolean isHidden() { | |
94 | 0 | return false; |
95 | } | |
96 | ||
97 | /** | |
98 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isRadio() | |
99 | */ | |
100 | public boolean isRadio() { | |
101 | 0 | return false; |
102 | } | |
103 | ||
104 | /** | |
105 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isSelect() | |
106 | */ | |
107 | public boolean isSelect() { | |
108 | 0 | return false; |
109 | } | |
110 | ||
111 | /** | |
112 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isSelect() | |
113 | */ | |
114 | public boolean isMultiselect() { | |
115 | 0 | return false; |
116 | } | |
117 | ||
118 | /** | |
119 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isText() | |
120 | */ | |
121 | public boolean isText() { | |
122 | 0 | return false; |
123 | } | |
124 | ||
125 | /** | |
126 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isTextarea() | |
127 | */ | |
128 | public boolean isTextarea() { | |
129 | 0 | return false; |
130 | } | |
131 | ||
132 | /** | |
133 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isCurrency() | |
134 | */ | |
135 | public boolean isCurrency() { | |
136 | 0 | return false; |
137 | } | |
138 | ||
139 | /** | |
140 | * | |
141 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isKualiUser() | |
142 | */ | |
143 | public boolean isKualiUser() { | |
144 | 0 | return false; |
145 | } | |
146 | ||
147 | /** | |
148 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isWorkgroup() | |
149 | */ | |
150 | public boolean isWorkflowWorkgroup() { | |
151 | 0 | return false; |
152 | } | |
153 | ||
154 | /** | |
155 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isFile() | |
156 | */ | |
157 | public boolean isFile() { | |
158 | 0 | return false; |
159 | } | |
160 | ||
161 | /** | |
162 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isLookupHidden() | |
163 | */ | |
164 | public boolean isLookupHidden() { | |
165 | 0 | return false; |
166 | } | |
167 | ||
168 | /** | |
169 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isLookupReadonly() | |
170 | */ | |
171 | public boolean isLookupReadonly() { | |
172 | 0 | return false; |
173 | } | |
174 | ||
175 | /** | |
176 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isButton() | |
177 | */ | |
178 | public boolean isButton() { | |
179 | 0 | return false; |
180 | } | |
181 | ||
182 | /** | |
183 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isLink() | |
184 | */ | |
185 | public boolean isLink() { | |
186 | 0 | return false; |
187 | } | |
188 | ||
189 | ||
190 | /** | |
191 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#setKeyValuesFinder(java.lang.String) | |
192 | */ | |
193 | public void setValuesFinderClass(String valuesFinderClass) { | |
194 | 0 | if (valuesFinderClass == null) { |
195 | 0 | throw new IllegalArgumentException("invalid (null) valuesFinderClass"); |
196 | } | |
197 | ||
198 | 0 | this.valuesFinderClass = valuesFinderClass; |
199 | 0 | } |
200 | ||
201 | /** | |
202 | * @return the businessObjectClass | |
203 | */ | |
204 | public String getBusinessObjectClass() { | |
205 | 0 | return this.businessObjectClass; |
206 | } | |
207 | ||
208 | /** | |
209 | * Used by a PersistableBusinessObjectValuesFinder to automatically query and display a list | |
210 | * of business objects as part of a select list or set of radio buttons. | |
211 | * | |
212 | * The keyAttribute, labelAttribute, and includeKeyInLabel are used with this property. | |
213 | * | |
214 | * @param businessObjectClass the businessObjectClass to set | |
215 | */ | |
216 | public void setBusinessObjectClass(String businessObjectClass) { | |
217 | 0 | if (businessObjectClass == null) { |
218 | 0 | throw new IllegalArgumentException("invalid (null) businessObjectClass"); |
219 | } | |
220 | ||
221 | 0 | this.businessObjectClass = businessObjectClass; |
222 | 0 | } |
223 | ||
224 | /** | |
225 | * @return the includeBlankRow | |
226 | */ | |
227 | public Boolean getIncludeBlankRow() { | |
228 | 0 | return this.includeBlankRow; |
229 | } | |
230 | ||
231 | /** | |
232 | * @return the includeBlankRow | |
233 | */ | |
234 | public void setIncludeBlankRow(Boolean includeBlankRow) { | |
235 | 0 | this.includeBlankRow = includeBlankRow; |
236 | 0 | } |
237 | ||
238 | /** | |
239 | * @return the includeKeyInLabel | |
240 | */ | |
241 | public Boolean getIncludeKeyInLabel() { | |
242 | 0 | return this.includeKeyInLabel; |
243 | } | |
244 | ||
245 | /** | |
246 | * Whether to include the key in the label for select lists and radio buttons. | |
247 | */ | |
248 | public void setIncludeKeyInLabel(Boolean includeKeyInLabel) { | |
249 | 0 | this.includeKeyInLabel = includeKeyInLabel; |
250 | 0 | } |
251 | ||
252 | /** | |
253 | * @return the keyAttribute | |
254 | */ | |
255 | public String getKeyAttribute() { | |
256 | 0 | return this.keyAttribute; |
257 | } | |
258 | ||
259 | /** | |
260 | * Attribute of the given businessObjectClass to use as the value of a select list | |
261 | * or set of radio buttons. | |
262 | */ | |
263 | public void setKeyAttribute(String keyAttribute) { | |
264 | 0 | this.keyAttribute = keyAttribute; |
265 | 0 | } |
266 | ||
267 | /** | |
268 | * @return the labelAttribute | |
269 | */ | |
270 | public String getLabelAttribute() { | |
271 | 0 | return this.labelAttribute; |
272 | } | |
273 | ||
274 | /** | |
275 | * Attribute of the given businessObjectClass to use as the displayed label on a select list | |
276 | * or set of radio buttons. | |
277 | */ | |
278 | public void setLabelAttribute(String labelAttribute) { | |
279 | 0 | this.labelAttribute = labelAttribute; |
280 | 0 | } |
281 | ||
282 | /** | |
283 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#getKeyValuesFinder() | |
284 | */ | |
285 | public String getValuesFinderClass() { | |
286 | 0 | return valuesFinderClass; |
287 | } | |
288 | ||
289 | /** | |
290 | * Size of a text control. | |
291 | * | |
292 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#setSize(int) | |
293 | */ | |
294 | public void setSize(Integer size) { | |
295 | 0 | this.size = size; |
296 | 0 | } |
297 | ||
298 | /** | |
299 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#getSize() | |
300 | */ | |
301 | public Integer getSize() { | |
302 | 0 | return size; |
303 | } | |
304 | ||
305 | /** | |
306 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#hasScript() | |
307 | */ | |
308 | public boolean hasScript() { | |
309 | 0 | return false; |
310 | } | |
311 | ||
312 | /** | |
313 | * Number of rows to display on a text-area widget. | |
314 | * | |
315 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#setRows(int) | |
316 | */ | |
317 | public void setRows(Integer rows) { | |
318 | 0 | this.rows = rows; |
319 | 0 | } |
320 | ||
321 | /** | |
322 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#getRows() | |
323 | */ | |
324 | public Integer getRows() { | |
325 | 0 | return rows; |
326 | } | |
327 | ||
328 | /** | |
329 | * Number of columns to display on a text-area widget. | |
330 | * | |
331 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#setCols(int) | |
332 | */ | |
333 | public void setCols(Integer cols) { | |
334 | 0 | this.cols = cols; |
335 | 0 | } |
336 | ||
337 | /** | |
338 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#getCols() | |
339 | */ | |
340 | public Integer getCols() { | |
341 | 0 | return cols; |
342 | } | |
343 | ||
344 | /** | |
345 | * Directly validate simple fields. | |
346 | * | |
347 | * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object) | |
348 | */ | |
349 | public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) { | |
350 | 0 | if (!isCheckbox() && !isHidden() && !isRadio() && !isSelect() && !isMultiselect() && !isText() && !isTextarea() && !isCurrency() && !isKualiUser() && !isLookupHidden() && !isLookupReadonly() && !isWorkflowWorkgroup() && !isFile()&& !isButton() && !isLink()) { |
351 | 0 | throw new CompletionException("error validating " + rootBusinessObjectClass.getName() + " control: unknown control type in control definition (" + "" + ")"); |
352 | } | |
353 | 0 | if (valuesFinderClass != null) { |
354 | try { | |
355 | 0 | Class valuesFinderClassObject = ClassUtils.getClass(ClassLoaderUtils.getDefaultClassLoader(), getValuesFinderClass()); |
356 | 0 | if (!KeyValuesFinder.class.isAssignableFrom(valuesFinderClassObject)) { |
357 | 0 | throw new ClassValidationException("valuesFinderClass is not a valid instance of " + KeyValuesFinder.class.getName() + " instead was: " + valuesFinderClassObject.getName()); |
358 | } | |
359 | 0 | } catch (ClassNotFoundException e) { |
360 | 0 | throw new ClassValidationException("valuesFinderClass could not be found: " + getValuesFinderClass(), e); |
361 | 0 | } |
362 | } | |
363 | 0 | if (businessObjectClass != null) { |
364 | try { | |
365 | 0 | Class businessObjectClassObject = ClassUtils.getClass(ClassLoaderUtils.getDefaultClassLoader(), getBusinessObjectClass()); |
366 | 0 | if (!BusinessObject.class.isAssignableFrom(businessObjectClassObject)) { |
367 | 0 | throw new ClassValidationException("businessObjectClass is not a valid instance of " + BusinessObject.class.getName() + " instead was: " + businessObjectClassObject.getName()); |
368 | } | |
369 | 0 | } catch (ClassNotFoundException e) { |
370 | 0 | throw new ClassValidationException("businessObjectClass could not be found: " + getBusinessObjectClass(), e); |
371 | 0 | } |
372 | } | |
373 | 0 | } |
374 | ||
375 | /** | |
376 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#getScript() | |
377 | */ | |
378 | public String getScript() { | |
379 | 0 | return script; |
380 | } | |
381 | ||
382 | /** | |
383 | * JavaScript script to run when a select control's value is changed. | |
384 | * | |
385 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#setScript() | |
386 | */ | |
387 | public void setScript(String script) { | |
388 | 0 | this.script = script; |
389 | 0 | } |
390 | ||
391 | /** | |
392 | * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isRanged() | |
393 | */ | |
394 | public boolean isRanged() { | |
395 | 0 | return this.ranged; |
396 | } | |
397 | ||
398 | /** | |
399 | * Sets the control as a ranged (from and to) date field if true, or a single date field if false | |
400 | * | |
401 | * @param ranged boolean true for a ranged control, false for a single date field | |
402 | */ | |
403 | public void setRanged(boolean ranged) { | |
404 | 0 | this.ranged = ranged; |
405 | 0 | } |
406 | ||
407 | /** | |
408 | * @see java.lang.Object#equals(Object) | |
409 | */ | |
410 | public boolean equals(Object object) { | |
411 | 0 | if ( !(object instanceof ControlDefinitionBase) ) { |
412 | 0 | return false; |
413 | } | |
414 | 0 | ControlDefinitionBase rhs = (ControlDefinitionBase)object; |
415 | 0 | return new EqualsBuilder() |
416 | .append( this.cols, rhs.cols ) | |
417 | .append( this.businessObjectClass, rhs.businessObjectClass ) | |
418 | .append( this.valuesFinderClass, rhs.valuesFinderClass ) | |
419 | .append( this.rows, rhs.rows ) | |
420 | .append( this.script, rhs.script ) | |
421 | .append( this.size, rhs.size ) | |
422 | .append( this.datePicker, rhs.datePicker ) | |
423 | .append( this.ranged, rhs.ranged ) | |
424 | .append( this.labelAttribute,rhs.labelAttribute ) | |
425 | .append( this.includeKeyInLabel, rhs.includeKeyInLabel ) | |
426 | .append( this.keyAttribute, rhs.keyAttribute ) | |
427 | .isEquals(); | |
428 | } | |
429 | ||
430 | ||
431 | } |