001/*
002 * Copyright 2008 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 */
016package org.kuali.ole.sys.document.datadictionary;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.ole.sys.document.web.renderers.GroupTotalRenderer;
020import org.kuali.ole.sys.document.web.renderers.Renderer;
021import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
022
023/**
024 * The definition of an accounting line group total renderer, which will display an accounting line
025 * group total as a standard "Total: " + amount.
026 */
027public class AccountingLineGroupTotalDefinition extends TotalDefinition{
028    private String totalProperty;
029    private String representedProperty;
030    private boolean nestedProperty;
031    private String containingPropertyName;
032    private String totalLabelProperty = "accounting.line.group.total.label";
033    
034    /**
035     * Gets the totalProperty attribute. 
036     * @return Returns the totalProperty.
037     */
038    public String getTotalProperty() {
039        return totalProperty;
040    }
041
042    /**
043     * Sets the totalProperty attribute value.
044     * @param totalProperty The totalProperty to set.
045     */
046    public void setTotalProperty(String totalProperty) {
047        this.totalProperty = totalProperty;
048    }
049
050    /**
051     * Gets the totalLabelProperty attribute. 
052     * @return Returns the totalLabelProperty.
053     */
054    public String getTotalLabelProperty() {
055        return totalLabelProperty;
056    }
057
058    /**
059     * Sets the totalLabelProperty attribute value.
060     * @param totalLabelProperty The totalLabelProperty to set.
061     */
062    public void setTotalLabelProperty(String totalLabelProperty) {
063        this.totalLabelProperty = totalLabelProperty;
064    }
065    
066    /**
067     * Uses GroupTotalRenderer to render the total
068     * @see org.kuali.ole.sys.document.datadictionary.TotalDefinition#getTotalRenderer()
069     */
070    @Override
071    public Renderer getTotalRenderer() {
072        GroupTotalRenderer renderer = new GroupTotalRenderer();
073        
074        renderer.setTotalLabelProperty(totalLabelProperty);
075        renderer.setRepresentedCellPropertyName(representedProperty);
076        
077        final String actualTotalProperty = this.getActualPropertyName(containingPropertyName, totalProperty);
078        renderer.setTotalProperty(actualTotalProperty);
079        
080        return renderer;
081    }
082
083    /**
084     * Validates that a total property has been added
085     * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Class)
086     */
087    public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
088        if (StringUtils.isBlank(totalProperty)) {
089            throw new AttributeValidationException("Please specify a totalProperty for the AccountingLineGroupTotalRenderer");
090        }
091    }
092
093    /**
094     * Gets the representedProperty attribute. 
095     * @return Returns the representedProperty.
096     */
097    public String getRepresentedProperty() {
098        return representedProperty;
099    }
100
101    /**
102     * Sets the representedProperty attribute value.
103     * @param representedProperty The representedProperty to set.
104     */
105    public void setRepresentedProperty(String representedProperty) {
106        this.representedProperty = representedProperty;
107    }
108    
109    /**
110     * @see org.kuali.ole.sys.document.datadictionary.TotalDefinition#isNestedProperty()
111     */
112    public boolean isNestedProperty() {
113        return nestedProperty;
114    }
115
116    /**
117     * Sets the nestedProperty attribute value.
118     * @param nestedProperty The nestedProperty to set.
119     */
120    public void setNestedProperty(boolean nestedProperty) {
121        this.nestedProperty = nestedProperty;
122    }
123
124    /**
125     * @see org.kuali.ole.sys.document.web.NestedFieldTotaling#setContainingPropertyName(java.lang.String)
126     */
127    public void setContainingPropertyName(String containingPropertyName) {
128        this.containingPropertyName = containingPropertyName;
129    }
130}