com.arsdigita.bebop
Class Paginator

java.lang.Object
  extended bycom.arsdigita.bebop.Completable
      extended bycom.arsdigita.bebop.SimpleComponent
          extended bycom.arsdigita.bebop.TextStylable
              extended bycom.arsdigita.bebop.BlockStylable
                  extended bycom.arsdigita.bebop.SimpleContainer
                      extended bycom.arsdigita.bebop.Paginator
All Implemented Interfaces:
Cloneable, Component, Container, Lockable, Resettable

public class Paginator
extends SimpleContainer
implements Resettable

A pagination component used to select different page views from a list of items.

In most cases, this component will be used with either a List or a Table. Here is an example on how to use this pagination component with a Table:


 Table myTable = new Table(new myTableModelBuilder(),
                           new DefaultTableColumnModel());
 Paginator pgntr = new Paginator((PaginationModelBuilder) myTable.getModelBuilder(), 10);

 Page p = new Page();
 p.add(pgntr);
 p.add(myTable);
 

The model builder that is used in myTable was designed to also implement the PaginationModelBuilder interface. With both interfaces being implemented by the same class, it is much easier to cache the results of operations performed on the DataQuery used to generate the results.


 public class myTableModelBuilder extends LockableImpl
     implements TableModelBuilder, PaginatedModelBuilder {

     private RequestLocal m_query;

     public myTableModelBuilder() {
         super();
         m_query = new RequestLocal();
     }

     private getDataQuery(PageState state) {
         // returns the DataQuery used to generate rows for the table
     }

     public int getTotalSize(Paginator pgntr, PageState state) {
         DataQuery query = getDataQuery(state);
         query.setRange(new Integer(pgntr.getFirst(state)),
                        new Integer(pgntr.getLast(state) + 1));
         m_query.set(state, query);
         return (int) query.size();
     }

     public TableModel makeModel(Table table, PageState state) {
         return new myTableModel(table, state, (DataQuery) m_query.get(state));
     }
 }
 

Subclasses that wish to render the page links in a different format will override the buildPaginationDisplay() method. The implementation of this method must set the selection model used to retrieve the page number by calling the setPageNumSelectionModel(SingleSelectionModel) method. Aside from changing the display, this pagination component will hide itself if PaginationModelBuilder.getTotalSize(Paginator, PageState) is less than the page size (i.e., a single page can be used to display the entire results). This default behavior can be changed by calling setHiddenIfSinglePage(boolean) with false.

Since:
4.6.10
Version:
$Id: //core-platform/dev/src/com/arsdigita/bebop/Paginator.java#15 $
Author:
Phong Nguyen
See Also:
PaginationModelBuilder

Field Summary
 
Fields inherited from class com.arsdigita.bebop.SimpleContainer
versionId
 
Fields inherited from class com.arsdigita.bebop.BlockStylable
ABSBOTTOM, ABSMIDDLE, BASELINE, BOTTOM, CENTER, FULL_WIDTH, INSERT, LEFT, MIDDLE, RIGHT, TEXTTOP, TOP
 
Fields inherited from class com.arsdigita.bebop.SimpleComponent
m_attr
 
Fields inherited from interface com.arsdigita.bebop.Resettable
versionId
 
Fields inherited from interface com.arsdigita.bebop.Component
BEBOP_XML_NS, CLASS, ID, ON_CLICK, STYLE
 
Constructor Summary
Paginator(PaginationModelBuilder builder, int defaultPageSize)
          Constructor.
 
Method Summary
protected  void buildPaginationDisplay()
          Builds the display for rendering the page links.
 int getFirst(PageState state)
          Returns the number of the first item to display.
 int getLast(PageState state)
          Returns the number of the last item to display.
 int getPageSize(PageState state)
          Returns the number of items to display per page.
 PaginationModelBuilder getPaginationModelBuilder()
          Returns the builder that is used to retrieve the total number of items to paginate.
 int getSelectedPageNum(PageState state)
          Returns the selected page number.
 int getTotalPages(PageState state)
          This returns the total number of pages that will be displayed by this paginator.
 boolean isHiddenIfSinglePage()
          Specifies whether this component is hidden if there is only a single page of items to display.
 boolean isVisible(PageState state)
          Returns true if this component is visible.
 void register(Page p)
          Register the page size selection model.
 void reset(PageState state)
          Resets this component by clearing the selected page.
 void setHiddenIfSinglePage(boolean isHidden)
          Sets whether or not this component should be hidden if there is only a single page of items to display.
protected  void setPageNumSelectionModel(SingleSelectionModel pageNumModel)
          Sets the selection model that is used for returning the selected page number.
 void setPageSize(PageState state, int pageSize)
          Sets the number of items to display per page.
 void setSelectedPageNum(PageState state, int pageNum)
          Sets the selected page number.
 
