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