Coverage Report - org.kuali.rice.kns.datadictionary.control.ControlDefinitionBase
 
Classes in this File Line Coverage Branch Coverage Complexity
ControlDefinitionBase
0%
0/83
0%
0/44
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.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  0
     public ControlDefinitionBase() {
 56  0
             ranged = true;
 57  0
     }
 58  
 
 59  
     public boolean isDatePicker() {
 60  0
         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  0
         this.datePicker=datePicker;
 70  0
     }
 71  
     
 72  
     public boolean isExpandedTextArea() {
 73  0
         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  0
         this.expandedTextArea=eTextArea;
 83  0
     }
 84  
 
 85  
     /**
 86  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isCheckbox()
 87  
      */
 88  
     public boolean isCheckbox() {
 89  0
         return false;
 90  
     }
 91  
 
 92  
     /**
 93  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isHidden()
 94  
      */
 95  
     public boolean isHidden() {
 96  0
         return false;
 97  
     }
 98  
 
 99  
     /**
 100  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isRadio()
 101  
      */
 102  
     public boolean isRadio() {
 103  0
         return false;
 104  
     }
 105  
 
 106  
     /**
 107  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isSelect()
 108  
      */
 109  
     public boolean isSelect() {
 110  0
         return false;
 111  
     }
 112  
     
 113  
     /**
 114  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isSelect()
 115  
      */
 116  
     public boolean isMultiselect() {
 117  0
         return false;
 118  
     }
 119  
 
 120  
     /**
 121  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isText()
 122  
      */
 123  
     public boolean isText() {
 124  0
         return false;
 125  
     }
 126  
 
 127  
     /**
 128  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isTextarea()
 129  
      */
 130  
     public boolean isTextarea() {
 131  0
         return false;
 132  
     }
 133  
 
 134  
     /**
 135  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isCurrency()
 136  
      */
 137  
     public boolean isCurrency() {
 138  0
         return false;
 139  
     }
 140  
 
 141  
     /**
 142  
      *
 143  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isKualiUser()
 144  
      */
 145  
     public boolean isKualiUser() {
 146  0
         return false;
 147  
     }
 148  
 
 149  
     /**
 150  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isWorkgroup()
 151  
      */
 152  
     public boolean isWorkflowWorkgroup() {
 153  0
         return false;
 154  
     }
 155  
 
 156  
     /**
 157  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isFile()
 158  
      */
 159  
     public boolean isFile() {
 160  0
         return false;
 161  
     }
 162  
 
 163  
     /**
 164  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isLookupHidden()
 165  
      */
 166  
     public boolean isLookupHidden() {
 167  0
         return false;
 168  
     }
 169  
 
 170  
     /**
 171  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isLookupReadonly()
 172  
      */
 173  
     public boolean isLookupReadonly() {
 174  0
         return false;
 175  
     }
 176  
     
 177  
     /**
 178  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isButton()
 179  
      */
 180  
     public boolean isButton() {
 181  0
         return false;
 182  
     }
 183  
     
 184  
     /**
 185  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isLink()
 186  
      */
 187  
     public boolean isLink() {
 188  0
         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  0
         if (valuesFinderClass == null) {
 197  0
             throw new IllegalArgumentException("invalid (null) valuesFinderClass");
 198  
         }
 199  
 
 200  0
         this.valuesFinderClass = valuesFinderClass;
 201  0
     }
 202  
 
 203  
     /**
 204  
      * @return the dataObjectClass
 205  
      */
 206  
     public String getBusinessObjectClass() {
 207  0
         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  0
         if (businessObjectClass == null) {
 220  0
             throw new IllegalArgumentException("invalid (null) dataObjectClass");
 221  
         }
 222  
 
 223  0
         this.businessObjectClass = businessObjectClass;
 224  0
     }
 225  
 
 226  
     /**
 227  
      * @return the includeBlankRow
 228  
      */
 229  
     public Boolean getIncludeBlankRow() {
 230  0
         return this.includeBlankRow;
 231  
     }
 232  
 
 233  
     /**
 234  
      * @return the includeBlankRow
 235  
      */
 236  
     public void setIncludeBlankRow(Boolean includeBlankRow) {
 237  0
         this.includeBlankRow = includeBlankRow;
 238  0
     }
 239  
 
 240  
     /**
 241  
      * @return the includeKeyInLabel
 242  
      */
 243  
     public Boolean getIncludeKeyInLabel() {
 244  0
         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  0
         this.includeKeyInLabel = includeKeyInLabel;
 252  0
     }
 253  
 
 254  
     /**
 255  
      * @return the keyAttribute
 256  
      */
 257  
     public String getKeyAttribute() {
 258  0
         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  0
         this.keyAttribute = keyAttribute;
 267  0
     }
 268  
 
 269  
     /**
 270  
      * @return the labelAttribute
 271  
      */
 272  
     public String getLabelAttribute() {
 273  0
         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  0
         this.labelAttribute = labelAttribute;
 282  0
     }
 283  
 
 284  
     /**
 285  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#getKeyValuesFinder()
 286  
      */
 287  
     public String getValuesFinderClass() {
 288  0
         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  0
         this.size = size;
 298  0
     }
 299  
 
 300  
     /**
 301  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#getSize()
 302  
      */
 303  
     public Integer getSize() {
 304  0
         return size;
 305  
     }
 306  
 
 307  
     /**
 308  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#hasScript()
 309  
      */
 310  
     public boolean hasScript() {
 311  0
         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  0
         this.rows = rows;
 321  0
     }
 322  
 
 323  
     /**
 324  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#getRows()
 325  
      */
 326  
     public Integer getRows() {
 327  0
         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  0
         this.cols = cols;
 337  0
     }
 338  
 
 339  
     /**
 340  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#getCols()
 341  
      */
 342  
     public Integer getCols() {
 343  0
         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  0
         if (!isCheckbox() && !isHidden() && !isRadio() && !isSelect() && !isMultiselect() && !isText() && !isTextarea() && !isCurrency() && !isKualiUser() && !isLookupHidden() && !isLookupReadonly() && !isWorkflowWorkgroup() && !isFile()&& !isButton() && !isLink()) {
 353  0
             throw new CompletionException("error validating " + rootBusinessObjectClass.getName() + " control: unknown control type in control definition (" + "" + ")");
 354  
         }
 355  0
         if (valuesFinderClass != null) {
 356  
                 try {
 357  0
                         Class valuesFinderClassObject = ClassUtils.getClass(ClassLoaderUtils.getDefaultClassLoader(), getValuesFinderClass());
 358  0
                         if (!KeyValuesFinder.class.isAssignableFrom(valuesFinderClassObject)) {
 359  0
                                 throw new ClassValidationException("valuesFinderClass is not a valid instance of " + KeyValuesFinder.class.getName() + " instead was: " + valuesFinderClassObject.getName());
 360  
                         }
 361  0
                 } catch (ClassNotFoundException e) {
 362  0
                         throw new ClassValidationException("valuesFinderClass could not be found: " + getValuesFinderClass(), e);
 363  0
                 }
 364  
         }
 365  0
         if (businessObjectClass != null) {
 366  
                 try {
 367  0
                         Class businessObjectClassObject = ClassUtils.getClass(ClassLoaderUtils.getDefaultClassLoader(), getBusinessObjectClass());
 368  0
                         if (!BusinessObject.class.isAssignableFrom(businessObjectClassObject)) {
 369  0
                                 throw new ClassValidationException("dataObjectClass is not a valid instance of " + BusinessObject.class.getName() + " instead was: " + businessObjectClassObject.getName());
 370  
                         }
 371  0
                 } catch (ClassNotFoundException e) {
 372  0
                         throw new ClassValidationException("dataObjectClass could not be found: " + getBusinessObjectClass(), e);
 373  0
                 }
 374  
         }
 375  0
     }
 376  
 
 377  
     /**
 378  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#getScript()
 379  
      */
 380  
     public String getScript() {
 381  0
         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  0
         this.script = script;
 391  0
     }
 392  
     
 393  
     /**
 394  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#isRanged()
 395  
      */
 396  
     public boolean isRanged() {
 397  0
                 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  0
                 this.ranged = ranged;
 407  0
         }
 408  
 
 409  
         /**
 410  
      * @see java.lang.Object#equals(Object)
 411  
      */
 412  
     public boolean equals(Object object) {
 413  0
             if ( !(object instanceof ControlDefinitionBase) ) {
 414  0
                     return false;
 415  
             }
 416  0
             ControlDefinitionBase rhs = (ControlDefinitionBase)object;
 417  0
             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  
 }