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 |
0 |
this(strColumnName, bSortable, objComparator, null, null); |
70 |
0 |
} |
71 |
|
|
72 |
|
public AbstractTableColumn(String strColumnName, boolean bSortable, |
73 |
|
Comparator objComparator, |
74 |
|
ITableRendererSource objColumnRendererSource, |
75 |
|
ITableRendererSource objValueRendererSource) |
76 |
0 |
{ |
77 |
0 |
setColumnName(strColumnName); |
78 |
0 |
setSortable(bSortable); |
79 |
0 |
setComparator(objComparator); |
80 |
0 |
setColumnRendererSource(objColumnRendererSource); |
81 |
0 |
setValueRendererSource(objValueRendererSource); |
82 |
0 |
} |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
public String getColumnName() |
88 |
|
{ |
89 |
0 |
return m_strColumnName; |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
public void setColumnName(String columnName) |
99 |
|
{ |
100 |
0 |
if (columnName != null) |
101 |
0 |
columnName = columnName.replace('.', '_'); |
102 |
|
|
103 |
0 |
m_strColumnName = columnName; |
104 |
0 |
} |
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
public boolean getSortable() |
110 |
|
{ |
111 |
0 |
return m_bSortable; |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
public void setSortable(boolean sortable) |
121 |
|
{ |
122 |
0 |
m_bSortable = sortable; |
123 |
0 |
} |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
public Comparator getComparator() |
129 |
|
{ |
130 |
0 |
return m_objComparator; |
131 |
|
} |
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
public void setComparator(Comparator comparator) |
140 |
|
{ |
141 |
0 |
m_objComparator = comparator; |
142 |
0 |
} |
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
public IRender getColumnRenderer(IRequestCycle objCycle, |
149 |
|
ITableModelSource objSource) |
150 |
|
{ |
151 |
0 |
ITableRendererSource objRendererSource = getColumnRendererSource(); |
152 |
|
|
153 |
0 |
if (objRendererSource == null) |
154 |
|
{ |
155 |
|
|
156 |
0 |
return new RenderString(""); |
157 |
|
} |
158 |
|
|
159 |
0 |
return objRendererSource.getRenderer(objCycle, objSource, this, null); |
160 |
|
} |
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
public IRender getValueRenderer(IRequestCycle objCycle, |
167 |
|
ITableModelSource objSource, Object objRow) |
168 |
|
{ |
169 |
0 |
ITableRendererSource objRendererSource = getValueRendererSource(); |
170 |
|
|
171 |
0 |
if (objRendererSource == null) |
172 |
|
{ |
173 |
|
|
174 |
0 |
return new RenderString(""); |
175 |
|
} |
176 |
|
|
177 |
0 |
return objRendererSource.getRenderer(objCycle, objSource, this, objRow); |
178 |
|
} |
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
public ITableRendererSource getColumnRendererSource() |
186 |
|
{ |
187 |
0 |
return m_objColumnRendererSource; |
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
public void setColumnRendererSource( |
197 |
|
ITableRendererSource columnRendererSource) |
198 |
|
{ |
199 |
0 |
m_objColumnRendererSource = columnRendererSource; |
200 |
0 |
} |
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
public ITableRendererSource getValueRendererSource() |
208 |
|
{ |
209 |
0 |
return m_objValueRendererSource; |
210 |
|
} |
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
public void setValueRendererSource(ITableRendererSource valueRendererSource) |
219 |
|
{ |
220 |
0 |
m_objValueRendererSource = valueRendererSource; |
221 |
0 |
} |
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
public void loadSettings(IComponent container) |
232 |
|
{ |
233 |
0 |
IComponent objColumnRendererSource = |
234 |
|
(IComponent) container.getComponents().get(getColumnName() + COLUMN_RENDERER_BLOCK_SUFFIX); |
235 |
|
|
236 |
0 |
if (objColumnRendererSource == null) |
237 |
0 |
objColumnRendererSource = (IComponent) container.getComponents().get(COLUMN_RENDERER_BLOCK_SUFFIX); |
238 |
|
|
239 |
0 |
if (objColumnRendererSource != null |
240 |
|
&& objColumnRendererSource instanceof Block) |
241 |
|
{ |
242 |
0 |
setColumnRendererSource(new BlockTableRendererSource((Block) objColumnRendererSource)); |
243 |
|
} |
244 |
|
|
245 |
0 |
IComponent objValueRendererSource = |
246 |
|
(IComponent) container.getComponents().get(getColumnName() + VALUE_RENDERER_BLOCK_SUFFIX); |
247 |
|
|
248 |
0 |
if (objValueRendererSource == null) |
249 |
|
{ |
250 |
0 |
objValueRendererSource = (IComponent) container.getComponents().get(VALUE_RENDERER_BLOCK_SUFFIX); |
251 |
|
} |
252 |
|
|
253 |
0 |
if (objValueRendererSource != null |
254 |
|
&& objValueRendererSource instanceof Block) |
255 |
|
{ |
256 |
0 |
setValueRendererSource(new BlockTableRendererSource((Block) objValueRendererSource)); |
257 |
|
} |
258 |
0 |
} |
259 |
|
|
260 |
|
} |