Search in sources :

Example 16 with DataView

use of org.apache.wicket.markup.repeater.data.DataView in project gitblit by gitblit.

the class ProjectsPage method setup.

private void setup(PageParameters params) {
    setupPage("", "");
    // check to see if we should display a login message
    boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, true);
    if (authenticateView && !GitBlitWebSession.get().isLoggedIn()) {
        add(new Label("projectsPanel"));
        return;
    }
    List<ProjectModel> projects = getProjects(params);
    Collections.sort(projects);
    ListDataProvider<ProjectModel> dp = new ListDataProvider<ProjectModel>(projects);
    DataView<ProjectModel> dataView = new DataView<ProjectModel>("project", dp) {

        private static final long serialVersionUID = 1L;

        int counter;

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            counter = 0;
        }

        @Override
        public void populateItem(final Item<ProjectModel> item) {
            final ProjectModel entry = item.getModelObject();
            PageParameters pp = WicketUtils.newProjectParameter(entry.name);
            item.add(new LinkPanel("projectTitle", "list", entry.getDisplayName(), ProjectPage.class, pp));
            item.add(new LinkPanel("projectDescription", "list", entry.description, ProjectPage.class, pp));
            item.add(new Label("repositoryCount", entry.repositories.size() + " " + (entry.repositories.size() == 1 ? getString("gb.repository") : getString("gb.repositories"))));
            String lastChange;
            if (entry.lastChange.getTime() == 0) {
                lastChange = "--";
            } else {
                lastChange = getTimeUtils().timeAgo(entry.lastChange);
            }
            Label lastChangeLabel = new Label("projectLastChange", lastChange);
            item.add(lastChangeLabel);
            WicketUtils.setCssClass(lastChangeLabel, getTimeUtils().timeAgoCss(entry.lastChange));
            WicketUtils.setAlternatingBackground(item, counter);
            counter++;
        }
    };
    add(dataView);
}
Also used : ListDataProvider(org.apache.wicket.markup.repeater.data.ListDataProvider) Label(org.apache.wicket.markup.html.basic.Label) PageParameters(org.apache.wicket.PageParameters) LinkPanel(com.gitblit.wicket.panels.LinkPanel) DataView(org.apache.wicket.markup.repeater.data.DataView) ParameterMenuItem(com.gitblit.models.Menu.ParameterMenuItem) Item(org.apache.wicket.markup.repeater.Item) ProjectModel(com.gitblit.models.ProjectModel)

Example 17 with DataView

use of org.apache.wicket.markup.repeater.data.DataView 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

Item (org.apache.wicket.markup.repeater.Item)17 DataView (org.apache.wicket.markup.repeater.data.DataView)17 Label (org.apache.wicket.markup.html.basic.Label)15 ListDataProvider (org.apache.wicket.markup.repeater.data.ListDataProvider)11 LinkPanel (com.gitblit.wicket.panels.LinkPanel)6 ArrayList (java.util.ArrayList)6 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)5 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)5 Fragment (org.apache.wicket.markup.html.panel.Fragment)5 ListDataProvider (com.evolveum.midpoint.web.component.util.ListDataProvider)4 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)4 UserModel (com.gitblit.models.UserModel)4 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)4 NavigatorPanel (com.evolveum.midpoint.web.component.data.paging.NavigatorPanel)3 TicketLabel (com.gitblit.tickets.TicketLabel)3 Component (org.apache.wicket.Component)3 IModel (org.apache.wicket.model.IModel)3 ParameterMenuItem (com.gitblit.models.Menu.ParameterMenuItem)2 RepositoryModel (com.gitblit.models.RepositoryModel)2 RepositoryUrl (com.gitblit.models.RepositoryUrl)2