KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > contrib > table > components > TableValues


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 JavaDoc;
18
19 import org.apache.tapestry.IRender;
20 import org.apache.tapestry.IRequestCycle;
21 import org.apache.tapestry.contrib.table.model.ITableColumn;
22 import org.apache.tapestry.contrib.table.model.ITableColumnModel;
23
24 /**
25  * A low level Table component that generates the columns in the current row in the table. This
26  * component must be wrapped by {@link org.apache.tapestry.contrib.table.components.TableRows}.
27  * <p>
28  * The component iterates over the columns in the table and automatically renders the column values
29  * for the current table row. The columns are wrapped in 'td' tags by default. <br>
30  * The column values are rendered using the renderer returned by the getValueRenderer() method in
31  * {@link org.apache.tapestry.contrib.table.model.ITableColumn}.
32  * <p>
33  * Please see the Component Reference for details on how to use this component. [ <a
34  * HREF="../../../../../../../ComponentReference/contrib.TableValues.html">Component Reference </a>]
35  *
36  * @author mindbridge
37  */

38 public abstract class TableValues extends AbstractTableRowComponent
39 {
40     public static final String JavaDoc TABLE_VALUE_CSS_CLASS_SUFFIX = "ColumnValue";
41
42     // Transient
43
private ITableColumn m_objTableColumn;
44
45     /**
46      * Get the list of all table columns to be displayed.
47      *
48      * @return an iterator of all table columns
49      */

50     public Iterator JavaDoc getTableColumnIterator()
51     {
52         ITableColumnModel objColumnModel = getTableModelSource().getTableModel().getColumnModel();
53         return objColumnModel.getColumns();
54     }
55
56     /**
57      * Returns the currently rendered table column. You can call this method to obtain the current
58      * column.
59      *
60      * @return ITableColumn the current table column
61      */

62     public ITableColumn getTableColumn()
63     {
64         return m_objTableColumn;
65     }
66
67     /**
68      * Sets the currently rendered table column. This method is for internal use only.
69      *
70      * @param tableColumn
71      * The current table column
72      */

73     public void setTableColumn(ITableColumn tableColumn)
74     {
75         m_objTableColumn = tableColumn;
76
77         if (isParameterBound("column"))
78             setColumnParameter(tableColumn);
79     }
80
81     /**
82      * Returns the renderer to be used to generate the appearance of the current column
83      *
84      * @return the value renderer of the current column
85      */

86     public IRender getTableValueRenderer()
87     {
88         Object JavaDoc objRow = getTableRowSource().getTableRow();
89         return getTableColumn().getValueRenderer(
90                 getPage().getRequestCycle(),
91                 getTableModelSource(),
92                 objRow);
93     }
94
95     /**
96      * Returns the CSS class of the generated table cell. It uses the class parameter if it has been
97      * bound, or the default value of "[column name]ColumnValue" otherwise.
98      *
99      * @return the CSS class of the cell
100      */

101     public String JavaDoc getValueClass()
102     {
103         if (isParameterBound("class"))
104             return getCellClass();
105
106         return getTableColumn().getColumnName() + TABLE_VALUE_CSS_CLASS_SUFFIX;
107     }
108
109     /** @since 4.0 */
110     protected void cleanupAfterRender(IRequestCycle cycle)
111     {
112         super.cleanupAfterRender(cycle);
113
114         m_objTableColumn = null;
115
116     }
117
118     /** @since 4.0 */
119
120     public abstract void setColumnParameter(ITableColumn column);
121
122     /** @since 4.0 */
123
124     public abstract String JavaDoc getCellClass();
125 }
Popular Tags