|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.arsdigita.bebop.Completable
com.arsdigita.bebop.SimpleComponent
com.arsdigita.bebop.TextStylable
com.arsdigita.bebop.BlockStylable
com.arsdigita.bebop.SimpleContainer
com.arsdigita.bebop.Paginator
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
.
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 |
public Paginator(PaginationModelBuilder builder, int defaultPageSize)
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 |
protected void buildPaginationDisplay()
setPageNumSelectionModel(SingleSelectionModel)
method is
called to set the selection model for retrieving the selected
page number.
protected void setPageNumSelectionModel(SingleSelectionModel pageNumModel)
buildPaginationDisplay()
method will need to call this
method.
pageNumModel
- The selection model used for returning the
selected page number.public int getSelectedPageNum(PageState state)
state
- Represents the current state of the request.
public void setSelectedPageNum(PageState state, int pageNum)
state
- Represents the current state of the request.pageNum
- The number of the page to set as selected.public int getPageSize(PageState state)
state
- Represents the current state of the request.
public void setPageSize(PageState state, int pageSize)
state
- Represents the current state of the request.pageSize
- The number of items to display per page.public int getTotalPages(PageState state)
state
- The page statepublic int getFirst(PageState state)
state
- Represents the current state of the request.
public int getLast(PageState state)
state
- Represents the current state of the request.
public PaginationModelBuilder getPaginationModelBuilder()
public boolean isHiddenIfSinglePage()
true
if this component is hidden
when there is only a single page to view.public void setHiddenIfSinglePage(boolean isHidden)
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.public boolean isVisible(PageState state)
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.
isVisible
in interface Component
isVisible
in class SimpleComponent
state
- Represents the current state of the request.
true
if this component is visible.getPageSize(PageState)
,
PaginationModelBuilder.getTotalSize(Paginator, PageState)
public void register(Page p)
register
in interface Component
register
in class SimpleComponent
p
- The page to register with.public void reset(PageState state)
reset
in interface Resettable
state
- Represents the current state of the request.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |