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.AccountingLineViewLine;
24  import org.kuali.ole.sys.document.web.AccountingLineViewLineFillingElement;
25  import org.kuali.ole.sys.document.web.RenderableElement;
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   * Data dictionary definition of a collection of elements which will be rendered as one table row in the table of each accounting line.
32   */
33  public class AccountingLineViewLineDefinition extends DataDictionaryDefinitionBase implements AccountingLineViewLineFillingDefinition {
34      private List<? extends AccountingLineViewRenderableElementDefinition> cells;
35      private String elementName;
36  
37      /**
38       * Validates that:
39       * 1) there is at least one child element
40       * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Class)
41       */
42      public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
43          if (cells == null || cells.size() == 0) {
44              throw new AttributeValidationException("At least one field must be specified to live within an AccountingLineViewLine"+(!StringUtils.isBlank(elementName) ? " ("+elementName+")" : ""));
45          }
46      }
47  
48      /**
49       * Gets the fields attribute. 
50       * @return Returns the fields.
51       */
52      public List<? extends AccountingLineViewRenderableElementDefinition> getFields() {
53          return cells;
54      }
55  
56      /**
57       * Sets the fields attribute value.
58       * @param fields The fields to set.
59       */
60      public void setFields(List<? extends AccountingLineViewRenderableElementDefinition> fields) {
61          this.cells = fields;
62      }
63  
64      /**
65       * Gets the elementName attribute. 
66       * @return Returns the elementName.
67       */
68      public String getElementName() {
69          return elementName;
70      }
71  
72      /**
73       * Sets the elementName attribute value.
74       * @param elementName The elementName to set.
75       */
76      public void setElementName(String elementName) {
77          this.elementName = elementName;
78      }
79  
80      /**
81       * @see org.kuali.ole.sys.document.datadictionary.AccountingLineViewRenderableElementDefinition#createLayoutElement(java.lang.Class)
82       */
83      public TableJoining createLayoutElement(Class<? extends AccountingLine> accountingLineClass) {
84          AccountingLineViewLine line = new AccountingLineViewLine();
85          line.setDefinition(this);
86          line.setElements(getChildrenRenderableElements(accountingLineClass));
87          return line;
88      }
89      
90      /**
91       * Creates children renderable elements for all children of this line definition
92       * @param accountingLineClass accounting line class to pass through
93       * @return a List of renderable children elements
94       */
95      protected List<RenderableElement> getChildrenRenderableElements(Class<? extends AccountingLine> accountingLineClass) {
96          List<RenderableElement> elements = new ArrayList<RenderableElement>();
97          for (AccountingLineViewRenderableElementDefinition cellDefinition : cells) {
98              final RenderableElement element = (RenderableElement)cellDefinition.createLayoutElement(accountingLineClass);
99              if (element != null) {
100                 elements.add(element);
101             }
102         }
103         return elements;
104     }
105 
106     /**
107      * @see org.kuali.ole.sys.document.datadictionary.AccountingLineViewLineFillingDefinition#createLineFillingLayoutElement(java.lang.Class)
108      */
109     public AccountingLineViewLineFillingElement createLineFillingLayoutElement(Class<? extends AccountingLine> accountingLineClass) {
110         return (AccountingLineViewLineFillingElement)createLayoutElement(accountingLineClass);
111     }
112     
113 }