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.kuali.ole.sys.businessobject.AccountingLine;
22  import org.kuali.ole.sys.document.web.AccountingLineViewLineFillingElement;
23  import org.kuali.ole.sys.document.web.AccountingLineViewLines;
24  import org.kuali.ole.sys.document.web.TableJoining;
25  import org.kuali.rice.krad.datadictionary.DataDictionaryDefinitionBase;
26  import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
27  
28  /**
29   * Data dictionary definition for a group of multiple lines to render.  This also renders blocks - though each block will be rendered as a line with an embedded table
30   */
31  public class AccountingLineViewLinesDefinition extends DataDictionaryDefinitionBase implements AccountingLineViewRenderableElementDefinition {
32      private List<AccountingLineViewLineFillingDefinition> lines;
33      private String elementName;
34  
35      /**
36       * Validates that:
37       * 1) there is at least one child line
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 (lines == null || lines.size() == 0) {
42              throw new AttributeValidationException("Please specify at least one child line for the lines definition");
43          }
44      }
45  
46      /**
47       * Gets the lines attribute. 
48       * @return Returns the lines.
49       */
50      public List<AccountingLineViewLineFillingDefinition> getLines() {
51          return lines;
52      }
53  
54      /**
55       * Sets the lines attribute value.
56       * @param lines The lines to set.
57       */
58      public void setLines(List<AccountingLineViewLineFillingDefinition> lines) {
59          this.lines = lines;
60      }
61  
62      /**
63       * Gets the elementName attribute. 
64       * @return Returns the elementName.
65       */
66      public String getElementName() {
67          return elementName;
68      }
69  
70      /**
71       * Sets the elementName attribute value.
72       * @param elementName The elementName to set.
73       */
74      public void setElementName(String elementName) {
75          this.elementName = elementName;
76      }
77  
78      /**
79       * @see org.kuali.ole.sys.document.datadictionary.AccountingLineViewRenderableElementDefinition#createLayoutElement()
80       */
81      public TableJoining createLayoutElement(Class<? extends AccountingLine> accountingLineClass) {
82          AccountingLineViewLines layoutElement = new AccountingLineViewLines();
83          layoutElement.setDefinition(this);
84          layoutElement.setElements(getLayoutElementsForLines(accountingLineClass));
85          return layoutElement;
86      }
87      
88      /**
89       * Generates layout elements for all the child lines of this lines definition
90       * @return a List with the line elements for all child lines of this element definition 
91       */
92      protected List<AccountingLineViewLineFillingElement> getLayoutElementsForLines(Class<? extends AccountingLine> accountingLineClass) {
93          List<AccountingLineViewLineFillingElement> elements = new ArrayList<AccountingLineViewLineFillingElement>();
94          for (AccountingLineViewLineFillingDefinition line : lines) {
95              elements.add(line.createLineFillingLayoutElement(accountingLineClass));
96          }
97          return elements;
98      }
99  }