1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.extremecomponents.table.bean;
17
18 import java.util.List;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.extremecomponents.table.ColumnAttributes;
24 import org.extremecomponents.table.model.TableModel;
25 import org.extremecomponents.table.model.TableProperties;
26 import org.extremecomponents.util.ExtremeUtils;
27
28
29
30 /***
31 * An exact copy of the column tag. The Model will only reference this copy.
32 *
33 * @author Jeff Johnston
34 */
35 public class Column implements ColumnAttributes
36 {
37 private static Log logger = LogFactory.getLog(Column.class);
38 public final static String DATE = "date";
39 public final static String CURRENCY = "currency";
40 public final static String NUMBER = "number";
41 private TableModel model;
42 private String property;
43 private Object value;
44 private String title;
45 private String styleClass;
46 private String headerClass;
47 private String cell;
48 private String format;
49 private String parse;
50 private String filter;
51 private String sort;
52 private List filterDroplist;
53 private String width;
54 private String group;
55 private String style;
56 private String export;
57
58 public Column(TableModel model)
59 {
60 this.model = model;
61 }
62
63 public String getProperty()
64 {
65 return property;
66 }
67
68 public void setProperty(String property)
69 {
70 this.property = property;
71 }
72
73 public Object getValue()
74 {
75 return value;
76 }
77
78 public void setValue(Object value)
79 {
80 this.value = value;
81 }
82
83 public String getTitle()
84 {
85 if (StringUtils.isEmpty(title))
86 {
87 return ExtremeUtils.camelCaseToWord(property);
88 }
89
90 return title;
91 }
92
93 public void setTitle(String title)
94 {
95 this.title = title;
96 }
97
98 public String getStyleClass()
99 {
100 return styleClass;
101 }
102
103 public void setStyleClass(String styleClass)
104 {
105 this.styleClass = styleClass;
106 }
107
108 public String getHeaderClass()
109 {
110 if (StringUtils.isEmpty(headerClass))
111 {
112 headerClass = model.getTable().getHeaderClass();
113 }
114
115 return headerClass;
116 }
117
118 public void setHeaderClass(String headerClass)
119 {
120 this.headerClass = headerClass;
121 }
122
123 public String getCell()
124 {
125 if (StringUtils.isBlank(cell))
126 {
127 cell = model.getProperties().getProperty(TableProperties.CELL);
128 }
129
130 return cell;
131 }
132
133 public void setCell(String cell)
134 {
135 this.cell = cell;
136 }
137
138 public String getFormat()
139 {
140 if (StringUtils.isNotBlank(format))
141 {
142 String namedFormat = model.getProperties().getProperty(TableProperties.FORMAT + format);
143 if (StringUtils.isNotBlank(namedFormat))
144 {
145 format = namedFormat;
146 }
147
148 return format;
149 }
150
151 if (getCell().equals(CURRENCY))
152 {
153 format = model.getProperties().getProperty(TableProperties.FORMAT + CURRENCY);
154 }
155 else if (getCell().equals(DATE))
156 {
157 format = model.getProperties().getProperty(TableProperties.FORMAT + DATE);
158 }
159
160 return format;
161 }
162
163 public void setFormat(String format)
164 {
165 this.format = format;
166 }
167
168 public String getParse()
169 {
170 if (StringUtils.isNotBlank(parse))
171 {
172 return parse;
173 }
174
175 if (getCell().equals(DATE))
176 {
177 parse = model.getProperties().getProperty(TableProperties.PARSE + DATE);
178 }
179
180 return parse;
181 }
182
183 public void setParse(String parse)
184 {
185 this.parse = parse;
186 }
187
188 public String getFilter()
189 {
190 if (StringUtils.isEmpty(filter))
191 {
192 filter = model.getTable().getFilter();
193 }
194
195 return filter;
196 }
197
198 public void setFilter(String filter)
199 {
200 this.filter = filter;
201 }
202
203 public String getSort()
204 {
205 if (StringUtils.isEmpty(sort))
206 {
207 sort = model.getTable().getSort();
208 }
209
210 return sort;
211 }
212
213 public void setSort(String sort)
214 {
215 this.sort = sort;
216 }
217
218 public boolean canSort()
219 {
220 return getSort().equals("true");
221 }
222
223 public String getWidth()
224 {
225 return width;
226 }
227
228 public void setWidth(String width)
229 {
230 this.width = width;
231 }
232
233 public String getGroup()
234 {
235 return group;
236 }
237
238 public void setGroup(String group)
239 {
240 this.group = group;
241 }
242
243 public boolean canGroup()
244 {
245 if (StringUtils.isNotBlank(group) && group.equalsIgnoreCase("true"))
246 {
247 return true;
248 }
249
250 return false;
251 }
252
253 public String getStyle()
254 {
255 return style;
256 }
257
258 public void setStyle(String style)
259 {
260 this.style = style;
261 }
262
263 public String getExport()
264 {
265 if (StringUtils.isBlank(export))
266 {
267 export = model.getProperties().getProperty(TableProperties.EXPORT);
268 }
269
270 return export;
271 }
272
273 public void setExport(String export)
274 {
275 this.export = export;
276 }
277
278 public boolean canExport()
279 {
280 return getExport().equals("true");
281 }
282
283 public List getFilterDroplist()
284 {
285 return filterDroplist;
286 }
287
288 public void setFilterDroplist(List list)
289 {
290 filterDroplist = list;
291 }
292
293 public boolean isDate()
294 {
295 if (StringUtils.isNotEmpty(getCell()) && getCell().equals(DATE))
296 {
297 return true;
298 }
299
300 return false;
301 }
302
303 public boolean isNumber()
304 {
305 String type = getCell();
306
307 if (StringUtils.isNotBlank(type) &&
308 (type.equalsIgnoreCase(CURRENCY) ||
309 type.equalsIgnoreCase(NUMBER)))
310 {
311 return true;
312 }
313
314 return false;
315 }
316 }