|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
TableRows.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.components; | |
16 | ||
17 | import java.util.Iterator; | |
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.IFullTableModel; | |
23 | import org.apache.tapestry.contrib.table.model.ITableModel; | |
24 | import org.apache.tapestry.contrib.table.model.ITableRowSource; | |
25 | ||
26 | /** | |
27 | * A low level Table component that generates the rows of the current page in the table. | |
28 | * This component must be wrapped by {@link org.apache.tapestry.contrib.table.components.TableView}. | |
29 | * | |
30 | * <p> | |
31 | * The component iterates over the rows of the current page in the table. | |
32 | * The rows are wrapped in 'tr' tags by default. | |
33 | * You can define columns manually within, or | |
34 | * you can use {@link org.apache.tapestry.contrib.table.components.TableValues} | |
35 | * to generate the columns automatically. | |
36 | * | |
37 | * <p> | |
38 | * Please see the Component Reference for details on how to use this component. | |
39 | * | |
40 | * [<a href="../../../../../../../ComponentReference/contrib.TableRows.html">Component Reference</a>] | |
41 | * | |
42 | * @author mindbridge | |
43 | * | |
44 | */ | |
45 | public abstract class TableRows extends AbstractTableViewComponent implements ITableRowSource | |
46 | { | |
47 | ||
48 | // Parameters | |
49 | public abstract Object getFullSourceParameter(); | |
50 | ||
51 | // Transient | |
52 | private Object m_objTableRow = null; | |
53 | private int m_nTableIndex; | |
54 | ||
55 | /** | |
56 | * Returns the currently rendered table row. | |
57 | * You can call this method to obtain the current row. | |
58 | * | |
59 | * @return Object the current table row | |
60 | */ | |
61 | 0 | public Object getTableRow() |
62 | { | |
63 | 0 | return m_objTableRow; |
64 | } | |
65 | ||
66 | /** | |
67 | * Sets the currently rendered table row. | |
68 | * This method is for internal use only. | |
69 | * | |
70 | * @param tableRow The current table row | |
71 | */ | |
72 | 0 | public void setTableRow(Object tableRow) |
73 | { | |
74 | 0 | m_objTableRow = tableRow; |
75 | ||
76 | 0 | IBinding objRowBinding = getBinding("row"); |
77 | 0 | if (objRowBinding != null) |
78 | 0 | objRowBinding.setObject(tableRow); |
79 | } | |
80 | ||
81 | /** | |
82 | * Returns the index of the currently rendered table row. | |
83 | * You can call this method to obtain the index of the current row. | |
84 | * | |
85 | * @return int the current table index | |
86 | */ | |
87 | 0 | public int getTableIndex() |
88 | { | |
89 | 0 | return m_nTableIndex; |
90 | } | |
91 | ||
92 | /** | |
93 | * Sets the index of the currently rendered table row. | |
94 | * This method is for internal use only. | |
95 | * | |
96 | * @param tableIndex The index of the current table row | |
97 | */ | |
98 | 0 | public void setTableIndex(int tableIndex) |
99 | { | |
100 | 0 | m_nTableIndex = tableIndex; |
101 | ||
102 | 0 | IBinding objIndexBinding = getBinding("index"); |
103 | 0 | if (objIndexBinding != null) |
104 | 0 | objIndexBinding.setObject(new Integer(tableIndex)); |
105 | } | |
106 | ||
107 | /** | |
108 | * Get the list of all table rows to be displayed on this page. | |
109 | * | |
110 | * @return an iterator of all table rows | |
111 | */ | |
112 | 0 | public Iterator getTableRowsIterator() |
113 | { | |
114 | 0 | ITableModel objTableModel = getTableModelSource().getTableModel(); |
115 | 0 | return objTableModel.getCurrentPageRows(); |
116 | } | |
117 | ||
118 | 0 | public Object getFullSource() |
119 | { | |
120 | 0 | ITableModel objTableModel = getTableModelSource().getTableModel(); |
121 | 0 | if (objTableModel instanceof IFullTableModel) |
122 | 0 | return ((IFullTableModel) objTableModel).getRows(); |
123 | 0 | return getFullSourceParameter(); |
124 | } | |
125 | ||
126 | /** | |
127 | * @see org.apache.tapestry.BaseComponent#renderComponent(IMarkupWriter, IRequestCycle) | |
128 | */ | |
129 | 0 | protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) |
130 | { | |
131 | 0 | Object objOldValue = cycle.getAttribute(ITableRowSource.TABLE_ROW_SOURCE_ATTRIBUTE); |
132 | 0 | cycle.setAttribute(ITableRowSource.TABLE_ROW_SOURCE_ATTRIBUTE, this); |
133 | ||
134 | 0 | super.renderComponent(writer, cycle); |
135 | ||
136 | 0 | cycle.setAttribute(ITableRowSource.TABLE_ROW_SOURCE_ATTRIBUTE, objOldValue); |
137 | ||
138 | // set the current row to null when the component is not active | |
139 | 0 | m_objTableRow = null; |
140 | } | |
141 | ||
142 | ||
143 | } |
|