001: /*
002: * $Id: PagingNavigator.java 459581 2006-03-02 08:46:15Z ehillenius $
003: * $Revision: 459581 $
004: * $Date: 2006-03-02 09:46:15 +0100 (Thu, 02 Mar 2006) $
005: *
006: * ==============================================================================
007: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
008: * use this file except in compliance with the License. You may obtain a copy of
009: * the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
015: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
016: * License for the specific language governing permissions and limitations under
017: * the License.
018: */
019: package wicket.markup.html.navigation.paging;
020:
021: import wicket.markup.html.link.Link;
022: import wicket.markup.html.panel.Panel;
023:
024: /**
025: * A Wicket panel component to draw and maintain a complete page navigator,
026: * meant to be easily added to any PageableListView. A navigation which contains
027: * links to the first and last page, the current page +- some increment and
028: * which supports paged navigation bars (@see
029: * PageableListViewNavigationWithMargin).
030: *
031: * @author Juergen Donnerstag
032: */
033: public class PagingNavigator extends Panel {
034: private static final long serialVersionUID = 1L;
035:
036: /** The navigation bar to be printed, e.g. 1 | 2 | 3 etc. */
037: private final PagingNavigation pagingNavigation;
038:
039: /**
040: * Constructor.
041: *
042: * @param id
043: * See Component
044: * @param pageable
045: * The pageable component the page links are referring to.
046: */
047: public PagingNavigator(final String id, final IPageable pageable) {
048: this (id, pageable, null);
049: }
050:
051: /**
052: * Constructor.
053: *
054: * @param id
055: * See Component
056: * @param pageable
057: * The pageable component the page links are referring to.
058: * @param labelProvider
059: * The label provider for the link text.
060: */
061: public PagingNavigator(final String id, final IPageable pageable,
062: final IPagingLabelProvider labelProvider) {
063: super (id);
064:
065: // Get the navigation bar and add it to the hierarchy
066: this .pagingNavigation = newNavigation(pageable, labelProvider);
067: add(pagingNavigation);
068:
069: // Add additional page links
070: add(newPagingNavigationLink("first", pageable, 0));
071: add(newPagingNavigationIncrementLink("prev", pageable, -1));
072: add(newPagingNavigationIncrementLink("next", pageable, 1));
073: add(newPagingNavigationLink("last", pageable, -1));
074: }
075:
076: /**
077: * Create a new increment link. May be subclassed to make use of specialized
078: * links, e.g. Ajaxian links.
079: *
080: * @param id
081: * the link id
082: * @param pageable
083: * the pageable to control
084: * @param increment
085: * the increment
086: * @return the increment link
087: */
088: protected Link newPagingNavigationIncrementLink(String id,
089: IPageable pageable, int increment) {
090: return new PagingNavigationIncrementLink(id, pageable,
091: increment);
092: }
093:
094: /**
095: * Create a new pagenumber link. May be subclassed to make use of
096: * specialized links, e.g. Ajaxian links.
097: *
098: * @param id
099: * the link id
100: * @param pageable
101: * the pageable to control
102: * @param pageNumber
103: * the page to jump to
104: * @return the pagenumber link
105: */
106: protected Link newPagingNavigationLink(String id,
107: IPageable pageable, int pageNumber) {
108: return new PagingNavigationLink(id, pageable, pageNumber);
109: }
110:
111: /**
112: * Create a new PagingNavigation. May be subclassed to make us of
113: * specialized PagingNavigation.
114: *
115: * @param pageable
116: * the pageable component
117: * @param labelProvider
118: * The label provider for the link text.
119: * @return the navigation object
120: */
121: protected PagingNavigation newNavigation(final IPageable pageable,
122: final IPagingLabelProvider labelProvider) {
123: return new PagingNavigation("navigation", pageable,
124: labelProvider);
125: }
126:
127: /**
128: * Gets the pageable navigation component for configuration purposes.
129: *
130: * @return the associated pageable navigation.
131: */
132: public final PagingNavigation getPagingNavigation() {
133: return pagingNavigation;
134: }
135: }
|