Example usage for org.apache.wicket.markup.html.navigation.paging IPageable getPageCount

List of usage examples for org.apache.wicket.markup.html.navigation.paging IPageable getPageCount

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.navigation.paging IPageable getPageCount.

Prototype

long getPageCount();

Source Link

Document

Gets the total number of pages this pageable object has.

Usage

From source file:com.doculibre.constellio.wicket.paging.ConstellioFacetsPagingNavigator.java

License:Open Source License

@Override
protected Link newPagingNavigationIncrementLink(String id, final IPageable pageable, final int increment) {
    SimpleSearch simpleSearch = dataProvider.getSimpleSearch();
    SimpleSearch clone = simpleSearch.clone();
    int page = clone.getFacetPage(facetName);
    int newPage = page + increment;
    clone.setFacetPage(facetName, newPage);

    PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class);
    return new BookmarkablePageLink(id, pageFactoryPlugin.getSearchResultsPage(),
            SearchResultsPage.getParameters(clone)) {
        public boolean isEnabled() {
            return super.isEnabled() && ConstellioFacetsPagingNavigator.this.isEnabled()
                    && ConstellioFacetsPagingNavigator.this.isEnableAllowed();
        }/*  w  w  w  . j  a  v a 2s. com*/

        /**
         * Returns true if the page link links to the given page.
         * 
         * @param page
         *            ignored
         * @return True if this link links to the given page
         * @see org.apache.wicket.markup.html.link.PageLink#linksTo(org.apache.wicket.Page)
         */
        public boolean linksTo(final Page page) {
            pageable.getCurrentPage();
            return ((increment < 0) && isFirst()) || ((increment > 0) && isLast());
        }

        /**
         * @return True if it is referring to the first page of the underlying PageableListView.
         */
        public boolean isFirst() {
            int currentPage = pageable.getCurrentPage();
            return currentPage <= 0;
        }

        /**
         * @return True if it is referring to the last page of the underlying PageableListView.
         */
        public boolean isLast() {
            int currentPage = pageable.getCurrentPage();
            return currentPage >= (pageable.getPageCount() - 1);
        }

        @Override
        public boolean isVisible() {
            return super.isVisible() && isEnabled();
        }
    }.setAutoEnable(true);
}

From source file:com.doculibre.constellio.wicket.paging.ConstellioFacetsPagingNavigator.java

License:Open Source License

@Override
protected Link newPagingNavigationLink(String id, final IPageable pageable, final int pageNumber) {
    SimpleSearch simpleSearch = dataProvider.getSimpleSearch();

    SimpleSearch clone = simpleSearch.clone();
    if (pageNumber == -1) {
        clone.setFacetPage(facetName, pageable.getPageCount() - 1);
    } else {//from   ww w . ja  v a 2 s  .  c om
        clone.setFacetPage(facetName, pageNumber);
    }

    PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class);
    return new BookmarkablePageLink(id, pageFactoryPlugin.getSearchResultsPage(),
            SearchResultsPage.getParameters(clone)) {
        public boolean isEnabled() {
            return super.isEnabled() && ConstellioFacetsPagingNavigator.this.isEnabled()
                    && ConstellioFacetsPagingNavigator.this.isEnableAllowed();
        }

        /**
         * Returns true if this PageableListView navigation link links to the given page.
         * 
         * @param page
         *            The page
         * @return True if this link links to the given page
         * @see org.apache.wicket.markup.html.link.PageLink#linksTo(org.apache.wicket.Page)
         */
        public final boolean linksTo(final Page page) {
            return pageNumber == pageable.getCurrentPage();
        }

        @Override
        public boolean isVisible() {
            return super.isVisible() && (this.isEnabled() || linksTo(getPage()));
        }
    }.setAutoEnable(true);
}

From source file:com.doculibre.constellio.wicket.paging.ConstellioPagingNavigator.java

License:Open Source License

