|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
TableFormRows.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 |
import java.util.Map;
|
|
19 |
|
|
20 |
import org.apache.tapestry.IRequestCycle;
|
|
21 |
import org.apache.tapestry.contrib.table.model.*;
|
|
22 |
|
|
23 |
|
|
24 |
/**
|
|
25 |
* A low level Table component that generates the rows of the current page in the table.
|
|
26 |
*
|
|
27 |
* This component is a variant of {@link org.apache.tapestry.contrib.table.components.TablePages},
|
|
28 |
* but is designed for operation in a form. The displayed rows are stored in
|
|
29 |
* hidden form fields, which are then read during a rewind. This ensures that
|
|
30 |
* the form will rewind in exactly the same was as it was rendered even if the
|
|
31 |
* TableModel has changed and no StaleLink exceptions will occur.
|
|
32 |
*
|
|
33 |
* The component must be wrapped by {@link org.apache.tapestry.contrib.table.components.TableView}.
|
|
34 |
*
|
|
35 |
* <p>
|
|
36 |
* The component iterates over the rows of the current page in the table.
|
|
37 |
* The rows are wrapped in 'tr' tags by default.
|
|
38 |
* You can define columns manually within, or
|
|
39 |
* you can use {@link org.apache.tapestry.contrib.table.components.TableValues}
|
|
40 |
* to generate the columns automatically.
|
|
41 |
* <p>
|
|
42 |
* Please see the Component Reference for details on how to use this component.
|
|
43 |
*
|
|
44 |
* [<a href="../../../../../../../ComponentReference/contrib.TableFormRows.html">Component Reference</a>]
|
|
45 |
*
|
|
46 |
* @author mindbridge
|
|
47 |
*
|
|
48 |
*/
|
|
49 |
public abstract class TableFormRows extends TableRows |
|
50 |
{ |
|
51 |
public abstract IPrimaryKeyConvertor getConvertor();
|
|
52 |
public abstract IPrimaryKeyConvertor getConvertorCache();
|
|
53 |
public abstract void setConvertorCache(IPrimaryKeyConvertor convertor); |
|
54 |
public abstract Map getConvertedValues();
|
|
55 |
|
|
56 |
/**
|
|
57 |
* Returns the PK convertor cached within the realm of the current request cycle.
|
|
58 |
*
|
|
59 |
* @return the cached PK convertor
|
|
60 |
*/
|
|
61 | 0 |
public IPrimaryKeyConvertor getCachedConvertor()
|
62 |
{ |
|
63 | 0 |
IPrimaryKeyConvertor objConvertor = getConvertorCache(); |
64 |
|
|
65 | 0 |
if (objConvertor == null) { |
66 | 0 |
objConvertor = getConvertor(); |
67 | 0 |
setConvertorCache(objConvertor); |
68 |
} |
|
69 |
|
|
70 | 0 |
return objConvertor;
|
71 |
} |
|
72 |
|
|
73 |
/**
|
|
74 |
* Get the list of all table rows to be displayed on this page, converted
|
|
75 |
* using the PK.convertor.
|
|
76 |
*
|
|
77 |
* @return an iterator of all converted table rows
|
|
78 |
*/
|
|
79 | 0 |
public Iterator getConvertedTableRowsIterator()
|
80 |
{ |
|
81 | 0 |
final Iterator objTableRowsIterator = getTableRowsIterator(); |
82 | 0 |
final IPrimaryKeyConvertor objConvertor = getCachedConvertor(); |
83 | 0 |
if (objConvertor == null) |
84 | 0 |
return objTableRowsIterator;
|
85 |
|
|
86 | 0 |
return new Iterator() |
87 |
{ |
|
88 | 0 |
public boolean hasNext() |
89 |
{ |
|
90 | 0 |
return objTableRowsIterator.hasNext();
|
91 |
} |
|
92 |
|
|
93 | 0 |
public Object next()
|
94 |
{ |
|
95 | 0 |
Object objValue = objTableRowsIterator.next(); |
96 | 0 |
Object objPrimaryKey = objConvertor.getPrimaryKey(objValue); |
97 | 0 |
Map mapConvertedValues = getConvertedValues(); |
98 | 0 |
mapConvertedValues.put(objPrimaryKey, objValue); |
99 | 0 |
return objPrimaryKey;
|
100 |
} |
|
101 |
|
|
102 | 0 |
public void remove() |
103 |
{ |
|
104 | 0 |
objTableRowsIterator.remove(); |
105 |
} |
|
106 |
}; |
|
107 |
} |
|
108 |
|
|
109 |
/**
|
|
110 |
* Sets the current table row PK and invokes {@link #setTableRow(Object)} as a result.
|
|
111 |
* This method is for internal use only.
|
|
112 |
*
|
|
113 |
* @param objConvertedTableRow The current converted table row (PK)
|
|
114 |
*/
|
|
115 | 0 |
public void setConvertedTableRow(Object objConvertedTableRow) |
116 |
{ |
|
117 | 0 |
Object objValue = objConvertedTableRow; |
118 |
|
|
119 | 0 |
IPrimaryKeyConvertor objConvertor = getCachedConvertor(); |
120 | 0 |
if (objConvertor != null) { |
121 | 0 |
IRequestCycle objCycle = getPage().getRequestCycle(); |
122 | 0 |
if (objCycle.isRewinding()) {
|
123 | 0 |
objValue = objConvertor.getValue(objConvertedTableRow); |
124 |
} |
|
125 |
else {
|
|
126 | 0 |
Map mapConvertedValues = getConvertedValues(); |
127 | 0 |
objValue = mapConvertedValues.get(objConvertedTableRow); |
128 |
} |
|
129 |
} |
|
130 |
|
|
131 | 0 |
setTableRow(objValue); |
132 |
} |
|
133 |
} |
|
134 |
|
|