KickJava   Java API By Example, From Geeks To Geeks.

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


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.IBinding;
20 import org.apache.tapestry.IMarkupWriter;
21 import org.apache.tapestry.IRequestCycle;
22 import org.apache.tapestry.contrib.table.model.ITableModel;
23 import org.apache.tapestry.contrib.table.model.ITableRowSource;
24
25 /**
26  * A low level Table component that generates the rows of the current page in the table.
27  * This component must be wrapped by {@link org.apache.tapestry.contrib.table.components.TableView}.
28  *
29  * <p>
30  * The component iterates over the rows of the current page in the table.
31  * The rows are wrapped in 'tr' tags by default.
32  * You can define columns manually within, or
33  * you can use {@link org.apache.tapestry.contrib.table.components.TableValues}
34  * to generate the columns automatically.
35  *
36  * <p>
37  * Please see the Component Reference for details on how to use this component.
38  *
39  * [<a HREF="../../../../../../../ComponentReference/contrib.TableRows.html">Component Reference</a>]
40  *
41  * @author mindbridge
42  *
43  */

44 public abstract class TableRows extends AbstractTableViewComponent implements ITableRowSource
45 {
46
47     // Transient
48
private Object JavaDoc m_objTableRow = null;
49
50     /**
51      * Returns the currently rendered table row.
52      * You can call this method to obtain the current row.
53      *
54      * @return Object the current table row
55      */

56     public Object JavaDoc getTableRow()
57     {
58         return m_objTableRow;
59     }
60
61     /**
62      * Sets the currently rendered table row.
63      * This method is for internal use only.
64      *
65      * @param tableRow The current table row
66      */

67     public void setTableRow(Object JavaDoc tableRow)
68     {
69         m_objTableRow = tableRow;
70
71         IBinding objRowBinding = getBinding("row");
72         if (objRowBinding != null)
73             objRowBinding.setObject(tableRow);
74     }
75
76     /**
77      * Get the list of all table rows to be displayed on this page.
78      *
79      * @return an iterator of all table rows
80      */

81     public Iterator JavaDoc getTableRowsIterator()
82     {
83         ITableModel objTableModel = getTableModelSource().getTableModel();
84         return objTableModel.getCurrentPageRows();
85     }
86
87     /**
88      * @see org.apache.tapestry.BaseComponent#renderComponent(IMarkupWriter, IRequestCycle)
89      */

90     protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
91     {
92         Object JavaDoc objOldValue = cycle.getAttribute(ITableRowSource.TABLE_ROW_SOURCE_ATTRIBUTE);
93         cycle.setAttribute(ITableRowSource.TABLE_ROW_SOURCE_ATTRIBUTE, this);
94
95         super.renderComponent(writer, cycle);
96
97         cycle.setAttribute(ITableRowSource.TABLE_ROW_SOURCE_ATTRIBUTE, objOldValue);
98
99         // set the current row to null when the component is not active
100
m_objTableRow = null;
101     }
102
103 }
104
Popular Tags