1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
package org.apache.tapestry.contrib.table.model.common; |
16 |
|
|
17 |
|
import org.apache.tapestry.IComponent; |
18 |
|
import org.apache.tapestry.IRender; |
19 |
|
import org.apache.tapestry.IRequestCycle; |
20 |
|
import org.apache.tapestry.components.Block; |
21 |
|
import org.apache.tapestry.contrib.table.model.IAdvancedTableColumn; |
22 |
|
import org.apache.tapestry.contrib.table.model.ITableModelSource; |
23 |
|
import org.apache.tapestry.contrib.table.model.ITableRendererSource; |
24 |
|
import org.apache.tapestry.valid.RenderString; |
25 |
|
|
26 |
|
import java.io.Serializable; |
27 |
|
import java.util.Comparator; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
public class AbstractTableColumn implements IAdvancedTableColumn, Serializable |
39 |
|
{ |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
public static final String COLUMN_RENDERER_BLOCK_SUFFIX = "ColumnHeader"; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
public static final String VALUE_RENDERER_BLOCK_SUFFIX = "ColumnValue"; |
51 |
|
|
52 |
|
private static final long serialVersionUID = 1L; |
53 |
|
|
54 |
|
private String m_strColumnName; |
55 |
|
private boolean m_bSortable; |
56 |
|
private Comparator m_objComparator; |
57 |
|
|
58 |
|
private ITableRendererSource m_objColumnRendererSource; |
59 |
|
private ITableRendererSource m_objValueRendererSource; |
60 |
|
|
61 |
|
public AbstractTableColumn() |
62 |
|
{ |
63 |
0 |
this("", false, null); |
64 |
0 |
} |
65 |
|
|
66 |
|
public AbstractTableColumn(String strColumnName, boolean bSortable, |
67 |
|
Comparator objComparator) |
68 |
|
{ |
69 |
1 |
this(strColumnName, bSortable, objComparator, null, null); |
70 |
1 |
} |
71 |
|
|
72 |
|
public AbstractTableColumn(String strColumnName, boolean bSortable, |
73 |
|
Comparator objComparator, |
74 |
|
ITableRendererSource objColumnRendererSource, |
75 |
|
ITableRendererSource objValueRendererSource) |
76 |
1 |
{ |
77 |
1 |
setColumnName(strColumnName); |
78 |
1 |
setSortable(bSortable); |
79 |
1 |
setComparator(objComparator); |
80 |
1 |
setColumnRendererSource(objColumnRendererSource); |
81 |
1 |
setValueRendererSource(objValueRendererSource); |
82 |
1 |
} |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
public String getColumnName() |
88 |
|
{ |
89 |
2 |
return m_strColumnName; |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
public void setColumnName(String columnName) |
99 |
|
{ |
100 |
1 |
m_strColumnName = columnName; |
101 |
1 |
} |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
public boolean getSortable() |
107 |
|
{ |
108 |
0 |
return m_bSortable; |
109 |
|
} |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
public void setSortable(boolean sortable) |
118 |
|
{ |
119 |
1 |
m_bSortable = sortable; |
120 |
1 |
} |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
public Comparator getComparator() |
126 |
|
{ |
127 |
0 |
return m_objComparator; |
128 |
|
} |
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
public void setComparator(Comparator comparator) |
137 |
|
{ |
138 |
2 |
m_objComparator = comparator; |
139 |
2 |
} |
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
public IRender getColumnRenderer(IRequestCycle objCycle, |
146 |
|
ITableModelSource objSource) |
147 |
|
{ |
148 |
0 |
ITableRendererSource objRendererSource = getColumnRendererSource(); |
149 |
|
|
150 |
0 |
if (objRendererSource == null) |
151 |
|
{ |
152 |
|
|
153 |
0 |
return new RenderString(""); |
154 |
|
} |
155 |
|
|
156 |
0 |
return objRendererSource.getRenderer(objCycle, objSource, this, null); |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
public IRender getValueRenderer(IRequestCycle objCycle, |
164 |
|
ITableModelSource objSource, Object objRow) |
165 |
|
{ |
166 |
0 |
ITableRendererSource objRendererSource = getValueRendererSource(); |
167 |
|
|
168 |
0 |
if (objRendererSource == null) |
169 |
|
{ |
170 |
|
|
171 |
0 |
return new RenderString(""); |
172 |
|
} |
173 |
|
|
174 |
0 |
return objRendererSource.getRenderer(objCycle, objSource, this, objRow); |
175 |
|
} |
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
public ITableRendererSource getColumnRendererSource() |
183 |
|
{ |
184 |
0 |
return m_objColumnRendererSource; |
185 |
|
} |
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
public void setColumnRendererSource(ITableRendererSource columnRendererSource) |
194 |
|
{ |
195 |
2 |
m_objColumnRendererSource = columnRendererSource; |
196 |
2 |
} |
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
public ITableRendererSource getValueRendererSource() |
204 |
|
{ |
205 |
3 |
return m_objValueRendererSource; |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
public void setValueRendererSource(ITableRendererSource valueRendererSource) |
215 |
|
{ |
216 |
3 |
m_objValueRendererSource = valueRendererSource; |
217 |
3 |
} |
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
public void loadSettings(IComponent container) |
228 |
|
{ |
229 |
1 |
String columnName = getColumnName(); |
230 |
|
|
231 |
1 |
IComponent objColumnRendererSource = |
232 |
|
(IComponent) container.getComponents().get(columnName + COLUMN_RENDERER_BLOCK_SUFFIX); |
233 |
|
|
234 |
1 |
if (objColumnRendererSource == null && columnName.indexOf(".") > -1) |
235 |
|
{ |
236 |
1 |
columnName = columnName.replace('.', '_'); |
237 |
|
|
238 |
1 |
objColumnRendererSource = |
239 |
|
(IComponent) container.getComponents().get(columnName + COLUMN_RENDERER_BLOCK_SUFFIX); |
240 |
|
} |
241 |
|
|
242 |
1 |
if (objColumnRendererSource == null) |
243 |
|
{ |
244 |
1 |
objColumnRendererSource = (IComponent) container.getComponents().get(COLUMN_RENDERER_BLOCK_SUFFIX); |
245 |
|
} |
246 |
|
|
247 |
1 |
if (objColumnRendererSource != null && objColumnRendererSource instanceof Block) |
248 |
|
{ |
249 |
0 |
setColumnRendererSource(new BlockTableRendererSource((Block) objColumnRendererSource)); |
250 |
|
} |
251 |
|
|
252 |
1 |
IComponent objValueRendererSource = |
253 |
|
(IComponent) container.getComponents().get(columnName + VALUE_RENDERER_BLOCK_SUFFIX); |
254 |
|
|
255 |
1 |
if (objValueRendererSource == null && columnName.indexOf(".") > -1) |
256 |
|
{ |
257 |
0 |
columnName = columnName.replace('.', '_'); |
258 |
|
|
259 |
0 |
objValueRendererSource = |
260 |
|
(IComponent) container.getComponents().get(columnName + VALUE_RENDERER_BLOCK_SUFFIX); |
261 |
|
} |
262 |
|
|
263 |
1 |
if (objValueRendererSource == null) |
264 |
|
{ |
265 |
0 |
objValueRendererSource = (IComponent) container.getComponents().get(VALUE_RENDERER_BLOCK_SUFFIX); |
266 |
|
} |
267 |
|
|
268 |
1 |
if (objValueRendererSource != null && objValueRendererSource instanceof Block) |
269 |
|
{ |
270 |
1 |
setValueRendererSource(new BlockTableRendererSource((Block) objValueRendererSource)); |
271 |
|
} |
272 |
1 |
} |
273 |
|
|
274 |
|
} |