1
2
3
4
5 package org.extremecomponents.tree.model;
6
7 import java.util.ArrayList;
8 import java.util.Iterator;
9 import java.util.List;
10 import java.util.Map;
11
12 import javax.servlet.jsp.PageContext;
13
14 import org.apache.commons.beanutils.BeanUtils;
15 import org.apache.commons.beanutils.PropertyUtils;
16
17 import org.apache.commons.logging.Log;
18 import org.apache.commons.logging.LogFactory;
19
20 import org.extremecomponents.table.bean.TableSection;
21
22 import org.extremecomponents.table.model.FilterHandler;
23 import org.extremecomponents.table.model.ParameterRegistry;
24 import org.extremecomponents.table.model.TableModel;
25
26 import org.extremecomponents.tree.bean.TreeNode;
27
28 import org.extremecomponents.util.ExtremeUtils;
29
30
31 /***
32 * org.extremecomponents.tree.model.TreeModel.java -
33 *
34 * @author Paul Horn
35 */
36 public class TreeModel extends TableModel
37 {
38 private static Log logger = LogFactory.getLog(TreeModel.class);
39 private String parentAttribute;
40 private String identifier;
41 private String extendedValue;
42 private TableSection tableSection;
43 private Object tableCollection;
44 private Map openNodes;
45 private TreeProperties properties = new TreeProperties();
46 private FilterHandler filterHandler = new FilterHandler(this);
47 private SortHandler sortHandler = new SortHandler(this);
48 private ViewHandler viewHandler = new ViewHandler(this);
49
50 public TreeModel(PageContext pageContext)
51 {
52 super(pageContext);
53 }
54
55 /***
56 * Do all the filtering and sorting and return the rows of the table
57 * that need to be displayed.
58 */
59 public List init() throws Exception
60 {
61 openNodes = getRegistry().getParameters(ParameterRegistry.OPEN);
62
63 setTableCollection(ExtremeUtils.retrieveFromScope(getPageContext(), getTable().getCollection(), getTable().getScope()));
64
65 List filteredSortedRows = null;
66
67 if (getFilterHandler().doFilter() && !filterHandler.doClear())
68 {
69 filteredSortedRows = getFilterHandler().filterRows(this, getTableCollection());
70 filteredSortedRows = TreeModelUtils.findParents(this, filteredSortedRows);
71 filteredSortedRows = TreeModelUtils.loadTreeStructure(this, filteredSortedRows);
72 TreeModelUtils.addClosedChildren(this, filteredSortedRows);
73 }
74 else
75 {
76 filteredSortedRows = TreeModelUtils.loadTreeStructure(this, getTableCollection());
77 }
78
79 getSortHandler().sort(filteredSortedRows);
80
81 getViewHandler().setView();
82
83 return filteredSortedRows;
84 }
85
86 /***
87 * @return tableCollection
88 */
89 public List getTableCollection()
90 {
91 return (List) tableCollection;
92 }
93
94 /***
95 * @param tableCollection
96 */
97 public void setTableCollection(Object tableCollection) throws Exception
98 {
99 if (tableCollection instanceof List)
100 {
101 this.tableCollection = tableCollection;
102 }
103 else
104 {
105 throw new Exception("The eXtremeTable could not find the List of Beans (or Map) identified by the collection and scope attributes.");
106 }
107 }
108
109 /***
110 * @return Returns the filterHandler.
111 */
112 public org.extremecomponents.table.model.FilterHandler getFilterHandler()
113 {
114 return filterHandler;
115 }
116
117 /***
118 * @param filterHandler The filterHandler to set.
119 */
120 public void setFilterHandler(FilterHandler filterHandler)
121 {
122 this.filterHandler = filterHandler;
123 }
124
125 /***
126 * @return Returns the sortHandler.
127 */
128 public org.extremecomponents.table.model.SortHandler getSortHandler()
129 {
130 return sortHandler;
131 }
132
133 /***
134 * @param sortHandler The sortHandler to set.
135 */
136 public void setSortHandler(SortHandler sortHandler)
137 {
138 this.sortHandler = sortHandler;
139 }
140
141 /***
142 * @return Returns the tableSection.
143 */
144 public TableSection getTableSection()
145 {
146 return tableSection;
147 }
148
149 /***
150 * @param tableSection The tableSection to set.
151 */
152 public void setTableSection(TableSection tableSection)
153 {
154 this.tableSection = tableSection;
155 }
156
157 /***
158 * @return Returns the viewHandler.
159 */
160 public org.extremecomponents.table.model.ViewHandler getViewHandler()
161 {
162 return viewHandler;
163 }
164
165 /***
166 * @param viewHandler The viewHandler to set.
167 */
168 public void setViewHandler(ViewHandler viewHandler)
169 {
170 this.viewHandler = viewHandler;
171 }
172
173 /***
174 * @return
175 */
176 public TreeProperties getTreeProperties()
177 {
178 return properties;
179 }
180
181 /***
182 * @return Returns the parentAttribute.
183 */
184 public String getParentAttribute()
185 {
186 return parentAttribute;
187 }
188
189 /***
190 * @param parentAttribute The parentAttribute to set.
191 */
192 public void setParentAttribute(String parentAttribute)
193 {
194 this.parentAttribute = parentAttribute;
195 }
196
197 /***
198 * @param properties The properties to set.
199 */
200 public void setProperties(TreeProperties properties)
201 {
202 this.properties = properties;
203 }
204
205 /***
206 * @return Returns the openNodes.
207 */
208 public Map getOpenNodes()
209 {
210 return openNodes;
211 }
212
213 /***
214 * @param openNodes The openNodes to set.
215 */
216 public void setOpenNodes(Map openNodes)
217 {
218 this.openNodes = openNodes;
219 }
220
221 /***
222 * @return Returns the identifier.
223 */
224 public String getIdentifier()
225 {
226 return identifier;
227 }
228
229 /***
230 * @param identifier The identifier to set.
231 */
232 public void setIdentifier(String identifier)
233 {
234 this.identifier = identifier;
235 }
236
237 /***
238 * @return
239 */
240 public String getExtendedValue()
241 {
242 return extendedValue;
243 }
244
245 /***
246 * @param string
247 */
248 public void setExtendedValue(String string)
249 {
250 extendedValue = string;
251 }
252 }