@Override
protected Link newPagingNavigationIncrementLink(String id, final IPageable pageable, final int increment) {
    DataView dataView = (DataView) pageable;
    SimpleSearch simpleSearch;//  ww  w .j ava2s .co m
    if (dataView.getDataProvider() instanceof FacetsDataProvider) {
        FacetsDataProvider dataProvider = (FacetsDataProvider) dataView.getDataProvider();
        simpleSearch = dataProvider.getSimpleSearch();
    } else {
        SearchResultsDataProvider dataProvider = (SearchResultsDataProvider) dataView.getDataProvider();
        simpleSearch = dataProvider.getSimpleSearch();
    }
    SimpleSearch clone = simpleSearch.clone();
    int page = clone.getPage();
    int newPage = page + increment;
    clone.setPage(newPage);

    PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class);
    return new BookmarkablePageLink(id, pageFactoryPlugin.getSearchResultsPage(),
            SearchResultsPage.getParameters(clone)) {
        public boolean isEnabled() {
            return super.isEnabled() && ConstellioPagingNavigator.this.isEnabled()
                    && ConstellioPagingNavigator.this.isEnableAllowed();
        }

        /**
         * Returns true if the page link links to the given page.
         * 
         * @param page
         *            ignored
         * @return True if this link links to the given page
         * @see org.apache.wicket.markup.html.link.PageLink#linksTo(org.apache.wicket.Page)
         */
        public boolean linksTo(final Page page) {
            pageable.getCurrentPage();
            return ((increment < 0) && isFirst()) || ((increment > 0) && isLast());
        }

        /**
         * @return True if it is referring to the first page of the underlying PageableListView.
         */
        public boolean isFirst() {
            return pageable.getCurrentPage() <= 0;
        }

        /**
         * @return True if it is referring to the last page of the underlying PageableListView.
         */
        public boolean isLast() {
            return pageable.getCurrentPage() >= (pageable.getPageCount() - 1);
        }

        @Override
        public boolean isVisible() {
            return super.isVisible() && isEnabled();
        }
    }.setAutoEnable(true);
}

From source file:com.doculibre.constellio.wicket.paging.ConstellioPagingNavigator.java

License:Open Source License

@Override
protected Link newPagingNavigationLink(String id, final IPageable pageable, final int pageNumber) {
    DataView dataView = (DataView) pageable;
    SimpleSearch simpleSearch;/*from   w w  w .j  a  v a2 s  .  co  m*/
    if (dataView.getDataProvider() instanceof FacetsDataProvider) {
        FacetsDataProvider dataProvider = (FacetsDataProvider) dataView.getDataProvider();
        simpleSearch = dataProvider.getSimpleSearch();
    } else {
        SearchResultsDataProvider dataProvider = (SearchResultsDataProvider) dataView.getDataProvider();
        simpleSearch = dataProvider.getSimpleSearch();
    }
    SimpleSearch clone = simpleSearch.clone();
    if (pageNumber == -1) {
        clone.setPage(pageable.getPageCount() - 1);
    } else {
        clone.setPage(pageNumber);
    }

    PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class);
    return new BookmarkablePageLink(id, pageFactoryPlugin.getSearchResultsPage(),
            SearchResultsPage.getParameters(clone)) {
        public boolean isEnabled() {
            boolean enabled = super.isEnabled() && ConstellioPagingNavigator.this.isEnabled()
                    && ConstellioPagingNavigator.this.isEnableAllowed();
            if (enabled) {
                int currentPage = pageable.getCurrentPage();
                if (!"first".equals(getId()) && !"last".equals(getId()) && currentPage == pageNumber) {
                    enabled = false;
                }
            }
            return enabled;
        }

        @Override
        public boolean isVisible() {
            boolean visible = super.isVisible();
            if (visible) {
                int currentPage = pageable.getCurrentPage();
                int pageCount = pageable.getPageCount();
                if ("first".equals(getId()) && currentPage == 0) {
                    visible = false;
                } else if ("last".equals(getId()) && currentPage == (pageCount - 1)) {
                    visible = false;
                }
            }
            return visible;
        }
    };
}

