Source Code Cross Referenced for DataTable.java in  » J2EE » wicket » wicket » extensions » markup » html » repeater » data » table » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » wicket » wicket.extensions.markup.html.repeater.data.table 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: DataTable.java 465472 2006-10-19 04:19:43Z ivaynberg $
003:         * $Revision: 465472 $ $Date: 2006-10-19 06:19:43 +0200 (Thu, 19 Oct 2006) $
004:         * 
005:         * ==================================================================== Licensed
006:         * under the Apache License, Version 2.0 (the "License"); you may not use this
007:         * file except in compliance with the License. You may obtain a copy of the
008:         * License at
009:         * 
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
014:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015:         * License for the specific language governing permissions and limitations under
016:         * the License.
017:         */
018:        package wicket.extensions.markup.html.repeater.data.table;
019:
020:        import wicket.extensions.markup.html.repeater.RepeatingView;
021:        import wicket.extensions.markup.html.repeater.data.IDataProvider;
022:        import wicket.extensions.markup.html.repeater.data.grid.DataGridView;
023:        import wicket.extensions.markup.html.repeater.refreshing.IItemReuseStrategy;
024:        import wicket.extensions.markup.html.repeater.refreshing.Item;
025:        import wicket.extensions.markup.html.repeater.refreshing.RefreshingView;
026:        import wicket.markup.html.WebMarkupContainer;
027:        import wicket.markup.html.navigation.paging.IPageable;
028:        import wicket.markup.html.panel.Panel;
029:        import wicket.model.IModel;
030:
031:        /**
032:         * A data table builds on data grid view to introduce toolbars. Toolbars can be
033:         * used to display sortable column headers, paging information, filter controls,
034:         * and other information.
035:         * <p>
036:         * Data table also provides its own markup for an html table so the user does
037:         * not need to provide it himself. This makes it very simple to add a datatable
038:         * to the markup, however, some flexibility.
039:         * <p>
040:         * Example
041:         * 
042:         * <pre>
043:         *             &lt;table wicket:id=&quot;datatable&quot;&gt;&lt;/table&gt;
044:         * </pre>
045:         * 
046:         * And the related Java code: ( the first column will be sortable because its
047:         * sort property is specified, the second column will not )
048:         * 
049:         * <pre>
050:         * 
051:         * IColumn[] columns = new IColumn[2];
052:         * 
053:         * columns[0] = new PropertyColumn(new Model(&quot;First Name&quot;), &quot;name.first&quot;, &quot;name.first&quot;);
054:         * columns[1] = new PropertyColumn(new Model(&quot;Last Name&quot;), &quot;name.last&quot;);
055:         * 
056:         * DataTable table = new DataTable(&quot;datatable&quot;, columns, new UserProvider(), 10);
057:         * table.add(new NavigationToolbar(table));
058:         * table.add(new HeadersToolbar(table));
059:         * add(table);
060:         * 
061:         * </pre>
062:         * 
063:         * @see DefaultDataTable
064:         * 
065:         * @author Igor Vaynberg (ivaynberg)
066:         * 
067:         */
068:        public class DataTable extends Panel implements  IPageable {
069:            /**
070:             * The component id that toolbars must be created with in order to be added
071:             * to the data table
072:             */
073:            public static final String TOOLBAR_COMPONENT_ID = "toolbar";
074:
075:            private static final long serialVersionUID = 1L;
076:
077:            private final DataGridView datagrid;
078:
079:            private IColumn[] columns;
080:
081:            private final RepeatingView topToolbars;
082:            private final RepeatingView bottomToolbars;
083:
084:            /**
085:             * Constructor
086:             * 
087:             * @param id
088:             *            component id
089:             * @param columns
090:             *            list of IColumn objects
091:             * @param dataProvider
092:             *            imodel for data provider
093:             * @param rowsPerPage
094:             *            number of rows per page
095:             */
096:            public DataTable(String id, IColumn[] columns,
097:                    IDataProvider dataProvider, int rowsPerPage) {
098:                super (id);
099:
100:                this .columns = columns;
101:
102:                datagrid = new DataGridView("rows", columns, dataProvider) {
103:                    private static final long serialVersionUID = 1L;
104:
105:                    protected Item newRowItem(String id, int index, IModel model) {
106:                        return DataTable.this .newRowItem(id, index, model);
107:                    }
108:
109:                    protected Item newCellItem(String id, int index,
110:                            IModel model) {
111:                        return DataTable.this .newCellItem(id, index, model);
112:                    }
113:                };
114:                datagrid.setRowsPerPage(rowsPerPage);
115:                add(datagrid);
116:
117:                topToolbars = new RepeatingView("topToolbars") {
118:                    private static final long serialVersionUID = 1L;
119:
120:                    public boolean isVisible() {
121:                        return size() > 0;
122:                    }
123:
124:                };
125:
126:                bottomToolbars = new RepeatingView("bottomToolbars") {
127:
128:                    private static final long serialVersionUID = 1L;
129:
130:                    public boolean isVisible() {
131:                        return size() > 0;
132:                    }
133:                };
134:
135:                add(topToolbars);
136:                add(bottomToolbars);
137:            }
138:
139:            /**
140:             * @return array of column objects this table displays
141:             */
142:            public final IColumn[] getColumns() {
143:                return columns;
144:            }
145:
146:            /**
147:             * Adds a toolbar to the datatable that will be displayed before the data
148:             * 
149:             * @param toolbar
150:             *            toolbar to be added
151:             * 
152:             * @see AbstractToolbar
153:             */
154:            public void addTopToolbar(AbstractToolbar toolbar) {
155:                addToolbar(toolbar, topToolbars);
156:            }
157:
158:            /**
159:             * Adds a toolbar to the datatable that will be displayed after the data
160:             * 
161:             * @param toolbar
162:             *            toolbar to be added
163:             * 
164:             * @see AbstractToolbar
165:             */
166:            public void addBottomToolbar(AbstractToolbar toolbar) {
167:                addToolbar(toolbar, bottomToolbars);
168:            }
169:
170:            private void addToolbar(AbstractToolbar toolbar,
171:                    RepeatingView container) {
172:                if (toolbar == null) {
173:                    throw new IllegalArgumentException(
174:                            "argument [toolbar] cannot be null");
175:                }
176:
177:                if (!toolbar.getId().equals(TOOLBAR_COMPONENT_ID)) {
178:                    throw new IllegalArgumentException(
179:                            "Toolbar must have component id equal to AbstractDataTable.TOOLBAR_COMPONENT_ID");
180:                }
181:
182:                toolbar.setRenderBodyOnly(true);
183:
184:                // create a container item for the toolbar (required by repeating view)
185:                WebMarkupContainer item = new WebMarkupContainer(container
186:                        .newChildId());
187:                item.setRenderBodyOnly(true);
188:                item.add(toolbar);
189:
190:                container.add(item);
191:            }
192:
193:            /**
194:             * @see wicket.markup.html.navigation.paging.IPageable#getCurrentPage()
195:             */
196:            public final int getCurrentPage() {
197:                return datagrid.getCurrentPage();
198:            }
199:
200:            /**
201:             * @see wicket.markup.html.navigation.paging.IPageable#setCurrentPage(int)
202:             */
203:            public final void setCurrentPage(int page) {
204:                datagrid.setCurrentPage(page);
205:                onPageChanged();
206:            }
207:
208:            /**
209:             * Event listener for page-changed event
210:             */
211:            protected void onPageChanged() {
212:                // noop
213:            }
214:
215:            /**
216:             * @see wicket.markup.html.navigation.paging.IPageable#getPageCount()
217:             */
218:            public final int getPageCount() {
219:                return datagrid.getPageCount();
220:            }
221:
222:            /**
223:             * @return total number of rows in this table
224:             */
225:            public final int getRowCount() {
226:                return datagrid.getRowCount();
227:            }
228:
229:            /**
230:             * Sets the number of items to be displayed per page
231:             * 
232:             * @param items
233:             *            number of items to display per page
234:             * 
235:             */
236:            public void setRowsPerPage(int items) {
237:                datagrid.setRowsPerPage(items);
238:            }
239:
240:            /**
241:             * @return number of rows per page
242:             */
243:            public final int getRowsPerPage() {
244:                return datagrid.getRowsPerPage();
245:            }
246:
247:            /**
248:             * Factory method for Item container that represents a row in the underlying
249:             * DataGridView
250:             * 
251:             * @see Item
252:             * 
253:             * @param id
254:             *            component id for the new data item
255:             * @param index
256:             *            the index of the new data item
257:             * @param model
258:             *            the model for the new data item.
259:             * 
260:             * @return DataItem created DataItem
261:             */
262:            protected Item newRowItem(final String id, int index,
263:                    final IModel model) {
264:                return new Item(id, index, model);
265:            }
266:
267:            /**
268:             * Factory method for Item container that represents a cell in the
269:             * underlying DataGridView
270:             * 
271:             * @see Item
272:             * 
273:             * @param id
274:             *            component id for the new data item
275:             * @param index
276:             *            the index of the new data item
277:             * @param model
278:             *            the model for the new data item
279:             * 
280:             * @return DataItem created DataItem
281:             */
282:            protected Item newCellItem(final String id, int index,
283:                    final IModel model) {
284:                return new Item(id, index, model);
285:            }
286:
287:            /**
288:             * Sets the item reuse strategy. This strategy controls the creation of
289:             * {@link Item}s.
290:             * 
291:             * @see RefreshingView#setItemReuseStrategy(IItemReuseStrategy)
292:             * @see IItemReuseStrategy
293:             * 
294:             * @param strategy
295:             *            item reuse strategy
296:             * @return this for chaining
297:             */
298:            public final DataTable setItemReuseStrategy(
299:                    IItemReuseStrategy strategy) {
300:                datagrid.setItemReuseStrategy(strategy);
301:                return this;
302:            }
303:
304:        }
w__ww___.j___a__va_2__s_._co_m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.