View Javadoc
1   /*
2    * Copyright 2008 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.ole.sys.document.datadictionary;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.ole.sys.businessobject.AccountingLine;
23  import org.kuali.ole.sys.document.web.AccountingLineViewColumns;
24  import org.kuali.ole.sys.document.web.AccountingLineViewField;
25  import org.kuali.ole.sys.document.web.AccountingLineViewLineFillingElement;
26  import org.kuali.ole.sys.document.web.TableJoining;
27  import org.kuali.rice.krad.datadictionary.DataDictionaryDefinitionBase;
28  import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
29  
30  /**
31   * 
32   */
33  public class AccountingLineViewColumnsDefinition extends DataDictionaryDefinitionBase implements AccountingLineViewLineFillingDefinition {
34      private int columnCount = 1;
35      private List<AccountingLineViewFieldDefinition> fields;
36      private String name;
37      
38      /**
39       * 
40       * @see org.kuali.ole.sys.document.datadictionary.AccountingLineViewRenderableElementDefinition#createLayoutElement(java.lang.Class)
41       */
42      public TableJoining createLayoutElement(Class<? extends AccountingLine> accountingLineClass) {
43          List<AccountingLineViewField> layoutFields = new ArrayList<AccountingLineViewField>();
44          
45          for (AccountingLineViewFieldDefinition fieldDefinition : fields) {
46              final AccountingLineViewField field = (AccountingLineViewField)fieldDefinition.createLayoutElement(accountingLineClass);
47              if (field != null) {
48                  layoutFields.add(field);
49              }
50          }
51          
52          return new AccountingLineViewColumns(this, layoutFields);
53      }
54  
55      /**
56       * @see org.kuali.ole.sys.document.datadictionary.AccountingLineViewLineFillingDefinition#createLineFillingLayoutElement(java.lang.Class)
57       */
58      public AccountingLineViewLineFillingElement createLineFillingLayoutElement(Class<? extends AccountingLine> accountingLineClass) {
59          return (AccountingLineViewLineFillingElement)createLayoutElement(accountingLineClass);
60      }
61  
62      /**
63       * 
64       * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Class)
65       */
66      public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
67          if (StringUtils.isBlank(name)) {
68              throw new AttributeValidationException("name for "+rootBusinessObjectClass.getName()+" accounting line view columns definition must be defined");
69          }
70          if (columnCount < 1) {
71              throw new AttributeValidationException("columnCount for "+rootBusinessObjectClass.getName()+" accounting line view columns data dictionary definition must be one or greater");
72          }
73          if (fields == null || fields.size() == 0) {
74              throw new AttributeValidationException("Please add at least one field to the "+rootBusinessObjectClass.getName()+" accounting line view columns definition");
75          }
76      }
77  
78      /**
79       * Gets the columnCount attribute. 
80       * @return Returns the columnCount.
81       */
82      public int getColumnCount() {
83          return columnCount;
84      }
85  
86      /**
87       * Sets the columnCount attribute value.
88       * @param columnCount The columnCount to set.
89       */
90      public void setColumnCount(int columnCount) {
91          this.columnCount = columnCount;
92      }
93  
94      /**
95       * Gets the fields attribute. 
96       * @return Returns the fields.
97       */
98      public List<AccountingLineViewFieldDefinition> getFields() {
99          return fields;
100     }
101 
102     /**
103      * Sets the fields attribute value.
104      * @param fields The fields to set.
105      */
106     public void setFields(List<AccountingLineViewFieldDefinition> fields) {
107         this.fields = fields;
108     }
109 
110     /**
111      * Gets the name attribute. 
112      * @return Returns the name.
113      */
114     public String getName() {
115         return name;
116     }
117 
118     /**
119      * Sets the name attribute value.
120      * @param name The name to set.
121      */
122     public void setName(String name) {
123         this.name = name;
124     }
125     
126 }