org.apache.beehive.netui.databinding.datagrid.api.pager
Class PagerModel

Object
  extended by PagerModel
All Implemented Interfaces:
Serializable

public class PagerModel
extends Object
implements Serializable

The PagerModel is a JavaBean that represents the page state of a data grid. In the default implementation, the page state consists of three pieces of data:

This pager model implementation is row based which means that the notion of the current page is based on which row is at the top of a page. Row numbering starts at zero and continues to page size. For example, in a data grid on its first page and with a page size of 10, the rows 0-9 will be displayed. The next page would contain rows 10-11 and so on.

The pager model provides JavaBean-style access to the properties of a pager. In addition, it provides read-only access to information about the row to use in order to navigate to a specific page. To navigate to the previous page, the getRowForPreviousPage() will return the row number that will appear at the top of the previous page. In order to build effective paging UI, it is also often useful to know the absolute page number. As with row numbers, page numbers are zero based. For example, if a data set displayed in a data grid has 30 records and the grid is on page a page displaying rows 10-19, the current page is 1. When displaying this value in UI, it is often useful to display it as:

     Page 2 of 3
 
Random page access can also be accomplished using the encodeRowForPage(int) method which will return the row number to display when jumping to a specific page in a grid.

See Also:
Serialized Form

Field Summary
static int DEFAULT_PAGE_SIZE
           
static int DEFAULT_ROW
           
 
Constructor Summary
PagerModel()
          Default constructor.
 
Method Summary
 int encodeRowForPage(int page)
          Get the row needed to jump to the given page
 int getDataSetSize()
          Set the data set size.
 int getDefaultPageSize()
          Get the default page size.
 int getFirstPage()
          Get the page number of the first page.
 int getLastPage()
          Get the page number for the last page.
 int getLastRowForPage()
           Get the last row for the current page of data.
 int getNextPage()
          Get the page number for the next page.
 int getPage()
          Get the page number given the current page size and current row.
 String getPageAction()
          Get the action used when building URLs for navigating to another page.
 int getPageCount()
          Get the total number of pages.
 String getPageHref()
          Get the href used when building URLs for navigating to another page.
 int getPageSize()
          Get the current page size.
 int getPreviousPage()
          Get the page number of the previous page.
 int getRow()
          Get the current row.
 int getRowForFirstPage()
          Get the row used to display the first page.
 int getRowForLastPage()
          Get the row used to display the last page.
 int getRowForNextPage()
          Get the row used to display the next page.
 int getRowForPreviousPage()
          Get the row used to display the previous page.
 void setDataSetSize(int dataSetSize)
          Set the data set size.
 void setDefaultPageSize(int pageSize)
          Set the default page size.
 void setPage(int page)
          Set a specific page.
 void setPageAction(String pageAction)
          Set the action used to navigate to another page.
 void setPageHref(String pageHref)
          Set the href used to navigate to another page.
 void setPageSize(int pageSize)
          Sets the page size and overrides the default page size if one has been set.
 void setRow(int row)
          Set the current row.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PAGE_SIZE

public static final int DEFAULT_PAGE_SIZE
See Also:
Constant Field Values

DEFAULT_ROW

public static final int DEFAULT_ROW
See Also:
Constant Field Values
Constructor Detail

PagerModel

public PagerModel()
Default constructor. This initializes the current row to the default row value DEFAULT_ROW.

Method Detail

getPageAction

public String getPageAction()
Get the action used when building URLs for navigating to another page.

Returns:
the action name or null if no action name is set

setPageAction

public void setPageAction(String pageAction)
Set the action used to navigate to another page.

Parameters:
pageAction - the action name

getPageHref

public String getPageHref()
Get the href used when building URLs for navigating to another page.

Returns:
the href or null if no href is set

setPageHref

public void setPageHref(String pageHref)
Set the href used to navigate to another page.

Parameters:
pageHref - the href

