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 org.kuali.ole.sys.businessobject.AccountingLine;
19  import org.kuali.ole.sys.context.SpringContext;
20  import org.kuali.ole.sys.document.service.AccountingLineRenderingService;
21  import org.kuali.ole.sys.document.web.AccountingLineViewDebitCreditAmountLayoutElement;
22  import org.kuali.ole.sys.document.web.TableJoining;
23  import org.kuali.rice.kns.datadictionary.MaintainableFieldDefinition;
24  import org.kuali.rice.kns.service.DataDictionaryService;
25  import org.kuali.rice.kns.util.FieldUtils;
26  import org.kuali.rice.kns.web.ui.Field;
27  import org.kuali.rice.kns.web.ui.FieldBridge;
28  
29  /**
30   * Data dictionary meta data that represents a debit/credit amount field.  By default, it expects the new line debit amount property on the form
31   * to be called "newSourceLineDebit", the debit amount on a new line to be called "newSourceLineCredit", and for the
32   * form to have a collection VoucherAccountingLineHelper implementation objects called "voucherLineHelpers", though
33   * these can be overridden.
34   */
35  public class AccountingLineViewDebitCreditAmountFieldDefinition extends MaintainableFieldDefinition implements AccountingLineViewRenderableElementDefinition {
36      private String newLineDebitAmountProperty = "newSourceLineDebit";
37      private String newLineCreditAmountProperty = "newSourceLineCredit";
38      private String voucherLineHelperProperty = "voucherLineHelper";
39      private boolean useShortLabels = true;
40      private String amountFieldName = "amount";
41      
42      /**
43       * @see org.kuali.ole.sys.document.datadictionary.AccountingLineViewRenderableElementDefinition#createLayoutElement(java.lang.Class)
44       */
45      public TableJoining createLayoutElement(Class<? extends AccountingLine> accountingLineClass) {
46          AccountingLineViewDebitCreditAmountLayoutElement layoutElement = new AccountingLineViewDebitCreditAmountLayoutElement();
47          
48          layoutElement.setDebitAmountField(createFieldForPropertyName(amountFieldName, accountingLineClass));
49          layoutElement.setDebitFieldDefinition(createFieldDefinitionForProperty(amountFieldName));
50          
51          layoutElement.setCreditAmountField(createFieldForPropertyName(amountFieldName, accountingLineClass));
52          layoutElement.setCreditFieldDefinition(createFieldDefinitionForProperty(amountFieldName));
53          
54          layoutElement.setDefinition(this);
55          
56          return layoutElement;
57      }
58      
59      /**
60       * Creates a field for the given AccountingLine class and property name
61       * @param propertyName the name of the property to create a Field for
62       * @param accountingLineClass the Class of the AccountingLine we're planning on rendering
63       * @return an appropriately created Field
64       */
65      protected Field createFieldForPropertyName(String propertyName, Class<? extends AccountingLine> accountingLineClass) {
66          Field realField = FieldUtils.getPropertyField(accountingLineClass, propertyName, false);
67          FieldBridge.setupField(realField, this, null);
68          if (useShortLabels) {
69              org.kuali.rice.krad.datadictionary.BusinessObjectEntry boEntry = SpringContext.getBean(DataDictionaryService.class).getDataDictionary().getBusinessObjectEntry(accountingLineClass.getName());
70              realField.setFieldLabel(boEntry.getAttributeDefinition(propertyName).getShortLabel());
71          }
72          return realField;
73      }
74      
75      /**
76       * Creates an AccountingLineViewFieldDefinition for the given property name
77       * @param propertyName the name of the field property that we're creating a definition for
78       * @return an appropriately created AccountingLineViewFieldDefinition
79       */
80      protected AccountingLineViewFieldDefinition createFieldDefinitionForProperty(String propertyName) {
81          AccountingLineViewFieldDefinition fieldDefinition = SpringContext.getBean(AccountingLineRenderingService.class).createGenericAccountingLineViewFieldDefinition(this);
82          fieldDefinition.setName(propertyName);
83          return fieldDefinition;
84      }
85  
86      /**
87       * Gets the newLineCreditAmountProperty attribute. 
88       * @return Returns the newLineCreditAmountProperty.
89       */
90      public String getNewLineCreditAmountProperty() {
91          return newLineCreditAmountProperty;
92      }
93  
94      /**
95       * Sets the newLineCreditAmountProperty attribute value.
96       * @param newLineCreditAmountProperty The newLineCreditAmountProperty to set.
97       */
98      public void setNewLineCreditAmountProperty(String newLineCreditAmountProperty) {
99          this.newLineCreditAmountProperty = newLineCreditAmountProperty;
100     }
101 
102     /**
103      * Gets the newLineDebitAmountProperty attribute. 
104      * @return Returns the newLineDebitAmountProperty.
105      */
106     public String getNewLineDebitAmountProperty() {
107         return newLineDebitAmountProperty;
108     }
109 
110     /**
111      * Sets the newLineDebitAmountProperty attribute value.
112      * @param newLineDebitAmountProperty The newLineDebitAmountProperty to set.
113      */
114     public void setNewLineDebitAmountProperty(String newLineDebitAmountProperty) {
115         this.newLineDebitAmountProperty = newLineDebitAmountProperty;
116     }
117 
118     /**
119      * Gets the voucherLineHelpersProperty attribute. 
120      * @return Returns the voucherLineHelpersProperty.
121      */
122     public String getVoucherLineHelperProperty() {
123         return voucherLineHelperProperty;
124     }
125 
126     /**
127      * Sets the voucherLineHelpersProperty attribute value.
128      * @param voucherLineHelpersProperty The voucherLineHelpersProperty to set.
129      */
130     public void setVoucherLineHelperProperty(String voucherLineHelpersProperty) {
131         this.voucherLineHelperProperty = voucherLineHelpersProperty;
132     }
133 
134     /**
135      * Gets the useShortLabels attribute. 
136      * @return Returns the useShortLabels.
137      */
138     public boolean shouldUseShortLabels() {
139         return useShortLabels;
140     }
141 
142     /**
143      * Sets the useShortLabels attribute value.
144      * @param useShortLabels The useShortLabels to set.
145      */
146     public void setUseShortLabels(boolean useShortLabels) {
147         this.useShortLabels = useShortLabels;
148     }
149 
150     /**
151      * Gets the amountFieldName attribute. 
152      * @return Returns the amountFieldName.
153      */
154     public String getAmountFieldName() {
155         return amountFieldName;
156     }
157 
158     /**
159      * Sets the amountFieldName attribute value.
160      * @param amountFieldName The amountFieldName to set.
161      */
162     public void setAmountFieldName(String amountFieldName) {
163         this.amountFieldName = amountFieldName;
164     }
165     
166 }