/** * Get the first page link to render. Adjust the first page link based on the current * PageableListView page displayed. */ private void setStartIndex() { // Which startIndex are we currently using long firstListItem = startIndex; // How many page links shall be displayed int viewSize = (int) Math.min(getViewSize(), pageable.getPageCount()); long margin = getMargin(); // What is the PageableListView's page index to be displayed long currentPage = pageable.getCurrentPage(); // Make sure the current page link index is within the current // window taking the left and right margin into account if (currentPage < (firstListItem + margin)) { firstListItem = currentPage - margin; } else if ((currentPage >= (firstListItem + viewSize - margin))) { firstListItem = (currentPage + margin + 1) - viewSize; } // Make sure the first index is >= 0 and the last index is <= // than the last page link index. if ((firstListItem + viewSize) >= pageable.getPageCount()) { firstListItem = pageable.getPageCount() - viewSize; } if (firstListItem < 0) { firstListItem = 0; } if ((viewSize != getIterations()) || (startIndex != firstListItem)) { modelChanging(); // Tell the ListView what the new start index shall be addStateChange(); startIndex = firstListItem; setIterations((int) Math.min(viewSize, pageable.getPageCount())); modelChanged(); // force all children to be re-rendered removeAll(); } }
@Override protected void onConfigure() { super.onConfigure(); setDefaultModel(new Model<Integer>((int) Math.max(Integer.MAX_VALUE, pageable.getPageCount()))); // PagingNavigation itself (as well as the PageableListView) // may have pages. // The index of the first page link depends on the PageableListView's // page currently printed. setStartIndex(); }