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