Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TableFormPages |
|
| 1.2857142857142858;1.286 |
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 org.apache.tapestry.IRequestCycle; | |
18 | import org.apache.tapestry.contrib.table.model.ITableModelSource; | |
19 | import org.apache.tapestry.event.PageBeginRenderListener; | |
20 | import org.apache.tapestry.event.PageDetachListener; | |
21 | import org.apache.tapestry.event.PageEvent; | |
22 | ||
23 | /** | |
24 | * A low level Table component that renders the pages in the table. | |
25 | * | |
26 | * This component is a variant of {@link org.apache.tapestry.contrib.table.components.TablePages}, | |
27 | * but is designed for operation in a form. The necessary page data is stored | |
28 | * in hidden fields, so that no StaleLink exceptions occur during a rewind. | |
29 | * The links also submit the form, which ensures that the data in the other | |
30 | * form fields is preserved even when the page chages. | |
31 | * | |
32 | * The component must be wrapped by {@link org.apache.tapestry.contrib.table.components.TableView}. | |
33 | * <p> | |
34 | * The component generates a list of pages in the Table centered around the | |
35 | * current one and allows you to navigate to other pages. | |
36 | * <p> | |
37 | * Please see the Component Reference for details on how to use this component. | |
38 | * | |
39 | * [<a href="../../../../../../../ComponentReference/contrib.TableFormPages.html">Component Reference</a>] | |
40 | * | |
41 | * @author mindbridge | |
42 | * | |
43 | */ | |
44 | public abstract class TableFormPages extends TablePages | |
45 | implements PageDetachListener, PageBeginRenderListener | |
46 | { | |
47 | private int m_nCurrentPage; | |
48 | private int m_nPageCount; | |
49 | private int m_nStartPage; | |
50 | private int m_nStopPage; | |
51 | ||
52 | public TableFormPages() | |
53 | 0 | { |
54 | 0 | initialize(); |
55 | 0 | } |
56 | ||
57 | /** | |
58 | * @see org.apache.tapestry.event.PageDetachListener#pageDetached(org.apache.tapestry.event.PageEvent) | |
59 | */ | |
60 | public void pageDetached(PageEvent event) | |
61 | { | |
62 | 0 | initialize(); |
63 | 0 | } |
64 | ||
65 | /** | |
66 | * @see org.apache.tapestry.event.PageBeginRenderListener#pageBeginRender(org.apache.tapestry.event.PageEvent) | |
67 | */ | |
68 | public void pageBeginRender(PageEvent event) | |
69 | { | |
70 | // values set during rewind are removed | |
71 | 0 | initialize(); |
72 | 0 | } |
73 | ||
74 | /** | |
75 | * Initialize the values and return the object to operation identical | |
76 | * to that of the super class. | |
77 | */ | |
78 | private void initialize() | |
79 | { | |
80 | 0 | m_nCurrentPage = -1; |
81 | 0 | m_nPageCount = -1; |
82 | 0 | m_nStartPage = -1; |
83 | 0 | m_nStopPage = -1; |
84 | 0 | } |
85 | ||
86 | // This would ideally be a delayed invocation -- called after the form rewind | |
87 | public void changePage(IRequestCycle objCycle) | |
88 | { | |
89 | 0 | ITableModelSource objSource = getTableModelSource(); |
90 | 0 | objSource.storeTableAction(new TableActionPageChange(getSelectedPage())); |
91 | 0 | } |
92 | ||
93 | // defined in the JWC file | |
94 | public abstract int getSelectedPage(); | |
95 | ||
96 | ||
97 | /** | |
98 | * @return the current page | |
99 | */ | |
100 | public int getCurrentPage() | |
101 | { | |
102 | 0 | if (m_nCurrentPage < 0) |
103 | 0 | m_nCurrentPage = super.getCurrentPage(); |
104 | 0 | return m_nCurrentPage; |
105 | } | |
106 | ||
107 | /** | |
108 | * @return number of all pages to display | |
109 | */ | |
110 | public int getPageCount() | |
111 | { | |
112 | 0 | if (m_nPageCount < 0) |
113 | 0 | m_nPageCount = super.getPageCount(); |
114 | 0 | return m_nPageCount; |
115 | } | |
116 | ||
117 | /** | |
118 | * @return the first page to display | |
119 | */ | |
120 | public int getStartPage() | |
121 | { | |
122 | 0 | if (m_nStartPage < 0) |
123 | 0 | m_nStartPage = super.getStartPage(); |
124 | 0 | return m_nStartPage; |
125 | } | |
126 | ||
127 | /** | |
128 | * @return the last page to display | |
129 | */ | |
130 | public int getStopPage() | |
131 | { | |
132 | 0 | if (m_nStopPage < 0) |
133 | 0 | m_nStopPage = super.getStopPage(); |
134 | 0 | return m_nStopPage; |
135 | } | |
136 | ||
137 | /** | |
138 | * @param i the current page | |
139 | */ | |
140 | public void setCurrentPage(int i) | |
141 | { | |
142 | 0 | m_nCurrentPage = i; |
143 | 0 | } |
144 | ||
145 | /** | |
146 | * @param i number of all pages to display | |
147 | */ | |
148 | public void setPageCount(int i) | |
149 | { | |
150 | 0 | m_nPageCount = i; |
151 | 0 | } |
152 | ||
153 | /** | |
154 | * @param i the first page to display | |
155 | */ | |
156 | public void setStartPage(int i) | |
157 | { | |
158 | 0 | m_nStartPage = i; |
159 | 0 | } |
160 | ||
161 | /** | |
162 | * @param i the last page to display | |
163 | */ | |
164 | public void setStopPage(int i) | |
165 | { | |
166 | 0 | m_nStopPage = i; |
167 | 0 | } |
168 | ||
169 | } |