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