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.apache.commons.lang.StringUtils; 022 import org.kuali.kfs.sys.businessobject.AccountingLine; 023 import org.kuali.kfs.sys.document.web.AccountingLineViewLine; 024 import org.kuali.kfs.sys.document.web.AccountingLineViewLineFillingElement; 025 import org.kuali.kfs.sys.document.web.RenderableElement; 026 import org.kuali.kfs.sys.document.web.TableJoining; 027 import org.kuali.rice.kns.datadictionary.DataDictionaryDefinitionBase; 028 import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException; 029 030 /** 031 * Data dictionary definition of a collection of elements which will be rendered as one table row in the table of each accounting line. 032 */ 033 public class AccountingLineViewLineDefinition extends DataDictionaryDefinitionBase implements AccountingLineViewLineFillingDefinition { 034 private List<? extends AccountingLineViewRenderableElementDefinition> cells; 035 private String elementName; 036 037 /** 038 * Validates that: 039 * 1) there is at least one child element 040 * @see org.kuali.rice.kns.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Class) 041 */ 042 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) { 043 if (cells == null || cells.size() == 0) { 044 throw new AttributeValidationException("At least one field must be specified to live within an AccountingLineViewLine"+(!StringUtils.isBlank(elementName) ? " ("+elementName+")" : "")); 045 } 046 } 047 048 /** 049 * Gets the fields attribute. 050 * @return Returns the fields. 051 */ 052 public List<? extends AccountingLineViewRenderableElementDefinition> getFields() { 053 return cells; 054 } 055 056 /** 057 * Sets the fields attribute value. 058 * @param fields The fields to set. 059 */ 060 public void setFields(List<? extends AccountingLineViewRenderableElementDefinition> fields) { 061 this.cells = fields; 062 } 063 064 /** 065 * Gets the elementName attribute. 066 * @return Returns the elementName. 067 */ 068 public String getElementName() { 069 return elementName; 070 } 071 072 /** 073 * Sets the elementName attribute value. 074 * @param elementName The elementName to set. 075 */ 076 public void setElementName(String elementName) { 077 this.elementName = elementName; 078 } 079 080 /** 081 * @see org.kuali.kfs.sys.document.datadictionary.AccountingLineViewRenderableElementDefinition#createLayoutElement(java.lang.Class) 082 */ 083 public TableJoining createLayoutElement(Class<? extends AccountingLine> accountingLineClass) { 084 AccountingLineViewLine line = new AccountingLineViewLine(); 085 line.setDefinition(this); 086 line.setElements(getChildrenRenderableElements(accountingLineClass)); 087 return line; 088 } 089 090 /** 091 * Creates children renderable elements for all children of this line definition 092 * @param accountingLineClass accounting line class to pass through 093 * @return a List of renderable children elements 094 */ 095 protected List<RenderableElement> getChildrenRenderableElements(Class<? extends AccountingLine> accountingLineClass) { 096 List<RenderableElement> elements = new ArrayList<RenderableElement>(); 097 for (AccountingLineViewRenderableElementDefinition cellDefinition : cells) { 098 final RenderableElement element = (RenderableElement)cellDefinition.createLayoutElement(accountingLineClass); 099 if (element != null) { 100 elements.add(element); 101 } 102 } 103 return elements; 104 } 105 106 /** 107 * @see org.kuali.kfs.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 }