KickJava   Java API By Example, From Geeks To Geeks.

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


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     {
54         initialize();
55     }
56
57     /**
58      * @see org.apache.tapestry.event.PageDetachListener#pageDetached(org.apache.tapestry.event.PageEvent)
59      */

60     public void pageDetached(PageEvent event)
61     {
62         initialize();
63     }
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
initialize();
72     }
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         m_nCurrentPage = -1;
81         m_nPageCount = -1;
82         m_nStartPage = -1;
83         m_nStopPage = -1;
84     }
85
86     // This would ideally be a delayed invocation -- called after the form rewind
87
public void changePage(IRequestCycle objCycle)
88     {
89         ITableModelSource objSource = getTableModelSource();
90         setCurrentPage(objSource, getSelectedPage());
91
92         // ensure that the change is saved
93
objSource.fireObservedStateChange();
94     }
95
96     // defined in the JWC file
97
public abstract int getSelectedPage();
98
99
100     /**
101      * @return the current page
102      */

103     public int getCurrentPage()
104     {
105         if (m_nCurrentPage < 0)
106             m_nCurrentPage = super.getCurrentPage();
107         return m_nCurrentPage;
108     }
109
110     /**
111      * @return number of all pages to display
112      */

113     public int getPageCount()
114     {
115         if (m_nPageCount < 0)
116             m_nPageCount = super.getPageCount();
117         return m_nPageCount;
118     }
119
120     /**
121      * @return the first page to display
122      */

123     public int getStartPage()
124     {
125         if (m_nStartPage < 0)
126             m_nStartPage = super.getStartPage();
127         return m_nStartPage;
128     }
129
130     /**
131      * @return the last page to display
132      */

133     public int getStopPage()
134     {
135         if (m_nStopPage < 0)
136             m_nStopPage = super.getStopPage();
137         return m_nStopPage;
138     }
139
140     /**
141      * @param i the current page
142      */

143     public void setCurrentPage(int i)
144     {
145         m_nCurrentPage = i;
146     }
147
148     /**
149      * @param i number of all pages to display
150      */

151     public void setPageCount(int i)
152     {
153         m_nPageCount = i;
154     }
155
156     /**
157      * @param i the first page to display
158      */

159     public void setStartPage(int i)
160     {
161         m_nStartPage = i;
162     }
163
164     /**
165      * @param i the last page to display
166      */

167     public void setStopPage(int i)
168     {
169         m_nStopPage = i;
170     }
171
172 }
173
Popular Tags