From source file:com.marc.lastweek.web.components.paginator.VerticalFancyPaginator.java

License:Open Source License

public VerticalFancyPaginator(String id, final IPageable pageableList) {
    super(id);//from w ww .j  a v a2s  . c  o  m

    this.setOutputMarkupId(true);

    System.out.println("current: " + pageableList.getCurrentPage());

    WebMarkupContainer paginatorBox = new WebMarkupContainer("paginatorBox") {
        private static final long serialVersionUID = -8245214604885147260L;

        @Override
        public boolean isVisible() {
            return pageableList.getPageCount() > 1;
        }
    };
    this.add(paginatorBox);

    PagingNavigationLink firstPageLink = new PagingNavigationLink("firstPageLink", pageableList, 0);
    paginatorBox.add(firstPageLink);
    PagingNavigationLink lastPageLink = new PagingNavigationLink("lastPageLink", pageableList,
            pageableList.getPageCount() - 1);
    lastPageLink.add(new Label("lastPageLabel", new Model(Integer.valueOf(pageableList.getPageCount()))));
    paginatorBox.add(lastPageLink);

    // Before current page
    WebMarkupContainer beforeCurrenPageItem = new WebMarkupContainer("beforeCurrentPageItem") {
        private static final long serialVersionUID = -5876391261093967497L;

        @Override
        public boolean isVisible() {
            return pageableList.getCurrentPage() >= 2;
        }
    };
    beforeCurrenPageItem.setOutputMarkupPlaceholderTag(true);
    PagingNavigationIncrementLink beforeCurrentPageLink = new PagingNavigationIncrementLink(
            "beforeCurrentPageLink", pageableList, -1);
    beforeCurrentPageLink.add(new Label("beforeCurrentPageLabel", new LoadableDetachableModel() {
        private static final long serialVersionUID = -3157979806031118522L;

        @Override
        protected Object load() {
            return Integer.valueOf(pageableList.getCurrentPage());
        }
    }));
    beforeCurrenPageItem.add(beforeCurrentPageLink);
    paginatorBox.add(beforeCurrenPageItem);

    // Current page
    WebMarkupContainer currenPageItem = new WebMarkupContainer("currentPageItem") {
        private static final long serialVersionUID = -9186596865047783422L;

        @Override
        public boolean isVisible() {
            return pageableList.getCurrentPage() >= 1
                    && pageableList.getCurrentPage() != pageableList.getPageCount() - 1;
        }
    };
    currenPageItem.setOutputMarkupPlaceholderTag(true);
    currenPageItem.add(new Label("currentPageLabel", new LoadableDetachableModel() {
        private static final long serialVersionUID = 393829273382282502L;

        @Override
        protected Object load() {
            return Integer.valueOf(pageableList.getCurrentPage() + 1);
        }
    }));
    paginatorBox.add(currenPageItem);

    // After CurrentPage
    WebMarkupContainer afterCurrenPageItem = new WebMarkupContainer("afterCurrentPageItem") {
        private static final long serialVersionUID = 7079913736005869990L;

        @Override
        public boolean isVisible() {
            return pageableList.getCurrentPage() < (pageableList.getPageCount() - 2);
        }
    };
    afterCurrenPageItem.setOutputMarkupPlaceholderTag(true);
    PagingNavigationIncrementLink afterCurrentPageLink = new PagingNavigationIncrementLink(
            "afterCurrentPageLink", pageableList, 1);
    afterCurrentPageLink.add(new Label("afterCurrentPageLabel", new LoadableDetachableModel() {
        private static final long serialVersionUID = 8932718471553075655L;

        @Override
        protected Object load() {
            return Integer.valueOf(pageableList.getCurrentPage() + 2);
        }
    }));
    afterCurrenPageItem.add(afterCurrentPageLink);
    paginatorBox.add(afterCurrenPageItem);

    // Two After CurrentPage
    WebMarkupContainer twoAfterCurrenPageItem = new WebMarkupContainer("twoAfterCurrentPageItem") {
        private static final long serialVersionUID = 572789655450253585L;

        @Override
        public boolean isVisible() {
            return pageableList.getCurrentPage() < (pageableList.getPageCount() - 3);
        }
    };
    twoAfterCurrenPageItem.setOutputMarkupPlaceholderTag(true);
    PagingNavigationIncrementLink twoAfterCurrentPageLink = new PagingNavigationIncrementLink(
            "twoAfterCurrentPageLink", pageableList, 2);
    twoAfterCurrentPageLink.add(new Label("twoAfterCurrentPageLabel", new LoadableDetachableModel() {
        private static final long serialVersionUID = 8932718471553075655L;

        @Override
        protected Object load() {
            return Integer.valueOf(pageableList.getCurrentPage() + 3);
        }
    }));
    twoAfterCurrenPageItem.add(twoAfterCurrentPageLink);
    paginatorBox.add(twoAfterCurrenPageItem);

    // Previous and next links
    WebMarkupContainer previousPageItem = new WebMarkupContainer("previousPageItem") {
        private static final long serialVersionUID = -5827228260699397983L;

        @Override
        public boolean isVisible() {
            return pageableList.getCurrentPage() > 0;
        }
    };
    previousPageItem.add(new PagingNavigationIncrementLink("previousPageLink", pageableList, -1));
    previousPageItem.setOutputMarkupPlaceholderTag(true);
    paginatorBox.add(previousPageItem);

    WebMarkupContainer nextPageItem = new WebMarkupContainer("nextPageItem") {
        private static final long serialVersionUID = -5827228260699397983L;

        @Override
        public boolean isVisible() {
            return pageableList.getCurrentPage() < (pageableList.getPageCount() - 1);
        }
    };
    nextPageItem.add(new PagingNavigationIncrementLink("nextPageLink", pageableList, 1));
    nextPageItem.setOutputMarkupPlaceholderTag(true);
    paginatorBox.add(nextPageItem);
}

