|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
AbstractTableColumn.java | 0% | 0% | 0% | 0% |
|
1 |
// Copyright 2004, 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
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.ITableColumn;
|
|
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 |
* A base implementation of {@link org.apache.tapestry.contrib.table.model.ITableColumn}
|
|
31 |
* that allows renderers to be set via aggregation.
|
|
32 |
*
|
|
33 |
* @see org.apache.tapestry.contrib.table.model.ITableRendererSource
|
|
34 |
* @author mindbridge
|
|
35 |
* @since 2.3
|
|
36 |
*/
|
|
37 |
public class AbstractTableColumn implements ITableColumn, Serializable |
|
38 |
{ |
|
39 |
/**
|
|
40 |
* The suffix of the name of the Block that will be used as the column renderer
|
|
41 |
* for this column
|
|
42 |
*/
|
|
43 |
public final static String COLUMN_RENDERER_BLOCK_SUFFIX = "ColumnHeader"; |
|
44 |
|
|
45 |
/**
|
|
46 |
* The suffix of the name of the Block that will be used as the value renderer
|
|
47 |
* for this column
|
|
48 |
*/
|
|
49 |
public final static String VALUE_RENDERER_BLOCK_SUFFIX = "ColumnValue"; |
|
50 |
|
|
51 |
private String m_strColumnName;
|
|
52 |
private boolean m_bSortable; |
|
53 |
private Comparator m_objComparator;
|
|
54 |
|
|
55 |
private ITableRendererSource m_objColumnRendererSource;
|
|
56 |
private ITableRendererSource m_objValueRendererSource;
|
|
57 |
|
|
58 | 0 |
public AbstractTableColumn()
|
59 |
{ |
|
60 | 0 |
this("", false, null); |
61 |
} |
|
62 |
|
|
63 | 0 |
public AbstractTableColumn(
|
64 |
String strColumnName, |
|
65 |
boolean bSortable,
|
|
66 |
Comparator objComparator) |
|
67 |
{ |
|
68 | 0 |
this(strColumnName, bSortable, objComparator, null, null); |
69 |
} |
|
70 |
|
|
71 | 0 |
public AbstractTableColumn(
|
72 |
String strColumnName, |
|
73 |
boolean bSortable,
|
|
74 |
Comparator objComparator, |
|
75 |
ITableRendererSource objColumnRendererSource, |
|
76 |
ITableRendererSource objValueRendererSource) |
|
77 |
{ |
|
78 | 0 |
setColumnName(strColumnName); |
79 | 0 |
setSortable(bSortable); |
80 | 0 |
setComparator(objComparator); |
81 | 0 |
setColumnRendererSource(objColumnRendererSource); |
82 | 0 |
setValueRendererSource(objValueRendererSource); |
83 |
} |
|
84 |
|
|
85 |
/**
|
|
86 |
* @see org.apache.tapestry.contrib.table.model.ITableColumn#getColumnName()
|
|
87 |
*/
|
|
88 | 0 |
public String getColumnName()
|
89 |
{ |
|
90 | 0 |
return m_strColumnName;
|
91 |
} |
|
92 |
|
|
93 |
/**
|
|
94 |
* Sets the columnName.
|
|
95 |
* @param columnName The columnName to set
|
|
96 |
*/
|
|
97 | 0 |
public void setColumnName(String columnName) |
98 |
{ |
|
99 | 0 |
m_strColumnName = columnName; |
100 |
} |
|
101 |
|
|
102 |
/**
|
|
103 |
* @see org.apache.tapestry.contrib.table.model.ITableColumn#getSortable()
|
|
104 |
*/
|
|
105 | 0 |
public boolean getSortable() |
106 |
{ |
|
107 | 0 |
return m_bSortable;
|
108 |
} |
|
109 |
|
|
110 |
/**
|
|
111 |
* Sets whether the column is sortable.
|
|
112 |
* @param sortable The sortable flag to set
|
|
113 |
*/
|
|
114 | 0 |
public void setSortable(boolean sortable) |
115 |
{ |
|
116 | 0 |
m_bSortable = sortable; |
117 |
} |
|
118 |
|
|
119 |
/**
|
|
120 |
* @see org.apache.tapestry.contrib.table.model.ITableColumn#getComparator()
|
|
121 |
*/
|
|
122 | 0 |
public Comparator getComparator()
|
123 |
{ |
|
124 | 0 |
return m_objComparator;
|
125 |
} |
|
126 |
|
|
127 |
/**
|
|
128 |
* Sets the comparator.
|
|
129 |
* @param comparator The comparator to set
|
|
130 |
*/
|
|
131 | 0 |
public void setComparator(Comparator comparator) |
132 |
{ |
|
133 | 0 |
m_objComparator = comparator; |
134 |
} |
|
135 |
|
|
136 |
/**
|
|
137 |
* @see org.apache.tapestry.contrib.table.model.ITableColumn#getColumnRenderer(IRequestCycle, ITableModelSource)
|
|
138 |
*/
|
|
139 | 0 |
public IRender getColumnRenderer(
|
140 |
IRequestCycle objCycle, |
|
141 |
ITableModelSource objSource) |
|
142 |
{ |
|
143 | 0 |
ITableRendererSource objRendererSource = |
144 |
getColumnRendererSource(); |
|
145 | 0 |
if (objRendererSource == null) |
146 |
{ |
|
147 |
// log error
|
|
148 | 0 |
return new RenderString(""); |
149 |
} |
|
150 |
|
|
151 | 0 |
return objRendererSource.getRenderer(objCycle, objSource, this, null); |
152 |
} |
|
153 |
|
|
154 |
/**
|
|
155 |
* @see org.apache.tapestry.contrib.table.model.ITableColumn#getValueRenderer(IRequestCycle, ITableModelSource, Object)
|
|
156 |
*/
|
|
157 | 0 |
public IRender getValueRenderer(
|
158 |
IRequestCycle objCycle, |
|
159 |
ITableModelSource objSource, |
|
160 |
Object objRow) |
|
161 |
{ |
|
162 | 0 |
ITableRendererSource objRendererSource = getValueRendererSource(); |
163 | 0 |
if (objRendererSource == null) |
164 |
{ |
|
165 |
// log error
|
|
166 | 0 |
return new RenderString(""); |
167 |
} |
|
168 |
|
|
169 | 0 |
return objRendererSource.getRenderer(
|
170 |
objCycle, |
|
171 |
objSource, |
|
172 |
this,
|
|
173 |
objRow); |
|
174 |
} |
|
175 |
|
|
176 |
/**
|
|
177 |
* Returns the columnRendererSource.
|
|
178 |
* @return ITableColumnRendererSource
|
|
179 |
*/
|
|
180 | 0 |
public ITableRendererSource getColumnRendererSource()
|
181 |
{ |
|
182 | 0 |
return m_objColumnRendererSource;
|
183 |
} |
|
184 |
|
|
185 |
/**
|
|
186 |
* Sets the columnRendererSource.
|
|
187 |
* @param columnRendererSource The columnRendererSource to set
|
|
188 |
*/
|
|
189 | 0 |
public void setColumnRendererSource(ITableRendererSource columnRendererSource) |
190 |
{ |
|
191 | 0 |
m_objColumnRendererSource = columnRendererSource; |
192 |
} |
|
193 |
|
|
194 |
/**
|
|
195 |
* Returns the valueRendererSource.
|
|
196 |
*
|
|
197 |
* @return the valueRendererSource of this column
|
|
198 |
*/
|
|
199 | 0 |
public ITableRendererSource getValueRendererSource()
|
200 |
{ |
|
201 | 0 |
return m_objValueRendererSource;
|
202 |
} |
|
203 |
|
|
204 |
/**
|
|
205 |
* Sets the valueRendererSource.
|
|
206 |
*
|
|
207 |
* @param valueRendererSource The valueRendererSource to set
|
|
208 |
*/
|
|
209 | 0 |
public void setValueRendererSource(ITableRendererSource valueRendererSource) |
210 |
{ |
|
211 | 0 |
m_objValueRendererSource = valueRendererSource; |
212 |
} |
|
213 |
|
|
214 |
/**
|
|
215 |
* Use the column name to get the column and value renderer sources
|
|
216 |
* from the provided component.
|
|
217 |
*
|
|
218 |
* @param objSettingsContainer the component from which to get the settings
|
|
219 |
*/
|
|
220 | 0 |
public void loadSettings(IComponent objSettingsContainer) |
221 |
{ |
|
222 | 0 |
IComponent objColumnRendererSource = (IComponent) objSettingsContainer.getComponents().get(getColumnName() + COLUMN_RENDERER_BLOCK_SUFFIX); |
223 | 0 |
if (objColumnRendererSource != null && objColumnRendererSource instanceof Block) |
224 | 0 |
setColumnRendererSource(new BlockTableRendererSource((Block) objColumnRendererSource));
|
225 |
|
|
226 | 0 |
IComponent objValueRendererSource = (IComponent) objSettingsContainer.getComponents().get(getColumnName() + VALUE_RENDERER_BLOCK_SUFFIX); |
227 | 0 |
if (objValueRendererSource != null && objValueRendererSource instanceof Block) |
228 | 0 |
setValueRendererSource(new BlockTableRendererSource((Block) objValueRendererSource));
|
229 |
} |
|
230 |
|
|
231 |
} |
|
232 |
|
|