Class Pager


  • public class Pager
    extends Object
    Author:
    Kir This class is the model for Pager, i.e. it maintains current page and allows to get records for the current page.
    • Constructor Detail

      • Pager

        public Pager​(int recordsPerPage)
        Parameters:
        recordsPerPage - records per page for this pager
    • Method Detail

      • setRecordsPerPage

        public void setRecordsPerPage​(int recordsPerPage)
        Set number of records per page. Value -1 means unlimited number of records
        Parameters:
        recordsPerPage - see above
      • setNumberOfRecords

        public void setNumberOfRecords​(int totalRecords)
        Set total number of records in collection to be paged
        Parameters:
        totalRecords - total number of records
      • setCurrentPage

        public void setCurrentPage​(int page)
        Page numbers are started with 1
        Parameters:
        page - current page, starting from 1
      • setCurrentPageFromRecord

        public int setCurrentPageFromRecord​(int recordIdx)
        Computes page containing record with specified index and sets this page as current.
        Parameters:
        recordIdx - index of a record, starting from zero
        Returns:
        index of the record on the selected page
      • getCurrentPage

        public int getCurrentPage()
        Page numbers are started with 1
        Returns:
        current page number
      • isLastPage

        public boolean isLastPage()
      • getRecordsPerPage

        public int getRecordsPerPage()
        Returns:
        number of records per page
      • getTotalRecords

        public int getTotalRecords()
        Returns:
        total number of records per page
      • getCurrentPageData

        public <T> List<T> getCurrentPageData​(List<T> data)
        Parameters:
        data - original collection of records (all of them)
        Returns:
        sublist of the data with information for the current page
      • getLastIndex

        public int getLastIndex()
      • getFirstIndex

        public int getFirstIndex()
      • getPageCount

        public int getPageCount()
        Returns:
        total number of pages, according to total number of records and records per page
      • isPreviousPageExists

        public boolean isPreviousPageExists()
        Returns:
        true if there is a previous page
      • isNextPageExists

        public boolean isNextPageExists()
        Returns:
        true if there is a next page
      • getVisiblePages

        public int[] getVisiblePages()
        Returns:
        numbers of visible pages (helper method on Web UI)
      • isUnknownNumberOfRecords

        public boolean isUnknownNumberOfRecords()
        Returns:
        true if actual total number of records is bigger than the total number of records set to this pager
      • setUnknownNumberOfRecords

        public void setUnknownNumberOfRecords​(boolean unknownNumberOfRecords)
        Set to true if current total number of records is smaller than the actual number of records
        Parameters:
        unknownNumberOfRecords - true in case of a pager with open interval and false otherwise (default)