View Javadoc
1   /**
2    * Copyright 2005-2015 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.kns.datadictionary.control;
17  
18  import org.apache.commons.lang.ClassUtils;
19  import org.apache.commons.lang.builder.EqualsBuilder;
20  import org.kuali.rice.core.api.util.ClassLoaderUtils;
21  import org.kuali.rice.krad.bo.BusinessObject;
22  import org.kuali.rice.krad.datadictionary.DataDictionaryDefinitionBase;
23  import org.kuali.rice.krad.datadictionary.control.ControlDefinition;
24  import org.kuali.rice.krad.datadictionary.exception.ClassValidationException;
25  import org.kuali.rice.krad.datadictionary.exception.CompletionException;
26  import org.kuali.rice.krad.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   * @deprecated Only used by KNS classes, use KRAD.
34   */
35  @Deprecated
36  public abstract class ControlDefinitionBase extends DataDictionaryDefinitionBase implements ControlDefinition {
37      private static final long serialVersionUID = 4372435175782501152L;
38      
39  	protected boolean datePicker;
40  	protected boolean expandedTextArea;
41      protected String script;
42      protected String valuesFinderClass;
43      protected String businessObjectClass;
44      protected String keyAttribute;
45      protected String labelAttribute;
46      protected Boolean includeBlankRow;
47      protected Boolean includeKeyInLabel;
48      protected Integer size;
49      protected Integer rows;
50      protected Integer cols;
51      protected boolean ranged;
52  
53  
54      public ControlDefinitionBase() {
55      	ranged = true;
56      }
57  
58      public boolean isDatePicker() {
59          return datePicker;
60      }
61  
62      /** Whether this control should have a date picker button next to the field.
63       *  Valid for text fields.
64       *  
65       * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#setDatePicker(boolean)
66       */
67      public void setDatePicker(boolean datePicker) {
68          this.datePicker=datePicker;
69      }
70      
71      public boolean isExpandedTextArea() {
72          return expandedTextArea;
73      }
74  
75      /** Whether this control should have a expanded text area button next to the field.
76       *  Valid for textarea fields.
77       *  
78       * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#setExpandedTextArea(boolean)
79       */
80      public void setExpandedTextArea(boolean eTextArea) {
81          this.expandedTextArea=eTextArea;
82      }
83  
84      /**
85       * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isCheckbox()
86       */
87      public boolean isCheckbox() {
88          return false;
89      }
90  
91      /**
92       * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isHidden()
93       */
94      public boolean isHidden() {
95          return false;
96      }
97  
98      /**
99       * @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 }