View Javadoc
1   /**
2    * Copyright 2005-2015 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.rice.krad.uif.util;
17  
18  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
20  import org.kuali.rice.krad.datadictionary.parse.BeanTags;
21  import org.kuali.rice.krad.datadictionary.uif.UifDictionaryBeanBase;
22  import org.kuali.rice.krad.uif.field.MessageField;
23  
24  import java.io.Serializable;
25  
26  /**
27   * ColumnCalculationInfo is used to specify which columns and what types of calculations are performed on those columns
28   * of table collection.  This functionality can only be used when the dataTables plugin is being used
29   * (richTable.render="true" for TableLayoutManager)
30   *
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  @BeanTags({@BeanTag(name = "columnCalculation", parent = "Uif-ColumnCalculationInfo"),
34          @BeanTag(name = "columnCalculationSum", parent = "Uif-ColumnCalculationInfo-Sum"),
35          @BeanTag(name = "columnCalculationAverage", parent = "Uif-ColumnCalculationInfo-Average"),
36          @BeanTag(name = "columnCalculationMax", parent = "Uif-ColumnCalculationInfo-Max"),
37          @BeanTag(name = "columnCalculationMin", parent = "Uif-ColumnCalculationInfo-Min")})
38  public class ColumnCalculationInfo extends UifDictionaryBeanBase implements Serializable {
39      private static final long serialVersionUID = 148856717025808296L;
40      private Integer columnNumber;
41      private String propertyName;
42  
43      private boolean showTotal;
44      private boolean showPageTotal;
45      private boolean showGroupTotal;
46  
47      private MessageField totalField;
48      private MessageField pageTotalField;
49      private MessageField groupTotalFieldPrototype;
50  
51      private String calculationFunctionName;
52      private String calculationFunctionExtraData;
53  
54      private boolean calculateOnKeyUp;
55      private boolean recalculateTotalClientSide;
56  
57      /**
58       * Gets the column number.  This should not be set through configuration as it is overridden by the
59       * propertyName's caclculated column number.  <b>Do not set through xml configuration</b>
60       *
61       * @return columnNumber to perform calculations on
62       */
63      @BeanTagAttribute(name = "columnNumber")
64      public Integer getColumnNumber() {
65          return columnNumber;
66      }
67  
68      /**
69       * Sets the column number. <b>Do not set through xml configuration</b>
70       *
71       * @param columnNumber
72       */
73      public void setColumnNumber(Integer columnNumber) {
74          this.columnNumber = columnNumber;
75      }
76  
77      /**
78       * Gets showTotal. showTotal shows/calculates the total field when true, otherwise it is not rendered.
79       *
80       * @return true if showing the total, false otherwise.
81       */
82      @BeanTagAttribute(name = "showTotal")
83      public boolean isShowTotal() {
84          return showTotal;
85      }
86  
87      /**
88       * Sets showTotal. showTotal shows/calculates the total field when true, otherwise it is not rendered.
89       *
90       * @param showTotal
91       */
92      public void setShowTotal(boolean showTotal) {
93          this.showTotal = showTotal;
94      }
95  
96      /**
97       * Gets showTotal. showTotal shows/calculates the total field when true, otherwise it is not rendered.
98       *
99       * @return true if showing the page total, false otherwise.
100      */
101     @BeanTagAttribute(name = "showPageTotal")
102     public boolean isShowPageTotal() {
103         return showPageTotal;
104     }
105 
106     /**
107      * Sets showPageTotal. showPageTotal shows/calculates the total field for the page when true (and only
108      * when the table actually has pages), otherwise it is not rendered.
109      *
110      * @param showPageTotal
111      */
112     public void setShowPageTotal(boolean showPageTotal) {
113         this.showPageTotal = showPageTotal;
114     }
115 
116     /**
117      * Gets showGroupTotal. showGroupTotal shows/calculates the total field for each grouping when true (and only
118      * when the table actually has grouping turned on), otherwise it is not rendered.
119      *
120      * @return true if showing the group total, false otherwise.
121      */
122     @BeanTagAttribute(name = "showGroupTotal")
123     public boolean isShowGroupTotal() {
124         return showGroupTotal;
125     }
126 
127     /**
128      * Sets showGroupTotal. showGroupTotal shows/calculates the total field for each grouping when true (and only
129      * when the table actually has grouping turned on), otherwise it is not rendered.
130      *
131      * @param showGroupTotal
132      */
133     public void setShowGroupTotal(boolean showGroupTotal) {
134         this.showGroupTotal = showGroupTotal;
135     }
136 
137     /**
138      * Gets the js calculationFunctionName.  This is the name of the js function to use in column calculations.
139      *
140      * <p>
141      * <b>This must be ONLY the function by name (no parenthesis or params)</b><br/>
142      * The actual js function declaration MUST take in an array of values as its first parameter.  The values passed in
143      * will be all the relavant values for the calculation.  Optionally, the function can also take a second parameter
144      * which can be specified by calculationFunctionExtraData.  This parameter can take any valid javascript value
145      * (integer, string, JSON object, etc).  In either case, the values parameter MUST be the first parameter.
146      * </p>
147      *
148      * @return calculatinoFunctionName to call for column calculations in js
149      */
150     @BeanTagAttribute(name = "calculationFunctionName")
151     public String getCalculationFunctionName() {
152         return calculationFunctionName;
153     }
154 
155     /**
156      * Sets the calculationFunctionName to call when doing column calculations
157      *
158      * @param calculationFunctionName
159      */
160     public void setCalculationFunctionName(String calculationFunctionName) {
161         this.calculationFunctionName = calculationFunctionName;
162     }
163 
164     /**
165      * Gets the totalField.  This field is the field which holds the total for the column and specifies its label.
166      * This SHOULD NOT BE SET except by the base bean (in MOST cases).
167      *
168      * @return the totalField
169      */
170     @BeanTagAttribute(name = "totalField", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
171     public MessageField getTotalField() {
172         return totalField;
173     }
174 
175     /**
176      * Sets the totalField.  This SHOULD NOT BE SET except by the base bean (in MOST cases).  Setting this property
177      * without the appropriate settings WILL break functionality.
178      *
179      * @param totalField
180      */
181     public void setTotalField(MessageField totalField) {
182         this.totalField = totalField;
183     }
184 
185     /**
186      * Gets the pageTotalField.  This field is the field which holds the pageTotal for the column
187      * and specifies its label. This SHOULD NOT BE SET except by the base bean (in MOST cases).
188      *
189      * @return the pageTotalField
190      */
191     @BeanTagAttribute(name = "pageTotalField", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
192     public MessageField getPageTotalField() {
193         return pageTotalField;
194     }
195 
196     /**
197      * Sets the pageTotalField.  This SHOULD NOT BE SET except by the base bean (in MOST cases).  Setting this property
198      * without the appropriate settings WILL break functionality.
199      *
200      * @param pageTotalField
201      */
202     public void setPageTotalField(MessageField pageTotalField) {
203         this.pageTotalField = pageTotalField;
204     }
205 
206     /**
207      * Gets the groupTotalFieldPrototype.  This field is copied and holds the groupTotal for the column
208      * and specifies its label. This SHOULD NOT BE SET except by the base bean (in MOST cases).
209      *
210      * @return the groupTotalFieldPrototype
211      */
212     @BeanTagAttribute(name = "groupTotalFieldPrototype", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
213     public MessageField getGroupTotalFieldPrototype() {
214         return groupTotalFieldPrototype;
215     }
216 
217     /**
218      * Sets the groupTotalFieldPrototype.  This SHOULD NOT BE SET except by the base bean (in MOST cases).
219      * Setting this property without the appropriate settings WILL break functionality.
220      *
221      * @param groupTotalFieldPrototype
222      */
223     public void setGroupTotalFieldPrototype(MessageField groupTotalFieldPrototype) {
224         this.groupTotalFieldPrototype = groupTotalFieldPrototype;
225     }
226 
227     /**
228      * If true, the column is calculated when the user enters a character on each key up.  There is a small delay
229      * built in to prevent calculations from being fired for each key stroke.
230      *
231      * @return true if calculated the column on key up, false if calculating on change (default)
232      */
233     @BeanTagAttribute(name = "calculationOnKeyUp")
234     public boolean isCalculateOnKeyUp() {
235         return calculateOnKeyUp;
236     }
237 
238     /**
239      * Sets calculateOnKeyUp which controls the type of handler used
240      *
241      * @param calculateOnKeyUp
242      */
243     public void setCalculateOnKeyUp(boolean calculateOnKeyUp) {
244         this.calculateOnKeyUp = calculateOnKeyUp;
245     }
246 
247     /**
248      * When set to false, calculations will not be fired for the totalField client-side.  This ONLY effects the
249      * totalField.  If page and group totals are still shown, they will (and can only) be calculated client-side.
250      *
251      * <p>
252      * To use this particular feature: set this to false, and use springEL in the totalField's message.messageText
253      * to get a pre-calculated total from a field on the form.  This will be refreshed when the table is refreshed,
254      * but will not be updated by client-side interactions - used for complex or special calculation mechanisms
255      * that may require server only information.
256      * </p>
257      *
258      * @return true if calculating the totalField client-side, false otherwise
259      */
260     @BeanTagAttribute(name = "recalculateTotalClientSide")
261     public boolean isRecalculateTotalClientSide() {
262         return recalculateTotalClientSide;
263     }
264 
265     /**
266      * Set the recalculateTotalClientSide flag
267      *
268      * @param recalculateTotalClientSide
269      */
270     public void setRecalculateTotalClientSide(boolean recalculateTotalClientSide) {
271         this.recalculateTotalClientSide = recalculateTotalClientSide;
272     }
273 
274     /**
275      * This specifies extra data to be sent to the calculation function.  This can be any valid javascript value
276      * (number, string, JSON - for passing multiple settings, etc).
277      * <br/>
278      * <b>The function specified by calculationFunctionName MUST take a second parameter when using this option.</b>
279      *
280      * @return the extra data to pass into the function specified by name in calculationFunctionName
281      */
282     @BeanTagAttribute(name = "calculationFunctionExtraData")
283     public String getCalculationFunctionExtraData() {
284         return calculationFunctionExtraData;
285     }
286 
287     /**
288      * Sets the calculationFunctionExtraData which specifies additional data to pass into the calculationFunction.
289      *
290      * @param calculationFunctionExtraData
291      */
292     public void setCalculationFunctionExtraData(String calculationFunctionExtraData) {
293         this.calculationFunctionExtraData = calculationFunctionExtraData;
294     }
295 
296     /**
297      * Get the propertyName of the field to do calculations.  This field MUST exist as one of the fields
298      * of the collection.  <b>This property must be set or an exception will be thrown.</b>
299      *
300      * @return propertyName of the field(the column) to do calculations on
301      */
302     @BeanTagAttribute(name = "propertyName")
303     public String getPropertyName() {
304         return propertyName;
305     }
306 
307     /**
308      * Set the propertyName of the field to do calculations on
309      *
310      * @param propertyName
311      */
312     public void setPropertyName(String propertyName) {
313         this.propertyName = propertyName;
314     }
315 
316 }