001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.sys.document.datadictionary;
017
018 import java.util.ArrayList;
019 import java.util.List;
020
021 import org.kuali.kfs.sys.businessobject.AccountingLine;
022 import org.kuali.kfs.sys.document.web.AccountingLineViewLine;
023 import org.kuali.kfs.sys.document.web.AccountingLineViewLineFillingElement;
024 import org.kuali.kfs.sys.document.web.AccountingLineViewLines;
025 import org.kuali.kfs.sys.document.web.TableJoining;
026 import org.kuali.rice.kns.datadictionary.DataDictionaryDefinitionBase;
027 import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException;
028
029 /**
030 * 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
031 */
032 public class AccountingLineViewLinesDefinition extends DataDictionaryDefinitionBase implements AccountingLineViewRenderableElementDefinition {
033 private List<AccountingLineViewLineFillingDefinition> lines;
034 private String elementName;
035
036 /**
037 * Validates that:
038 * 1) there is at least one child line
039 * @see org.kuali.rice.kns.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Class)
040 */
041 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
042 if (lines == null || lines.size() == 0) {
043 throw new AttributeValidationException("Please specify at least one child line for the lines definition");
044 }
045 }
046
047 /**
048 * Gets the lines attribute.
049 * @return Returns the lines.
050 */
051 public List<AccountingLineViewLineFillingDefinition> getLines() {
052 return lines;
053 }
054
055 /**
056 * Sets the lines attribute value.
057 * @param lines The lines to set.
058 */
059 public void setLines(List<AccountingLineViewLineFillingDefinition> lines) {
060 this.lines = lines;
061 }
062
063 /**
064 * Gets the elementName attribute.
065 * @return Returns the elementName.
066 */
067 public String getElementName() {
068 return elementName;
069 }
070
071 /**
072 * Sets the elementName attribute value.
073 * @param elementName The elementName to set.
074 */
075 public void setElementName(String elementName) {
076 this.elementName = elementName;
077 }
078
079 /**
080 * @see org.kuali.kfs.sys.document.datadictionary.AccountingLineViewRenderableElementDefinition#createLayoutElement()
081 */
082 public TableJoining createLayoutElement(Class<? extends AccountingLine> accountingLineClass) {
083 AccountingLineViewLines layoutElement = new AccountingLineViewLines();
084 layoutElement.setDefinition(this);
085 layoutElement.setElements(getLayoutElementsForLines(accountingLineClass));
086 return layoutElement;
087 }
088
089 /**
090 * Generates layout elements for all the child lines of this lines definition
091 * @return a List with the line elements for all child lines of this element definition
092 */
093 protected List<AccountingLineViewLineFillingElement> getLayoutElementsForLines(Class<? extends AccountingLine> accountingLineClass) {
094 List<AccountingLineViewLineFillingElement> elements = new ArrayList<AccountingLineViewLineFillingElement>();
095 for (AccountingLineViewLineFillingDefinition line : lines) {
096 elements.add(line.createLineFillingLayoutElement(accountingLineClass));
097 }
098 return elements;
099 }
100 }