net.sf.clickclick.control.paginator
Class SimplePaginator

java.lang.Object
  extended by org.apache.click.control.AbstractControl
      extended by net.sf.clickclick.control.paginator.SimplePaginator
All Implemented Interfaces:
Serializable, Paginator, Control, Renderable

public class SimplePaginator
extends AbstractControl
implements Paginator

Provides a simple independent paginator control.

The Paginator is based on the following article: http://woork.blogspot.com/2008/03/perfect-pagination-style-using-css.html.

Pre defined styles

The paginator CSS style sheet, ("/clickclick/core/paginator/SimplePaginator.css"), defines the following predefined styles:

See Also:
Serialized Form

Field Summary
protected  ActionLink controlLink
          The link to render.
protected  int itemsPerPage
           
protected  int lowerBound
          Indicates the lower bound for rendering paging links.
static String PAGE
          The control ActionLink page number parameter name: "page".
protected  String styleClass
          The css style class, default is "pagination-digg".
protected  int totalItems
           
protected  int upperBound
          Indicates the upper bound for rendering paging links.
 
Fields inherited from class org.apache.click.control.AbstractControl
actionListener, attributes, behaviors, headElements, listener, listenerMethod, messages, name, parent, styles
 
Fields inherited from interface org.apache.click.Control
CONTROL_MESSAGES
 
Constructor Summary
SimplePaginator()
          Create a default SimplePaginator.
SimplePaginator(String name)
          Create a SimplePaginator for the given name.
 
Method Summary
protected  void calcLowerAndUpperBound()
          Calculate the lowerBound and upperBound values.
 ActionLink getControlLink()
          Return the page link.
 int getCurrentPage()
          Return the current page value.
 int getFirstItem()
          Return the index of the first item to display.
 String getFirstLabelMessage()
          Return the label of the first page link.
 String getFirstTitleMessage()
          Return the title of the first page link.
 String getGotoPageTitleMessage()
          Return the title of the page link.
 List<Element> getHeadElements()
          Return the following head elements for the paginator: "/clickclick/core/paginator/SimplePaginator.css"
 int getItemsPerPage()
           
 int getLastItem()
          Return the index of the last item to display.
 String getLastLabelMessage()
          Return the label of the last page link.
 String getLastTitleMessage()
          Return the title of the last page link.
 String getNextLabelMessage()
          Return the label of the next page link.
 String getNextTitleMessage()
          Return the title of the next page link.
 int getPageTotal()
          Return the total number of pages.
 String getPreviousLabelMessage()
          Return the label of the previous page link.
 String getPreviousTitleMessage()
          Return the title of the previous page link.
 int getTotalItems()
           
 void onDestroy()
           
 void render(HtmlStringBuffer buffer)
          Render the paginator output to the specified buffer.
protected  void renderFirst(HtmlStringBuffer buffer)
          Render the first paginator link.
protected  void renderLast(HtmlStringBuffer buffer)
          Render the last paginator link.
protected  void renderNext(HtmlStringBuffer buffer)
          Render the next paginator link.
protected  void renderPagingLink(HtmlStringBuffer buffer, int pageNumber)
          Render the page link for the given page number.
protected  void renderPagingLinkContainer(HtmlStringBuffer buffer, int pageNumber)
          Render the page link container.
protected  void renderPagingLinkSeparator(HtmlStringBuffer buffer)
          Render a separator between page links.
protected  void renderPrevious(HtmlStringBuffer buffer)
          Render the previous paginator link.
 void setClass(String value)
          Set the HTML class attribute.
 void setControlLink(ActionLink controlLink)
          Set the page link.
 void setCurrentPage(int currentPage)
          Set the current page value.
 void setItemsPerPage(int itemsPerPage)
          Set the number of items per page.
 void setTotalItems(int totalItems)
          Set the total number of items the paginator is presenting.
 String toString()
          Render the HTML representation of the paginator.
 
Methods inherited from class org.apache.click.control.AbstractControl
addBehavior, addStyleClass, appendAttributes, dispatchActionEvent, getActionListener, getAttribute, getAttributes, getBehaviors, getContext, getControlSizeEst, getCssSelector, getHtmlImports, getId, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, getTag, hasAttribute, hasAttributes, hasBehaviors, hasStyles, isAjaxTarget, onDeploy, onInit, onProcess, onRender, removeBehavior, removeStyleClass, renderTagBegin, renderTagEnd, setActionListener, setAttribute, setId, setListener, setName, setParent, setStyle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PAGE

public static final String PAGE
The control ActionLink page number parameter name: "page".

See Also:
Constant Field Values

lowerBound

protected int lowerBound
Indicates the lower bound for rendering paging links.


upperBound

protected int upperBound
Indicates the upper bound for rendering paging links.


styleClass

protected String styleClass
The css style class, default is "pagination-digg".


controlLink

protected ActionLink controlLink
The link to render.


totalItems

protected int totalItems

itemsPerPage

protected int itemsPerPage
Constructor Detail

SimplePaginator

public SimplePaginator()
Create a default SimplePaginator.


SimplePaginator

public SimplePaginator(String name)
Create a SimplePaginator for the given name.

Parameters:
name - the name of the paginator
Method Detail

getFirstTitleMessage

public String getFirstTitleMessage()
Return the title of the first page link.

The title can be localized through the message "paginator-first-title".

Returns:
the title of the first page link

getFirstLabelMessage