From source file:com.norconex.commons.wicket.bootstrap.table.BootstrapAjaxPagingNavigator.java

License:Apache License

@Override
protected AbstractLink newPagingNavigationLink(final String id, IPageable pageable, int pageNumber) {
    final AjaxPagingNavigationLink link = new AjaxPagingNavigationLink(id, pageable, pageNumber) {
        private static final long serialVersionUID = -4537725137974552570L;

        protected long cullPageNumber(long pageNumber) {
            long idx = pageNumber;
            if (id.startsWith("first")) {
                return 0;
            }//from   w  ww .  j  av  a2  s  . c  o  m
            if (id.startsWith("last")) {
                return pageable.getPageCount() - 1;
            }
            if (id.startsWith("prev")) {
                idx = pageable.getCurrentPage() - 1;
            } else if (id.startsWith("next")) {
                idx = pageable.getCurrentPage() + 1;
            }
            if (idx < 0) {
                idx = 0;
            }
            if (idx > (pageable.getPageCount() - 1)) {
                idx = pageable.getPageCount() - 1;
            }
            if (idx < 0) {
                idx = 0;
            }
            return idx;
        }
    };
    AjaxLink<String> navCont = new AjaxLink<String>(id + "Cont") {
        private static final long serialVersionUID = -7566811745303329592L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            link.onClick(target);
        }
    };
    navCont.add(link);

    // add css for enable/disable link
    long pageIndex = pageable.getCurrentPage() + pageNumber;
    navCont.add(new AttributeModifier("class", new BootstrapPageLinkCssModel(pageable, pageIndex, "disabled")));
    return navCont;
}

From source file:com.norconex.commons.wicket.bootstrap.table.BootstrapAjaxPagingNavigator.java

License:Apache License

