View Javadoc

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