1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.extremecomponents.table.bean;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.extremecomponents.table.TableAttributes;
22 import org.extremecomponents.table.model.TableModel;
23 import org.extremecomponents.table.model.TableProperties;
24
25
26
27 /***
28 * An exact copy of the table tag. The Model will only reference this copy.
29 *
30 * @author Jeff Johnston
31 */
32 public class Table implements TableAttributes
33 {
34 private static Log logger = LogFactory.getLog(Table.class);
35 public final static String EXTREME_TABLE = "eXtremeTable_";
36 private TableModel model;
37 private String id;
38 private String collection;
39 private String scope;
40 private String action;
41 private String styleClass;
42 private String headerClass;
43 private String border;
44 private String cellpadding;
45 private String cellspacing;
46 private String maxRows;
47 private String filter;
48 private String pagination;
49 private String imagePath;
50 private String sort;
51 private String title;
52 private String style;
53 private String width;
54
55 public Table(TableModel model)
56 {
57 this.model = model;
58 }
59
60 public String getId()
61 {
62 if (StringUtils.isEmpty(id))
63 {
64 return collection;
65 }
66
67 return id;
68 }
69
70 public void setId(String id)
71 {
72 this.id = id;
73 }
74
75 public String getCollection()
76 {
77 return collection;
78 }
79
80 public void setCollection(String collection)
81 {
82 this.collection = collection;
83 }
84
85 public String getAction()
86 {
87 return action;
88 }
89
90 public void setAction(String action)
91 {
92 this.action = action;
93 }
94
95 public String getScope()
96 {
97 return scope;
98 }
99
100 public void setScope(String scope)
101 {
102 this.scope = scope;
103 }
104
105 public String getStyleClass()
106 {
107 if (StringUtils.isEmpty(styleClass))
108 {
109 styleClass = model.getProperties().getProperty(TableProperties.STYLE_CLASS);
110 }
111
112 return styleClass;
113 }
114
115 public void setStyleClass(String styleClass)
116 {
117 this.styleClass = styleClass;
118 }
119
120 public String getHeaderClass()
121 {
122 if (StringUtils.isEmpty(headerClass))
123 {
124 headerClass = model.getProperties().getProperty(TableProperties.HEADER_CLASS);
125 }
126
127 return headerClass;
128 }
129
130 public void setHeaderClass(String headerClass)
131 {
132 this.headerClass = headerClass;
133 }
134
135 public String getBorder()
136 {
137 if (StringUtils.isEmpty(border))
138 {
139 border = model.getProperties().getProperty(TableProperties.BORDER);
140 }
141
142 return border;
143 }
144
145 public void setBorder(String border)
146 {
147 this.border = border;
148 }
149
150 public String getCellpadding()
151 {
152 if (StringUtils.isEmpty(cellpadding))
153 {
154 cellpadding = model.getProperties().getProperty(TableProperties.CELLPADDING);
155 }
156
157 return cellpadding;
158 }
159
160 public void setCellpadding(String cellpadding)
161 {
162 this.cellpadding = cellpadding;
163 }
164
165 public String getCellspacing()
166 {
167 if (StringUtils.isEmpty(cellspacing))
168 {
169 cellspacing = model.getProperties().getProperty(TableProperties.CELLSPACING);
170 }
171
172 return cellspacing;
173 }
174
175 public void setCellspacing(String cellspacing)
176 {
177 this.cellspacing = cellspacing;
178 }
179
180 public String getMaxRows()
181 {
182 boolean invokeExport = model.getExportHandler().invokeExport();
183 if (invokeExport)
184 {
185 maxRows = "0";
186 }
187 else if (StringUtils.isEmpty(maxRows))
188 {
189 maxRows = model.getProperties().getProperty(TableProperties.MAX_ROWS);
190 }
191
192 return maxRows;
193 }
194
195 public void setMaxRows(String maxRows)
196 {
197 this.maxRows = maxRows;
198 }
199
200 public String getFilter()
201 {
202 if (StringUtils.isEmpty(filter))
203 {
204 filter = model.getProperties().getProperty(TableProperties.FILTER);
205 }
206
207 return filter;
208 }
209
210 public boolean doFilter()
211 {
212 return getFilter().equals("true");
213 }
214
215 public void setFilter(String filter)
216 {
217 this.filter = filter;
218 }
219
220 public String getPagination()
221 {
222 if (StringUtils.isEmpty(pagination))
223 {
224 pagination = model.getProperties().getProperty(TableProperties.PAGINATION);
225 }
226
227 return pagination;
228 }
229
230 public boolean doPagination()
231 {
232 return getPagination().equals("true");
233 }
234
235 public void setPagination(String pagination)
236 {
237 this.pagination = pagination;
238 }
239
240 public String getImagePath()
241 {
242 if (StringUtils.isBlank(imagePath))
243 {
244 imagePath = model.getProperties().getProperty(TableProperties.IMAGE_PATH);
245 }
246
247 return imagePath;
248 }
249
250 public void setImagePath(String imagePath)
251 {
252 this.imagePath = imagePath;
253 }
254
255 public String getImage(String name)
256 {
257 getImagePath();
258
259 if (StringUtils.isNotBlank(imagePath))
260 {
261 int index = imagePath.indexOf("*.");
262 return imagePath.substring(0, index) + name + imagePath.substring(index+1);
263 }
264
265 return null;
266 }
267
268 public String getSort()
269 {
270 if (StringUtils.isEmpty(sort))
271 {
272 sort = model.getProperties().getProperty(TableProperties.SORT);
273 }
274
275 return sort;
276 }
277
278 public boolean canSort()
279 {
280 return getSort().equals("true");
281 }
282
283 public void setSort(String sort)
284 {
285 this.sort = sort;
286 }
287
288 public String getTitle()
289 {
290 return title;
291 }
292
293 public void setTitle(String title)
294 {
295 this.title = title;
296 }
297
298 public String getStyle()
299 {
300 return style;
301 }
302
303 public void setStyle(String style)
304 {
305 this.style = style;
306 }
307
308 public String getWidth()
309 {
310 if (StringUtils.isEmpty(width))
311 {
312 width = model.getProperties().getProperty(TableProperties.WIDTH);
313 }
314
315 return width;
316 }
317
318 public void setWidth(String width)
319 {
320 this.width = width;
321 }
322 }