@Override
protected AbstractLink newPagingNavigationIncrementLink(final String id, IPageable pageable, int increment) {
    final AjaxPagingNavigationLink link = new AjaxPagingNavigationLink(id, pageable, increment) {
        private static final long serialVersionUID = 6737074324471003133L;

        protected long cullPageNumber(long pageNumber) {
            long idx = pageNumber;
            if (id.startsWith("first")) {
                return 0;
            }//w  ww.  j  a  va  2  s. c  o  m
            if (id.startsWith("last")) {
                return pageable.getPageCount() - 1;
            }
            if (id.startsWith("prev")) {
                idx = pageable.getCurrentPage() - 1;
            } else if (id.startsWith("next")) {
                idx = pageable.getCurrentPage() + 1;
            }
            if (idx < 0) {
                idx = 0;
            }
            if (idx > (pageable.getPageCount() - 1)) {
                idx = pageable.getPageCount() - 1;
            }
            if (idx < 0) {
                idx = 0;
            }
            return idx;
        }
    };
    AjaxLink<String> navCont = new AjaxLink<String>(id + "Cont") {
        private static final long serialVersionUID = -7414576817418282720L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            link.onClick(target);
        }
    };
    navCont.add(link);

    // add css for enable/disable link
    long pageIndex = pageable.getCurrentPage() + increment;
    navCont.add(new AttributeModifier("class", new BootstrapPageLinkIncrementCssModel(pageable, pageIndex)));
    return navCont;
}

From source file:jp.xet.uncommons.wicket.gp.BookmarkableNavigator.java

License:Apache License

@Override
protected AbstractLink newPagingNavigationIncrementLink(String id, final IPageable pageable,
        final int increment) {
    int idx = pageable.getCurrentPage() + increment;
    int page = Math.max(0, Math.min(pageable.getPageCount() - 1, idx));
    return new BookmarkablePageLink<Void>(id, getPage().getClass(), getParams(page)) {

        public boolean isLast() {
            return pageable.getCurrentPage() >= (pageable.getPageCount() - 1);
        }/*from   w w w .  j  a  v a2 s .co m*/

        @Override
        public boolean linksTo(final Page page) {
            pageable.getCurrentPage();
            return ((increment < 0) && isFirst()) || ((increment > 0) && isLast());
        }

        private boolean isFirst() {
            return pageable.getCurrentPage() <= 0;
        }
    }.setAutoEnable(true);
}

From source file:jp.xet.uncommons.wicket.gp.BookmarkableNavigator.java

License:Apache License

private int cullPageNumber(int pageNumber) {
    int idx = pageNumber;
    IPageable pageable = getPageable();
    if (idx < 0) {
        idx = pageable.getPageCount() + idx;
    }/*w ww  .  j  ava 2 s  . c  o  m*/
    if (idx > (pageable.getPageCount() - 1)) {
        idx = pageable.getPageCount() - 1;
    }
    if (idx < 0) {
        idx = 0;
    }
    return idx;
}

From source file:jp.xet.uncommons.wicket.gp.StatelessSimplePagingNavigator.java

License:Apache License

/**
 * ??/*ww  w . j  ava 2s. c  o m*/
 * 
 * @param id The non-null id of this component
 * @param clazz
 * @param params
 * @param pageable
 * @param pageKeyName 
 * @param viewsize
 * @param anchorSelf
 * @throws IllegalArgumentException ?{@code null}???
 */
public StatelessSimplePagingNavigator(String id, Class<T> clazz, PageParameters params, IPageable pageable,
        String pageKeyName, int viewsize, boolean anchorSelf) {
    super(id, pageable, viewsize, anchorSelf);
    Args.notNull(clazz, "clazz");
    Args.notNull(pageable, "pageable");
    Args.notNull(pageKeyName, "pageKeyName");

    this.clazz = clazz;
    this.params = params;
    currentPage = pageable.getCurrentPage();
    pageCount = pageable.getPageCount();
    this.pageKeyName = pageKeyName;
    anchor = null;
}