use of org.apache.wicket.markup.repeater.data.ListDataProvider in project gitblit by gitblit.
the class MyTicketsPage method buildPager.
protected void buildPager(final String query, final String milestone, final String[] states, final String assignedTo, final String sort, final boolean desc, final String repositoryId, final int page, int pageSize, int count, int total) {
boolean showNav = total > (2 * pageSize);
boolean allowPrev = page > 1;
boolean allowNext = (pageSize * (page - 1) + count) < total;
add(new BookmarkablePageLink<Void>("prevLink", MyTicketsPage.class, queryParameters(query, milestone, states, assignedTo, sort, desc, repositoryId, page - 1)).setEnabled(allowPrev).setVisible(showNav));
add(new BookmarkablePageLink<Void>("nextLink", MyTicketsPage.class, queryParameters(query, milestone, states, assignedTo, sort, desc, repositoryId, page + 1)).setEnabled(allowNext).setVisible(showNav));
if (total <= pageSize) {
add(new Label("pageLink").setVisible(false));
return;
}
// determine page numbers to display
int pages = count == 0 ? 0 : ((total / pageSize) + (total % pageSize == 0 ? 0 : 1));
// preferred number of pagelinks
int segments = 5;
if (pages < segments) {
// not enough data for preferred number of page links
segments = pages;
}
int minpage = Math.min(Math.max(1, page - 2), pages - (segments - 1));
int maxpage = Math.min(pages, minpage + (segments - 1));
List<Integer> sequence = new ArrayList<Integer>();
for (int i = minpage; i <= maxpage; i++) {
sequence.add(i);
}
ListDataProvider<Integer> pagesDp = new ListDataProvider<Integer>(sequence);
DataView<Integer> pagesView = new DataView<Integer>("pageLink", pagesDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<Integer> item) {
final Integer i = item.getModelObject();
LinkPanel link = new LinkPanel("page", null, "" + i, MyTicketsPage.class, queryParameters(query, milestone, states, assignedTo, sort, desc, repositoryId, i));
link.setRenderBodyOnly(true);
if (i == page) {
WicketUtils.setCssClass(item, "active");
}
item.add(link);
}
};
add(pagesView);
}
Aggregations