public String getFirstLabelMessage()
Return the label of the first page link.

The label can be localized through the message "paginator-first-label".

Returns:
the label of the first page link

getLastTitleMessage

public String getLastTitleMessage()
Return the title of the last page link.

The title can be localized through the message "paginator-last-title".

Returns:
the title of the last page link

getLastLabelMessage

public String getLastLabelMessage()
Return the label of the last page link.

The label can be localized through the message "paginator-last-label".

Returns:
the label of the last page link

getNextTitleMessage

public String getNextTitleMessage()
Return the title of the next page link.

The title can be localized through the message "paginator-next-title".

Returns:
the title of the next page link

getNextLabelMessage

public String getNextLabelMessage()
Return the label of the next page link.

The label can be localized through the message "paginator-next-label".

Returns:
the label of the next page link

getPreviousTitleMessage

public String getPreviousTitleMessage()
Return the title of the previous page link.

The title can be localized through the message "paginator-previous-title".

Returns:
the title of the previous page link

getPreviousLabelMessage

public String getPreviousLabelMessage()
Return the label of the previous page link.

The label can be localized through the message "paginator-previous-label".

Returns:
the label of the previous page link

getGotoPageTitleMessage

public String getGotoPageTitleMessage()
Return the title of the page link.

The title can be localized through the message "paginator-goto-title".

Returns:
the title of the page link

setControlLink

public void setControlLink(ActionLink controlLink)
Set the page link.

Parameters:
pageLink - the page link

getControlLink

public ActionLink getControlLink()
Return the page link.

Returns:
the page link

setClass

public void setClass(String value)
Set the HTML class attribute.

Note: this method will replace the existing "class" attribute value.

Predefined paginator CSS classes are:

Parameters:
value - the HTML class attribute

setCurrentPage

public void setCurrentPage(int currentPage)
Set the current page value.

Specified by:
setCurrentPage in interface Paginator
Parameters:
currentPage - the current page value

getCurrentPage

public int getCurrentPage()
Return the current page value.

Specified by:
getCurrentPage in interface Paginator
Returns:
the current page value

getPageTotal

public int getPageTotal()
Return the total number of pages.

Returns:
the total number of pages

getTotalItems

public int getTotalItems()
Returns:
the totalItems

setTotalItems

public void setTotalItems(int totalItems)
Description copied from interface: Paginator
Set the total number of items the paginator is presenting.

Specified by:
setTotalItems in interface Paginator
Parameters:
totalItems - the totalItems to set

getItemsPerPage

public int getItemsPerPage()
Returns:
the itemsPerPage

setItemsPerPage

public void setItemsPerPage(int itemsPerPage)
Description copied from interface: Paginator
Set the number of items per page. A value of 0 means there is no items per page.

Specified by:
setItemsPerPage in interface Paginator
Parameters:
itemsPerPage - the itemsPerPage to set

getFirstItem

public int getFirstItem()
Return the index of the first item to display. Index starts from 0.

Note: items per page must be set for this method to correctly calculate the first item index, otherwise this method will return 0.

Returns:
the index of the first item to display

getLastItem

public int getLastItem()
Return the index of the last item to display. Index starts from 0.

Note: the paginator total items and items per page must be set for this method to correctly calculate the last item, otherwise this method will return 0.

Returns:
the index of the last item to display

getHeadElements

public List<Element> getHeadElements()
Return the following head elements for the paginator:

Specified by:
getHeadElements in interface Control
Overrides:
getHeadElements in class AbstractControl
Returns:
the head elements of the paginator

onDestroy

public void onDestroy()
Specified by:
onDestroy in interface Control
Overrides:
onDestroy in class AbstractControl

render

public void render(HtmlStringBuffer buffer)
Render the paginator output to the specified buffer.

Specified by:
render in interface Control
Specified by:
render in interface Renderable
Overrides:
render in class AbstractControl
Parameters:
buffer - the buffer to render output to

toString

public String toString()
Render the HTML representation of the paginator.

Overrides:
toString in class AbstractControl
Returns:
the HTML representation of the paginator

renderPagingLinkContainer

protected void renderPagingLinkContainer(HtmlStringBuffer buffer,
                                         int pageNumber)
Render the page link container.

Parameters:
buffer - the buffer to render to
pageNumber - the page number of the page link to render

renderPagingLink

protected void renderPagingLink(HtmlStringBuffer buffer,
                                int pageNumber)
Render the page link for the given page number.

Parameters:
buffer - the buffer to render to
pageNumber - the page number of the page link to render

renderPagingLinkSeparator

protected void renderPagingLinkSeparator(HtmlStringBuffer buffer)
Render a separator between page links.

Parameters:
buffer - the buffer to render to

renderFirst

protected void renderFirst(HtmlStringBuffer buffer)
Render the first paginator link.

Parameters:
buffer - the buffer to render to

renderPrevious

protected void renderPrevious(HtmlStringBuffer buffer)
Render the previous paginator link.

Parameters:
buffer - the buffer to render to

renderLast

protected void renderLast(HtmlStringBuffer buffer)
Render the last paginator link.

Parameters:
buffer - the buffer to render to

renderNext

protected void renderNext(HtmlStringBuffer buffer)
Render the next paginator link.

Parameters:
buffer - the buffer to render to

calcLowerAndUpperBound

protected void calcLowerAndUpperBound()
Calculate the lowerBound and upperBound values.