001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kns.datadictionary.control;
017
018 import org.apache.commons.lang.ClassUtils;
019 import org.apache.commons.lang.builder.EqualsBuilder;
020 import org.kuali.rice.core.api.util.ClassLoaderUtils;
021 import org.kuali.rice.krad.bo.BusinessObject;
022 import org.kuali.rice.krad.datadictionary.DataDictionaryDefinitionBase;
023 import org.kuali.rice.krad.datadictionary.control.ControlDefinition;
024 import org.kuali.rice.krad.datadictionary.exception.ClassValidationException;
025 import org.kuali.rice.krad.datadictionary.exception.CompletionException;
026 import org.kuali.rice.krad.keyvalues.KeyValuesFinder;
027
028 /**
029 * A single HTML control definition in the DataDictionary, which contains information relating to the HTML control used to realize a
030 * specific attribute. All types of controls are represented by an instance of this class; you have to call one of the is* methods
031 * to figure out which of the other accessors should return useful values.
032 *
033 *
034 */
035 @Deprecated
036 public abstract class ControlDefinitionBase extends DataDictionaryDefinitionBase implements ControlDefinition {
037 private static final long serialVersionUID = 4372435175782501152L;
038
039 protected boolean datePicker;
040 protected boolean expandedTextArea;
041 protected String script;
042 protected String valuesFinderClass;
043 protected String businessObjectClass;
044 protected String keyAttribute;
045 protected String labelAttribute;
046 protected Boolean includeBlankRow;
047 protected Boolean includeKeyInLabel;
048 protected Integer size;
049 protected Integer rows;
050 protected Integer cols;
051 protected boolean ranged;
052
053
054 public ControlDefinitionBase() {
055 ranged = true;
056 }
057
058 public boolean isDatePicker() {
059 return datePicker;
060 }
061
062 /** Whether this control should have a date picker button next to the field.
063 * Valid for text fields.
064 *
065 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#setDatePicker(boolean)
066 */
067 public void setDatePicker(boolean datePicker) {
068 this.datePicker=datePicker;
069 }
070
071 public boolean isExpandedTextArea() {
072 return expandedTextArea;
073 }
074
075 /** Whether this control should have a expanded text area button next to the field.
076 * Valid for textarea fields.
077 *
078 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#setExpandedTextArea(boolean)
079 */
080 public void setExpandedTextArea(boolean eTextArea) {
081 this.expandedTextArea=eTextArea;
082 }
083
084 /**
085 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isCheckbox()
086 */
087 public boolean isCheckbox() {
088 return false;
089 }
090
091 /**
092 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isHidden()
093 */
094 public boolean isHidden() {
095 return false;
096 }
097
098 /**
099 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isRadio()
100 */
101 public boolean isRadio() {
102 return false;
103 }
104
105 /**
106 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isSelect()
107 */
108 public boolean isSelect() {
109 return false;
110 }
111
112 /**
113 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isSelect()
114 */
115 public boolean isMultiselect() {
116 return false;
117 }
118
119 /**
120 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isText()
121 */
122 public boolean isText() {
123 return false;
124 }
125
126 /**
127 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isTextarea()
128 */
129 public boolean isTextarea() {
130 return false;
131 }
132
133 /**
134 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isCurrency()
135 */
136 public boolean isCurrency() {
137 return false;
138 }
139
140 /**
141 *
142 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isKualiUser()
143 */
144 public boolean isKualiUser() {
145 return false;
146 }
147
148 /**
149 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isWorkgroup()
150 */
151 public boolean isWorkflowWorkgroup() {
152 return false;
153 }
154
155 /**
156 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isFile()
157 */
158 public boolean isFile() {
159 return false;
160 }
161
162 /**
163 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isLookupHidden()
164 */
165 public boolean isLookupHidden() {
166 return false;
167 }
168
169 /**
170 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isLookupReadonly()
171 */
172 public boolean isLookupReadonly() {
173 return false;
174 }
175
176 /**
177 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isButton()
178 */
179 public boolean isButton() {
180 return false;
181 }
182
183 /**
184 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isLink()
185 */
186 public boolean isLink() {
187 return false;
188 }
189
190
191 /**
192 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#setKeyValuesFinder(java.lang.String)
193 */
194 public void setValuesFinderClass(String valuesFinderClass) {
195 if (valuesFinderClass == null) {
196 throw new IllegalArgumentException("invalid (null) valuesFinderClass");
197 }
198
199 this.valuesFinderClass = valuesFinderClass;
200 }
201
202 /**
203 * @return the dataObjectClass
204 */
205 public String getBusinessObjectClass() {
206 return this.businessObjectClass;
207 }
208
209 /**
210 * Used by a PersistableBusinessObjectValuesFinder to automatically query and display a list
211 * of business objects as part of a select list or set of radio buttons.
212 *
213 * The keyAttribute, labelAttribute, and includeKeyInLabel are used with this property.
214 *
215 * @param businessObjectClass the dataObjectClass to set
216 */
217 public void setBusinessObjectClass(String businessObjectClass) {
218 if (businessObjectClass == null) {
219 throw new IllegalArgumentException("invalid (null) dataObjectClass");
220 }
221
222 this.businessObjectClass = businessObjectClass;
223 }
224
225 /**
226 * @return the includeBlankRow
227 */
228 public Boolean getIncludeBlankRow() {
229 return this.includeBlankRow;
230 }
231
232 /**
233 * @return the includeBlankRow
234 */
235 public void setIncludeBlankRow(Boolean includeBlankRow) {
236 this.includeBlankRow = includeBlankRow;
237 }
238
239 /**
240 * @return the includeKeyInLabel
241 */
242 public Boolean getIncludeKeyInLabel() {
243 return this.includeKeyInLabel;
244 }
245
246 /**
247 * Whether to include the key in the label for select lists and radio buttons.
248 */
249 public void setIncludeKeyInLabel(Boolean includeKeyInLabel) {
250 this.includeKeyInLabel = includeKeyInLabel;
251 }
252
253 /**
254 * @return the keyAttribute
255 */
256 public String getKeyAttribute() {
257 return this.keyAttribute;
258 }
259
260 /**
261 * Attribute of the given dataObjectClass to use as the value of a select list
262 * or set of radio buttons.
263 */
264 public void setKeyAttribute(String keyAttribute) {
265 this.keyAttribute = keyAttribute;
266 }
267
268 /**
269 * @return the labelAttribute
270 */
271 public String getLabelAttribute() {
272 return this.labelAttribute;
273 }
274
275 /**
276 * Attribute of the given dataObjectClass to use as the displayed label on a select list
277 * or set of radio buttons.
278 */
279 public void setLabelAttribute(String labelAttribute) {
280 this.labelAttribute = labelAttribute;
281 }
282
283 /**
284 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#getKeyValuesFinder()
285 */
286 public String getValuesFinderClass() {
287 return valuesFinderClass;
288 }
289
290 /**
291 * Size of a text control.
292 *
293 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#setSize(int)
294 */
295 public void setSize(Integer size) {
296 this.size = size;
297 }
298
299 /**
300 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#getSize()
301 */
302 public Integer getSize() {
303 return size;
304 }
305
306 /**
307 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#hasScript()
308 */
309 public boolean hasScript() {
310 return false;
311 }
312
313 /**
314 * Number of rows to display on a text-area widget.
315 *
316 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#setRows(int)
317 */
318 public void setRows(Integer rows) {
319 this.rows = rows;
320 }
321
322 /**
323 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#getRows()
324 */
325 public Integer getRows() {
326 return rows;
327 }
328
329 /**
330 * Number of columns to display on a text-area widget.
331 *
332 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#setCols(int)
333 */
334 public void setCols(Integer cols) {
335 this.cols = cols;
336 }
337
338 /**
339 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#getCols()
340 */
341 public Integer getCols() {
342 return cols;
343 }
344
345 /**
346 * Directly validate simple fields.
347 *
348 * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
349 */
350 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
351 if (!isCheckbox() && !isHidden() && !isRadio() && !isSelect() && !isMultiselect() && !isText() && !isTextarea() && !isCurrency() && !isKualiUser() && !isLookupHidden() && !isLookupReadonly() && !isWorkflowWorkgroup() && !isFile()&& !isButton() && !isLink()) {
352 throw new CompletionException("error validating " + rootBusinessObjectClass.getName() + " control: unknown control type in control definition (" + "" + ")");
353 }
354 if (valuesFinderClass != null) {
355 try {
356 Class valuesFinderClassObject = ClassUtils.getClass(ClassLoaderUtils.getDefaultClassLoader(), getValuesFinderClass());
357 if (!KeyValuesFinder.class.isAssignableFrom(valuesFinderClassObject)) {
358 throw new ClassValidationException("valuesFinderClass is not a valid instance of " + KeyValuesFinder.class.getName() + " instead was: " + valuesFinderClassObject.getName());
359 }
360 } catch (ClassNotFoundException e) {
361 throw new ClassValidationException("valuesFinderClass could not be found: " + getValuesFinderClass(), e);
362 }
363 }
364 if (businessObjectClass != null) {
365 try {
366 Class businessObjectClassObject = ClassUtils.getClass(ClassLoaderUtils.getDefaultClassLoader(), getBusinessObjectClass());
367 if (!BusinessObject.class.isAssignableFrom(businessObjectClassObject)) {
368 throw new ClassValidationException("dataObjectClass is not a valid instance of " + BusinessObject.class.getName() + " instead was: " + businessObjectClassObject.getName());
369 }
370 } catch (ClassNotFoundException e) {
371 throw new ClassValidationException("dataObjectClass could not be found: " + getBusinessObjectClass(), e);
372 }
373 }
374 }
375
376 /**
377 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#getScript()
378 */
379 public String getScript() {
380 return script;
381 }
382
383 /**
384 * JavaScript script to run when a select control's value is changed.
385 *
386 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#setScript()
387 */
388 public void setScript(String script) {
389 this.script = script;
390 }
391
392 /**
393 * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isRanged()
394 */
395 public boolean isRanged() {
396 return this.ranged;
397 }
398
399 /**
400 * Sets the control as a ranged (from and to) date field if true, or a single date field if false
401 *
402 * @param ranged boolean true for a ranged control, false for a single date field
403 */
404 public void setRanged(boolean ranged) {
405 this.ranged = ranged;
406 }
407
408 /**
409 * @see java.lang.Object#equals(Object)
410 */
411 public boolean equals(Object object) {
412 if ( !(object instanceof ControlDefinitionBase) ) {
413 return false;
414 }
415 ControlDefinitionBase rhs = (ControlDefinitionBase)object;
416 return new EqualsBuilder()
417 .append( this.cols, rhs.cols )
418 .append( this.businessObjectClass, rhs.businessObjectClass )
419 .append( this.valuesFinderClass, rhs.valuesFinderClass )
420 .append( this.rows, rhs.rows )
421 .append( this.script, rhs.script )
422 .append( this.size, rhs.size )
423 .append( this.datePicker, rhs.datePicker )
424 .append( this.ranged, rhs.ranged )
425 .append( this.labelAttribute,rhs.labelAttribute )
426 .append( this.includeKeyInLabel, rhs.includeKeyInLabel )
427 .append( this.keyAttribute, rhs.keyAttribute )
428 .isEquals();
429 }
430
431
432 }