KickJava   Java API By Example, From Geeks To Geeks.

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


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.IAsset;
20 import org.apache.tapestry.IMarkupWriter;
21 import org.apache.tapestry.IRender;
22 import org.apache.tapestry.IRequestCycle;
23 import org.apache.tapestry.contrib.table.model.ITableColumn;
24 import org.apache.tapestry.contrib.table.model.ITableColumnModel;
25
26 /**
27  * A low level Table component that renders the column headers in the table. This component must be
28  * wrapped by {@link org.apache.tapestry.contrib.table.components.TableView}.
29  * <p>
30  * The component iterates over all column objects in the
31  * {@link org.apache.tapestry.contrib.table.model.ITableColumnModel}and renders a header for each
32  * one of them using the renderer provided by the getColumnRender() method in
33  * {@link org.apache.tapestry.contrib.table.model.ITableColumn}. The headers are wrapped in 'th'
34  * tags by default.
35  * <p>
36  * Please see the Component Reference for details on how to use this component. [ <a
37  * HREF="../../../../../../../ComponentReference/contrib.TableColumns.html">Component Reference
38  * </a>]
39  *
40  * @author mindbridge
41  */

42 public abstract class TableColumns extends AbstractTableViewComponent
43 {
44     public static final String JavaDoc TABLE_COLUMN_ARROW_UP_ATTRIBUTE = "org.apache.tapestry.contrib.table.components.TableColumns.arrowUp";
45
46     public static final String JavaDoc TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE = "org.apache.tapestry.contrib.table.components.TableColumns.arrowDown";
47
48     public static final String JavaDoc TABLE_COLUMN_CSS_CLASS_SUFFIX = "ColumnHeader";
49
50     public abstract IAsset getArrowDownAsset();
51
52     public abstract IAsset getArrowUpAsset();
53
54     public abstract void setColumn(ITableColumn column);
55
56     // Transient
57
private ITableColumn m_objTableColumn = null;
58
59     /**
60      * Returns the currently rendered table column. You can call this method to obtain the current
61      * column.
62      *
63      * @return ITableColumn the current table column
64      */

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

76     public void setTableColumn(ITableColumn tableColumn)
77     {
78         m_objTableColumn = tableColumn;
79
80         if (isParameterBound("column"))
81             setColumn(tableColumn);
82     }
83
84     /**
85      * Get the list of all table columns to be displayed.
86      *
87      * @return an iterator of all table columns
88      */

89     public Iterator JavaDoc getTableColumnIterator()
90     {
91         ITableColumnModel objColumnModel = getTableModelSource().getTableModel().getColumnModel();
92         return objColumnModel.getColumns();
93     }
94
95     /**
96      * Returns the renderer to be used to generate the header of the current column
97      *
98      * @return the header renderer of the current column
99      */

100     public IRender getTableColumnRenderer()
101     {
102         return getTableColumn().getColumnRenderer(
103                 getPage().getRequestCycle(),
104                 getTableModelSource());
105     }
106
107     public abstract String JavaDoc getColumnClassParameter();
108
109     /**
110      * Returns the CSS class of the generated table cell. It uses the class parameter if it has been
111      * bound, or the default value of "[column name]ColumnHeader" otherwise.
112      *
113      * @return the CSS class of the cell
114      */

115     public String JavaDoc getColumnClass()
116     {
117         if (isParameterBound("class"))
118             return getColumnClassParameter();
119
120         return getTableColumn().getColumnName() + TABLE_COLUMN_CSS_CLASS_SUFFIX;
121     }
122
123     /**
124      * @see org.apache.tapestry.BaseComponent#renderComponent(IMarkupWriter, IRequestCycle)
125      */

126     protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
127     {
128         Object JavaDoc oldValueUp = cycle.getAttribute(TABLE_COLUMN_ARROW_UP_ATTRIBUTE);
129         Object JavaDoc oldValueDown = cycle.getAttribute(TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE);
130
131         try
132         {
133             cycle.setAttribute(TABLE_COLUMN_ARROW_UP_ATTRIBUTE, getArrowUpAsset());
134             cycle.setAttribute(TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE, getArrowDownAsset());
135
136             super.renderComponent(writer, cycle);
137         }
138         finally
139         {
140             cycle.setAttribute(TABLE_COLUMN_ARROW_UP_ATTRIBUTE, oldValueUp);
141             cycle.setAttribute(TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE, oldValueDown);
142
143             // set the current column to null when the component is not active
144
m_objTableColumn = null;
145         }
146     }
147
148 }
Popular Tags