Methods inherited from class com.arsdigita.bebop.SimpleContainer
add, add, children, contains, generateChildrenXML, generateParent, generateXML, get, getNamespace, getTag, indexOf, isEmpty, setNamespace, setTag, size
 
Methods inherited from class com.arsdigita.bebop.BlockStylable
setBorder, setBorder, setBorderColor, setHorizontalAlignment, setMargin, setMargin, setPadding, setPadding, setVerticalAlignment
 
Methods inherited from class com.arsdigita.bebop.TextStylable
setBackgroundColor, setColor
 
Methods inherited from class com.arsdigita.bebop.SimpleComponent
clone, exportAttributes, getAttribute, getClassAttr, getIdAttr, getKey, getMetaDataAttribute, getStyleAttr, hasAttributes, isLocked, lock, register, respond, setAttribute, setClassAttr, setIdAttr, setKey, setMetaDataAttribute, setStyleAttr, setVisible
 
Methods inherited from class com.arsdigita.bebop.Completable
addCompletionListener, fireCompletionEvent
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.arsdigita.bebop.Component
getClassAttr, getIdAttr, getKey, getStyleAttr, register, respond, setClassAttr, setIdAttr, setKey, setStyleAttr, setVisible
 
Methods inherited from interface com.arsdigita.util.Lockable
isLocked, lock
 

Constructor Detail

Paginator

public Paginator(PaginationModelBuilder builder,
                 int defaultPageSize)
Constructor.

Parameters:
builder - The builder used to retrieve the total number of results to paginate.
defaultPageSize - The default number of results to display on each page.
Method Detail

buildPaginationDisplay

protected void buildPaginationDisplay()
Builds the display for rendering the page links. Subclasses can override this method to provide a different rendering of the page links. If this is the case, make sure that the setPageNumSelectionModel(SingleSelectionModel) method is called to set the selection model for retrieving the selected page number.


setPageNumSelectionModel

protected void setPageNumSelectionModel(SingleSelectionModel pageNumModel)
Sets the selection model that is used for returning the selected page number. Subclasses that override the buildPaginationDisplay() method will need to call this method.

Parameters:
pageNumModel - The selection model used for returning the selected page number.

getSelectedPageNum

public int getSelectedPageNum(PageState state)
Returns the selected page number.

Parameters:
state - Represents the current state of the request.
Returns:
The selected page number.

setSelectedPageNum

public void setSelectedPageNum(PageState state,
                               int pageNum)
Sets the selected page number.

Parameters:
state - Represents the current state of the request.
pageNum - The number of the page to set as selected.

getPageSize

public int getPageSize(PageState state)
Returns the number of items to display per page.

Parameters:
state - Represents the current state of the request.
Returns:
The number of items to display per page.

setPageSize

public void setPageSize(PageState state,
                        int pageSize)
Sets the number of items to display per page.

Parameters:
state - Represents the current state of the request.
pageSize - The number of items to display per page.

getTotalPages

public int getTotalPages(PageState state)
This returns the total number of pages that will be displayed by this paginator.

Parameters:
state - The page state

getFirst

public int getFirst(PageState state)
Returns the number of the first item to display.

Parameters:
state - Represents the current state of the request.
Returns:
The number of the first item to display.

getLast

public int getLast(PageState state)
Returns the number of the last item to display.

Parameters:
state - Represents the current state of the request.
Returns:
The number of teh last item to display.

getPaginationModelBuilder

public PaginationModelBuilder getPaginationModelBuilder()
Returns the builder that is used to retrieve the total number of items to paginate.

Returns:
The builder used to compute the total number of items to paginate.

isHiddenIfSinglePage

public boolean isHiddenIfSinglePage()
Specifies whether this component is hidden if there is only a single page of items to display.

Returns:
Returns true if this component is hidden when there is only a single page to view.

setHiddenIfSinglePage

public void setHiddenIfSinglePage(boolean isHidden)
Sets whether or not this component should be hidden if there is only a single page of items to display.

Parameters:
isHidden - By default, this component will be hidden when there is only a single page to display. Set this to false if this is not the desired effect.

isVisible

public boolean isVisible(PageState state)
Returns true if this component is visible. This component will not be visible if the paginator model builder's isVisible method reports false. If this component is set to be hidden when there is only a single page to display, then the total page size returned from the PaginationModelBuilder object must be greater than the number of items per page.

Specified by:
isVisible in interface Component
Overrides:
isVisible in class SimpleComponent
Parameters:
state - Represents the current state of the request.
Returns:
Returns true if this component is visible.
See Also:
getPageSize(PageState), PaginationModelBuilder.getTotalSize(Paginator, PageState)

register

public void register(Page p)
Register the page size selection model.

Specified by:
register in interface Component
Overrides:
register in class SimpleComponent
Parameters:
p - The page to register with.

reset

public void reset(PageState state)
Resets this component by clearing the selected page.

Specified by:
reset in interface Resettable
Parameters:
state - Represents the current state of the request.


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC