Search in sources :

Example 11 with ListDataProvider

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);
}
Also used : ListDataProvider(org.apache.wicket.markup.repeater.data.ListDataProvider) Label(org.apache.wicket.markup.html.basic.Label) ArrayList(java.util.ArrayList) LinkPanel(com.gitblit.wicket.panels.LinkPanel) DataView(org.apache.wicket.markup.repeater.data.DataView) Item(org.apache.wicket.markup.repeater.Item)

Aggregations

Label (org.apache.wicket.markup.html.basic.Label)11 Item (org.apache.wicket.markup.repeater.Item)11 DataView (org.apache.wicket.markup.repeater.data.DataView)11 ListDataProvider (org.apache.wicket.markup.repeater.data.ListDataProvider)11 LinkPanel (com.gitblit.wicket.panels.LinkPanel)6 ArrayList (java.util.ArrayList)6 Fragment (org.apache.wicket.markup.html.panel.Fragment)5 UserModel (com.gitblit.models.UserModel)4 TicketLabel (com.gitblit.tickets.TicketLabel)3 Component (org.apache.wicket.Component)3 PageParameters (org.apache.wicket.PageParameters)3 ParameterMenuItem (com.gitblit.models.Menu.ParameterMenuItem)2 RepositoryModel (com.gitblit.models.RepositoryModel)2 RepositoryUrl (com.gitblit.models.RepositoryUrl)2 AccessPermission (com.gitblit.Constants.AccessPermission)1 SearchType (com.gitblit.Constants.SearchType)1 GitClientApplication (com.gitblit.models.GitClientApplication)1 PathChangeModel (com.gitblit.models.PathModel.PathChangeModel)1 ProjectModel (com.gitblit.models.ProjectModel)1 RefLogEntry (com.gitblit.models.RefLogEntry)1