Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TableValues |
|
| 1.375;1.375 |
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.components; | |
16 | ||
17 | import java.util.Iterator; | |
18 | ||
19 | import org.apache.tapestry.IBinding; | |
20 | import org.apache.tapestry.IRender; | |
21 | import org.apache.tapestry.IRequestCycle; | |
22 | import org.apache.tapestry.contrib.table.model.ITableColumn; | |
23 | import org.apache.tapestry.contrib.table.model.ITableColumnModel; | |
24 | ||
25 | /** | |
26 | * A low level Table component that generates the columns in the current row in the table. This | |
27 | * component must be wrapped by {@link org.apache.tapestry.contrib.table.components.TableRows}. | |
28 | * <p> | |
29 | * The component iterates over the columns in the table and automatically renders the column values | |
30 | * for the current table row. The columns are wrapped in 'td' tags by default. <br> | |
31 | * The column values are rendered using the renderer returned by the getValueRenderer() method in | |
32 | * {@link org.apache.tapestry.contrib.table.model.ITableColumn}. | |
33 | * <p> | |
34 | * Please see the Component Reference for details on how to use this component. [ <a | |
35 | * href="../../../../../../../ComponentReference/contrib.TableValues.html">Component Reference </a>] | |
36 | * | |
37 | * @author mindbridge | |
38 | */ | |
39 | 0 | public abstract class TableValues extends AbstractTableRowComponent |
40 | { | |
41 | public static final String TABLE_VALUE_CSS_CLASS_SUFFIX = "ColumnValue"; | |
42 | ||
43 | // Transient | |
44 | private ITableColumn m_objTableColumn; | |
45 | ||
46 | /** | |
47 | * Get the list of all table columns to be displayed. | |
48 | * | |
49 | * @return an iterator of all table columns | |
50 | */ | |
51 | public Iterator getTableColumnIterator() | |
52 | { | |
53 | 0 | ITableColumnModel objColumnModel = getTableModelSource().getTableModel().getColumnModel(); |
54 | 0 | return objColumnModel.getColumns(); |
55 | } | |
56 | ||
57 | /** | |
58 | * Returns the currently rendered table column. You can call this method to obtain the current | |
59 | * column. | |
60 | * | |
61 | * @return ITableColumn the current table column | |
62 | */ | |
63 | public ITableColumn getTableColumn() | |
64 | { | |
65 | 0 | return m_objTableColumn; |
66 | } | |
67 | ||
68 | /** | |
69 | * Sets the currently rendered table column. This method is for internal use only. | |
70 | * | |
71 | * @param tableColumn | |
72 | * The current table column | |
73 | */ | |
74 | public void setTableColumn(ITableColumn tableColumn) | |
75 | { | |
76 | 0 | m_objTableColumn = tableColumn; |
77 | ||
78 | 0 | if (isParameterBound("column")) |
79 | 0 | setColumnParameter(tableColumn); |
80 | 0 | } |
81 | ||
82 | /** | |
83 | * Returns the renderer to be used to generate the appearance of the current column. | |
84 | * | |
85 | * @return the value renderer of the current column | |
86 | */ | |
87 | public IRender getTableValueRenderer() | |
88 | { | |
89 | 0 | Object objRow = getTableRowSource().getTableRow(); |
90 | 0 | return getTableColumn().getValueRenderer( |
91 | getPage().getRequestCycle(), | |
92 | getTableModelSource(), | |
93 | objRow); | |
94 | } | |
95 | ||
96 | /** | |
97 | * Returns the CSS class of the generated table cell. It uses the class parameter if it has been | |
98 | * bound, or the default value of "[column name]ColumnValue" otherwise. | |
99 | * | |
100 | * @return the CSS class of the cell | |
101 | */ | |
102 | public String getValueClass() | |
103 | { | |
104 | 0 | IBinding classBinding = getBinding("class"); |
105 | 0 | if (classBinding != null) |
106 | 0 | return classBinding.getObject(String.class).toString(); |
107 | ||
108 | 0 | return getTableColumn().getColumnName() + TABLE_VALUE_CSS_CLASS_SUFFIX; |
109 | } | |
110 | ||
111 | /** @since 4.0 */ | |
112 | protected void cleanupAfterRender(IRequestCycle cycle) | |
113 | { | |
114 | 0 | super.cleanupAfterRender(cycle); |
115 | ||
116 | 0 | m_objTableColumn = null; |
117 | ||
118 | 0 | } |
119 | ||
120 | /** @since 4.0 */ | |
121 | ||
122 | public abstract void setColumnParameter(ITableColumn column); | |
123 | ||
124 | /** @since 4.0 */ | |
125 | ||
126 | public abstract String getCellClass(); | |
127 | } |