Author: fdesbois Date: 2010-03-09 12:50:12 +0100 (Tue, 09 Mar 2010) New Revision: 2908 Log: Add some javadoc for Pager Modified: branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java Modified: branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java =================================================================== --- branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java 2010-03-09 11:39:25 UTC (rev 2907) +++ branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java 2010-03-09 11:50:12 UTC (rev 2908) @@ -24,12 +24,23 @@ */ public class Pager { + /** + * Number of total rows. + */ @Parameter(required = true) private int nbTotalRows; + /** + * Main element of the pager, the page which contains the pager have + * to manage this property (using @Persist for exemple) to ensure that + * the pager will done its work correctly. + */ @Parameter(required = true) private int currentPage; + /** + * Number of rows to show per page. + */ @Parameter(required = true) private int nbRowsPerPage; @@ -70,6 +81,15 @@ } + /** + * Use an action event to change the current page. The link refresh the + * entire page, no zone is managed yet. + * + * @param writer used to write a element + * @param index new page to change (argument of onAction method) + * @param text to write inside the a tag + * @param style of the css (class) for the a tag + */ protected void writeLink(MarkupWriter writer, int index, String text, String style) { Link link = resources.createEventLink(EventConstants.ACTION, @@ -79,10 +99,20 @@ writer.end(); } + /** + * Get the start index of the range shown. + * + * @return the start index for elements to show + */ public int getStartIndex() { return ( (currentPage - 1) * nbRowsPerPage); } + /** + * Get the end index of the range shown. + * + * @return the end index for elements to show + */ public int getEndIndex() { int end = (currentPage * nbRowsPerPage) - 1; if (end >= nbTotalRows) { @@ -91,22 +121,38 @@ return end; } - public int getFirstValue() { + protected int getFirstValue() { return getStartIndex() + 1; } - public int getLastValue() { + protected int getLastValue() { return getEndIndex() + 1; } + /** + * Test if there is previous elements before this actual range. + * + * @return true if there is previous elements, false otherwise + */ public boolean hasPrevious() { return getStartIndex() > 0; } + /** + * Test if there is next elements after this actual range. + * + * @return true if there is next elements, false otherwise + */ public boolean hasNext() { return getEndIndex() < (nbTotalRows - 1); } + /** + * Action event for changing page. The currentPage is changed to + * {@code newPage}. + * + * @param newPage to set + */ void onAction(int newPage) { currentPage = newPage; }