KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > icefaces > samples > showcase > components > expandableTable > SalesRecordsManager


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33
34 package com.icesoft.icefaces.samples.showcase.components.expandableTable;
35
36 import com.icesoft.icefaces.samples.showcase.util.StyleBean;
37
38 import javax.faces.application.Application;
39 import javax.faces.context.FacesContext;
40 import java.util.ArrayList JavaDoc;
41 import java.util.GregorianCalendar JavaDoc;
42
43 /**
44  * <p>The <code>SalesRecordsManager</code> class is responsible for constructing
45  * the list of <code>SalesGroupRecordBean</code> beans which will be bound to a
46  * ice:dataTable JSF component. This construction process is currently static
47  * but could easily be configured to work with Hibernate or DAO implementation.
48  * </p>
49  * <p/>
50  * <p>Large data sets could be handle by adding a ice:dataPaginator.
51  * Alternatively the dataTable could also be hidden and the dataTable could be
52  * added to scrollable ice:panelGroup. </p>
53  * <p/>
54  * <p>All default style allocation can be changed in this class. The
55  * application /lib/sytle.css file can be edited to change the style properties
56  * of the table.</p>
57  */

58 public class SalesRecordsManager {
59
60     private ArrayList JavaDoc inventoryGroupItemBeans;
61
62     private boolean isInit;
63
64     // css style related constants
65
public static final String JavaDoc GROUP_INDENT_STYLE_CLASS = "groupRowIndentStyle";
66     public static final String JavaDoc GROUP_ROW_STYLE_CLASS = "groupRowStyle";
67     public static final String JavaDoc CHILD_INDENT_STYLE_CLASS = "childRowIndentStyle";
68     public static final String JavaDoc CHILD_ROW_STYLE_CLASS = "childRowStyle";
69     // toggle for expand contract
70
public static final String JavaDoc CONTRACT_IMAGE = "tree_nav_top_close_no_siblings.gif";
71     public static final String JavaDoc EXPAND_IMAGE = "tree_nav_top_open_no_siblings.gif";
72
73     public SalesRecordsManager() {
74         init();
75     }
76
77     private void init() {
78
79         // check if manager has been initiated
80
if (isInit) {
81             return;
82         }
83         isInit = true;
84
85         // initiate the list
86
if (inventoryGroupItemBeans != null) {
87             inventoryGroupItemBeans.clear();
88         } else {
89             inventoryGroupItemBeans = new ArrayList JavaDoc(10);
90         }
91         
92         Application application =
93                 FacesContext.getCurrentInstance().getApplication();
94         StyleBean styleBean =
95                 ((StyleBean) application.createValueBinding("#{styleBean}").
96                         getValue(FacesContext.getCurrentInstance()));
97
98         /**
99          * Build the array list group items. Currently static but could be easily
100          * bound to a database.
101          */

102
103         // Tuesday's group
104
SalesGroupRecordBean salesRecordGroup =
105                 new SalesGroupRecordBean(GROUP_INDENT_STYLE_CLASS,
106                                          GROUP_ROW_STYLE_CLASS,
107                                          styleBean,
108                                          EXPAND_IMAGE, CONTRACT_IMAGE,
109                                          inventoryGroupItemBeans, false);
110         salesRecordGroup.setDescription("Tuesday's Items");
111         salesRecordGroup.setDate(new GregorianCalendar JavaDoc(2006, 5, 2));
112
113         // add Tuesday's children
114
SalesGroupRecordBean childSalesGroup =
115                 new SalesGroupRecordBean(CHILD_INDENT_STYLE_CLASS,
116                                          CHILD_ROW_STYLE_CLASS);
117         childSalesGroup.setDescription("2mm Torx screws");
118         childSalesGroup.setDate(new GregorianCalendar JavaDoc(2006, 6, 3));
119         childSalesGroup.setQuantity(6);
120         childSalesGroup.setPrice(0.25);
121         salesRecordGroup.addChildSalesGroupRecord(childSalesGroup);
122         childSalesGroup =
123                 new SalesGroupRecordBean(CHILD_INDENT_STYLE_CLASS,
124                                          CHILD_ROW_STYLE_CLASS);
125         childSalesGroup.setDescription("5mm Torx screws");
126         childSalesGroup.setDate(new GregorianCalendar JavaDoc(2006, 7, 2));
127         childSalesGroup.setQuantity(6);
128         childSalesGroup.setPrice(0.25);
129         salesRecordGroup.addChildSalesGroupRecord(childSalesGroup);
130
131         // Wednesday's group
132
salesRecordGroup =
133                 new SalesGroupRecordBean(GROUP_INDENT_STYLE_CLASS,
134                                          GROUP_ROW_STYLE_CLASS,
135                                          styleBean,
136                                          EXPAND_IMAGE, CONTRACT_IMAGE,
137                                          inventoryGroupItemBeans, true);
138         salesRecordGroup.setDescription("Wednesday's Items");
139         salesRecordGroup.setDate(new GregorianCalendar JavaDoc(2006, 6, 2));
140
141         // add Wednesday's children
142
childSalesGroup =
143                 new SalesGroupRecordBean(CHILD_INDENT_STYLE_CLASS,
144                                          CHILD_ROW_STYLE_CLASS);
145         childSalesGroup.setDescription("Steel Hammer");
146         childSalesGroup.setDate(new GregorianCalendar JavaDoc(2006, 6, 6));
147         childSalesGroup.setQuantity(1);
148         childSalesGroup.setPrice(35.0);
149         salesRecordGroup.addChildSalesGroupRecord(childSalesGroup);
150         childSalesGroup =
151                 new SalesGroupRecordBean(CHILD_INDENT_STYLE_CLASS,
152                                          CHILD_ROW_STYLE_CLASS);
153         childSalesGroup.setDescription("Bag of 10# nails");
154         childSalesGroup.setDate(new GregorianCalendar JavaDoc(2006, 6, 6));
155         childSalesGroup.setQuantity(2);
156         childSalesGroup.setPrice(15.0);
157         salesRecordGroup.addChildSalesGroupRecord(childSalesGroup);
158         childSalesGroup =
159                 new SalesGroupRecordBean(CHILD_INDENT_STYLE_CLASS,
160                                          CHILD_ROW_STYLE_CLASS);
161         childSalesGroup.setDescription("Bag of 15# nails");
162         childSalesGroup.setDate(new GregorianCalendar JavaDoc(2006, 6, 6));
163         childSalesGroup.setQuantity(5);
164         childSalesGroup.setPrice(15.0);
165         salesRecordGroup.addChildSalesGroupRecord(childSalesGroup);
166
167         // Thursday's group
168
salesRecordGroup =
169                 new SalesGroupRecordBean(GROUP_INDENT_STYLE_CLASS,
170                                          GROUP_ROW_STYLE_CLASS,
171                                          styleBean,
172                                          EXPAND_IMAGE, CONTRACT_IMAGE,
173                                          inventoryGroupItemBeans, false);
174         salesRecordGroup.setDescription("Thursday's Items");
175         salesRecordGroup.setDate(new GregorianCalendar JavaDoc(2006, 7, 2));
176
177         // add Thursday's children
178
childSalesGroup =
179                 new SalesGroupRecordBean(CHILD_INDENT_STYLE_CLASS,
180                                          CHILD_ROW_STYLE_CLASS);
181         childSalesGroup.setDescription("B&D Table Saw");
182         childSalesGroup.setDate(new GregorianCalendar JavaDoc(2006, 6, 15));
183         childSalesGroup.setQuantity(1);
184         childSalesGroup.setPrice(310.0);
185         salesRecordGroup.addChildSalesGroupRecord(childSalesGroup);
186
187     }
188
189     /**
190      * Cleans up the resources used by this class. This method could be called
191      * when a session destroyed event is called.
192      */

193     public void dispose() {
194         isInit = false;
195         // clean up the array list
196
if (inventoryGroupItemBeans != null) {
197             SalesGroupRecordBean tmp;
198             ArrayList JavaDoc tmpList;
199             for (int i = 0; i < inventoryGroupItemBeans.size(); i++) {
200                 tmp = (SalesGroupRecordBean) inventoryGroupItemBeans.get(i);
201                 tmpList = tmp.getChildSalesRecords();
202                 if (tmpList != null) {
203                     tmpList.clear();
204                 }
205             }
206             inventoryGroupItemBeans.clear();
207         }
208     }
209
210     /**
211      * Gets the list of SalesGroupRecordBean which will be used by the
212      * ice:dataTable component.
213      *
214      * @return array list of parent SalesGroupRecordBeans
215      */

216     public ArrayList JavaDoc getSalesGroupRecordBeans() {
217         return inventoryGroupItemBeans;
218     }
219 }
Popular Tags