getDefaultPageSize

public int getDefaultPageSize()
Get the default page size. If no page size has been set via setDefaultPageSize(int) this value is DEFAULT_PAGE_SIZE

Returns:
the default page size

setDefaultPageSize

public void setDefaultPageSize(int pageSize)
Set the default page size. The default page size is used when no other page size has been set and is useful when clients wish to occasionally override the page size but wish to have the default page size set differently than the PagerModel's default.

Parameters:
pageSize - the new page size
Throws:
IllegalArgumentException - if the page size is less than 1

getDataSetSize

public int getDataSetSize()
Set the data set size. In order to calculate paging state for the last page such as the state returned for getRowForLastPage() the default PagerModel implementation must know the total size of the data set.

Returns:
the size

setDataSetSize

public void setDataSetSize(int dataSetSize)
Set the data set size.

Parameters:
dataSetSize - the size

getPageSize

public int getPageSize()
Get the current page size.

Returns:
the page size

setPageSize

public void setPageSize(int pageSize)
Sets the page size and overrides the default page size if one has been set.

Parameters:
pageSize - the specific page size

getPage

public int getPage()
Get the page number given the current page size and current row. The page number is zero based and should be adjusted by one when being displayed to users.

Returns:
the page number

setPage

public void setPage(int page)
Set a specific page. This will change the current row to match the given page value.

Parameters:
page - the new page
Throws:
IllegalArgumentException - if the given page is less than zero

getRow

public int getRow()
Get the current row. If no row has been specified, the default row is returned.

Returns:
the current row

setRow

public void setRow(int row)
Set the current row.

Parameters:
row - the new row
Throws:
IllegalArgumentException - if the given row is less than zero

getLastRowForPage

public int getLastRowForPage()

Get the last row for the current page of data. This value is useful when displaying paging UI like:

   Row 11 through 20 of 60
 
The last row on the page is returned as a zero-based number from the beginning of the data set. In the case above, the value returned is 19 and is converted to 20 for readability by adding one. If the current page is only partially filled, this method will return the value for a partial page. For example, with a data set of size 4 on a page of size 10, the value 3 would be returned.

Returns:
the last row for the current page

getRowForFirstPage

public int getRowForFirstPage()
Get the row used to display the first page.

Returns:
the row for the first page

getRowForPreviousPage

public int getRowForPreviousPage()
Get the row used to display the previous page. Note, a return value of less than zero means that the previous page does not exist as it would scroll off the beginning of the data set and is invalid.

Returns:
the row for the previous page

getRowForNextPage

public int getRowForNextPage()
Get the row used to display the next page. Note, if this value is greater than the size of the data set it would scroll off the end of the data set and is invalid.

Returns:
the row for the previous page

getRowForLastPage

public int getRowForLastPage()
Get the row used to display the last page. This requires tha the data set size has been set via

Returns:
the row for the last page
Throws:
IllegalStateException - when the size of the data set has not been set

encodeRowForPage

public int encodeRowForPage(int page)
Get the row needed to jump to the given page

Parameters:
page - the new page
Returns:
the row used to jump to the new page
Throws:
IllegalArgumentException - if the given page value is less than zero

getPageCount

public int getPageCount()
Get the total number of pages. This value is useful when displaying the total number of pages in UI like:
   Page 4 of 10
 
This method returns an absolute count of the number of pages which could be displayed given the size of the data set and the current page size. This method requires the PagerModel know the total size of the data set.

Returns:
the number of pages
Throws:
IllegalStateException - when the size of the data set has not been set

getFirstPage

public int getFirstPage()
Get the page number of the first page.

Returns:
the first page

getPreviousPage

public int getPreviousPage()
Get the page number of the previous page.

Returns:
the previous page

getNextPage

public int getNextPage()
Get the page number for the next page.

Returns:
the next page

getLastPage

public int getLastPage()
Get the page number for the last page.

Returns:
the last page