View Javadoc

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