/** * Get the number of pages based on the data size. * * @return the page count, or -1 if the display is not set */ protected int getPageCount() { if (display == null) { return -1; } int pageSize = getPageSize(); return (display.getRowCount() + pageSize - 1) / pageSize; }
/** * Returns true if there is enough data such that the specified page is within * range. * * @param index the page index * @return true if the specified page is in range */ protected boolean hasPage(int index) { return display == null ? false : getPageSize() * index < display.getRowCount(); }
/** * Returns true if there is enough data such that a call to * {@link #previousPage()} will succeed in moving the starting point of the * table backward. * * @return true if there is a previous page */ protected boolean hasPreviousPage() { return display == null ? false : getPageStart() > 0 && display.getRowCount() > 0; }
/** * Set the page start to the last index that will still show a full page. */ protected void lastPageStart() { if (display != null) { setPageStart(display.getRowCount() - getPageSize()); } }
/** * Returns true if there is enough data such that a call to * {@link #nextPage()} will succeed in moving the starting point of the table * forward. * * @return true if there is a next page */ protected boolean hasNextPage() { if (display == null || display.getRowCount() == 0) { return false; } else if (!display.isRowCountExact()) { return true; } Range range = display.getVisibleRange(); return range.getStart() + range.getLength() < display.getRowCount(); }
/** * Set the page size of the display. * * @param pageSize the new page size * @see #getPageSize() */ protected void setPageSize(int pageSize) { if (display != null) { Range range = display.getVisibleRange(); int pageStart = range.getStart(); if (isRangeLimited && display.isRowCountExact()) { pageStart = Math.min(pageStart, display.getRowCount() - pageSize); } pageStart = Math.max(0, pageStart); display.setVisibleRange(pageStart, pageSize); } }
/** * Returns true if there is enough data to display a given number of * additional pages. * * @param pages the number of pages to query * @return true if there are {@code pages} next pages */ protected boolean hasNextPages(int pages) { if (display == null) { return false; } Range range = display.getVisibleRange(); return range.getStart() + pages * range.getLength() < display.getRowCount(); }
/** * Called when the row count changes. Only called if display is non-null. * * @param rowCount the new row count * @param isExact true if the row count is exact */ private void handleRowCountChange(int rowCount, boolean isExact) { int oldRowCount = lastRowCount; lastRowCount = display.getRowCount(); // If the row count has changed, limit the range. if (isRangeLimited && oldRowCount != lastRowCount) { setPageStart(getPageStart()); } // Call user methods. onRangeOrRowCountChanged(); } }
/** * Set the page start index. * * @param index the index * @see #getPageStart() */ protected void setPageStart(int index) { if (display != null) { Range range = display.getVisibleRange(); int pageSize = range.getLength(); if (isRangeLimited && display.isRowCountExact()) { index = Math.min(index, display.getRowCount() - pageSize); } index = Math.max(0, index); if (index != range.getStart()) { display.setVisibleRange(index, pageSize); } } }
@Override public void setDisplay(HasRows display) { // Enable or disable all buttons. boolean disableButtons = (display == null || display.getRowCount() == 0); setFastForwardDisabled(disableButtons); setNextPageButtonsDisabled(disableButtons); setPrevPageButtonsDisabled(disableButtons); super.setDisplay(display); }
public void onClick(ClickEvent event) { // Display should be non-null, but we check defensively. HasRows display = getDisplay(); if (display != null) { Range range = display.getVisibleRange(); int pageSize = Math.min(range.getLength() + increment, display.getRowCount() + (display.isRowCountExact() ? 0 : increment)); display.setVisibleRange(range.getStart(), pageSize); } } });
/** * Get the text to display in the pager that reflects the state of the pager. * * @return the text */ protected String createText() { // Default text is 1 based. NumberFormat formatter = NumberFormat.getFormat("#,###"); HasRows display = getDisplay(); Range range = display.getVisibleRange(); int pageStart = range.getStart() + 1; int pageSize = range.getLength(); int dataSize = display.getRowCount(); int endIndex = Math.min(dataSize, pageStart + pageSize - 1); endIndex = Math.max(pageStart, endIndex); boolean exact = display.isRowCountExact(); return formatter.format(pageStart) + "-" + formatter.format(endIndex) + (exact ? " of " : " of over ") + formatter.format(dataSize); }
@Override protected void onRangeOrRowCountChanged() { // Assumes a page start index of 0. HasRows display = getDisplay(); int pageSize = display.getVisibleRange().getLength(); boolean hasLess = pageSize > increment; boolean hasMore = !display.isRowCountExact() || pageSize < display.getRowCount(); showLessButton.setVisible(hasLess); showMoreButton.setVisible(hasMore); layout.setText(0, 1, (hasLess && hasMore) ? " | " : ""); }
/** * Returns true if there is enough data such that the specified page is within * range. * * @param index the page index * @return true if the specified page is in range */ protected boolean hasPage(int index) { return display == null ? false : getPageSize() * index < display.getRowCount(); }
/** * Get the number of pages based on the data size. * * @return the page count, or -1 if the display is not set */ protected int getPageCount() { if (display == null) { return -1; } int pageSize = getPageSize(); return (display.getRowCount() + pageSize - 1) / pageSize; }
/** * Returns true if there is enough data such that the specified page is within * range. * * @param index the page index * @return true if the specified page is in range */ protected boolean hasPage(int index) { return display == null ? false : getPageSize() * index < display.getRowCount(); }
/** * Returns true if there is enough data such that a call to * {@link #previousPage()} will succeed in moving the starting point of the * table backward. * * @return true if there is a previous page */ protected boolean hasPreviousPage() { return display == null ? false : getPageStart() > 0 && display.getRowCount() > 0; }
/** * Set the page start to the last index that will still show a full page. */ protected void lastPageStart() { if (display != null) { setPageStart(display.getRowCount() - getPageSize()); } }
@Override public void setDisplay(HasRows display) { // Enable or disable all buttons. boolean disableButtons = (display == null || display.getRowCount() == 0); setFastForwardDisabled(disableButtons); setNextPageButtonsDisabled(disableButtons); setPrevPageButtonsDisabled(disableButtons); super.setDisplay(display); }
public void onClick(ClickEvent event) { // Display should be non-null, but we check defensively. HasRows display = getDisplay(); if (display != null) { Range range = display.getVisibleRange(); int pageSize = Math.min(range.getLength() + increment, display.getRowCount() + (display.isRowCountExact() ? 0 : increment)); display.setVisibleRange(range.getStart(), pageSize); } } });