View Javadoc
1   /*
2    * Copyright 2010 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.ole.sys.document.datadictionary;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.kuali.ole.sys.businessobject.AccountingLine;
22  import org.kuali.ole.sys.document.web.AccountingLineViewMultipleReadOnlyFields;
23  import org.kuali.ole.sys.document.web.TableJoining;
24  import org.kuali.rice.kns.util.FieldUtils;
25  import org.kuali.rice.kns.web.ui.Field;
26  import org.kuali.rice.krad.datadictionary.DataDictionaryDefinitionBase;
27  import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
28  
29  /**
30   * The definition for an accounting line component which displays multiple fields from the command line, but
31   * all of them as read only, with their headers displayed first
32   */
33  public class AccountingLineViewMultipleReadOnlyFieldsDefinition extends DataDictionaryDefinitionBase implements AccountingLineViewRenderableElementDefinition {
34      public List<String> fieldNames;
35  
36      /**
37       * Makes sure that the number of fields set is greater than 0
38       * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Class)
39       */
40      public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
41          if (fieldNames.isEmpty()) {
42              throw new AttributeValidationException("Please specify one or more field names when defining AccountingLineViewMultipleReadOnlyFields "+getId());
43          }
44      }
45  
46      /**
47       * Creates a new AccountingLineViewMultipleReadOnlyField
48       * @see org.kuali.ole.sys.document.datadictionary.AccountingLineViewRenderableElementDefinition#createLayoutElement(java.lang.Class)
49       */
50      public TableJoining createLayoutElement(Class<? extends AccountingLine> accountingLineClass) {
51          List<Field> fields = new ArrayList<Field>();
52          for (String fieldName: fieldNames) {
53              fields.add(getKNSFieldForDefinition(accountingLineClass, fieldName));
54          }
55          return new AccountingLineViewMultipleReadOnlyFields(this, fields);
56      }
57      
58      /**
59       * Creates a KNS Field for an AccountingLineViewField definition
60       * @param accountingLineClass the class of the accounting line used by this definition
61       * @param fieldName the name of the field to initialize
62       * @return a properly initialized KNS field
63       */
64      public Field getKNSFieldForDefinition(Class<? extends AccountingLine> accountingLineClass, String fieldName) {
65          Field realField = FieldUtils.getPropertyField(accountingLineClass, fieldName, false);
66          return realField;
67      }
68  
69      /**
70       * @return the field names of fields to display in the cell
71       */
72      public List<String> getFieldNames() {
73          return fieldNames;
74      }
75  
76      /**
77       * Sets the field names to display in the field, in top-down order
78       * @param fieldNames the field names to display
79       */
80      public void setFieldNames(List<String> fieldNames) {
81          this.fieldNames = fieldNames;
82      }
83      
84  }