Example usage for org.apache.wicket.extensions.markup.html.repeater.util SortableDataProvider iterator

List of usage examples for org.apache.wicket.extensions.markup.html.repeater.util SortableDataProvider iterator

Introduction

In this page you can find the example usage for org.apache.wicket.extensions.markup.html.repeater.util SortableDataProvider iterator.

Prototype

Iterator<? extends T> iterator(long first, long count);

Source Link

Document

Gets an iterator for the subset of total data

Usage

From source file:org.headsupdev.agile.web.components.issues.IssueListPanel.java

License:Open Source License

public IssueListPanel(String id, final SortableDataProvider<Issue> issues, final HeadsUpPage page,
        final boolean hideProject, final boolean hideMilestone, final Milestone milestone) {
    super(id);//from w  w  w. java2  s.  c o m
    add(CSSPackageResource.getHeaderContribution(getClass(), "issue.css"));

    this.page = page;
    this.milestone = milestone;
    this.hideMilestone = hideMilestone;
    this.hideProject = hideProject;

    quickIssue = createIssue();

    final boolean timeEnabled = Boolean.parseBoolean(
            page.getProject().getConfigurationValue(StoredProject.CONFIGURATION_TIMETRACKING_ENABLED));

    rowAdd = new WebMarkupContainer("rowAdd");
    rowAdd.setMarkupId("rowAdd");

    Form<Issue> inlineForm = getInlineForm();
    add(inlineForm);

    inlineForm.add(new WebMarkupContainer("hours-header").setVisible(timeEnabled));
    final DataView dataView = new StripedDataView<Issue>("issues", issues, ITEMS_PER_PAGE) {
        protected void populateItem(final Item<Issue> item) {
            super.populateItem(item);
            Issue issue = item.getModelObject();

            item.add(new IssuePanelRow("issue", issue, page, hideProject, hideMilestone, false));
        }
    };
    inlineForm.add(dataView);

    AttributeModifier colspanModifier = new AttributeModifier("colspan", true, new Model<Integer>() {
        @Override
        public Integer getObject() {
            int cols = 9;
            if (hideMilestone) {
                cols--;
            }
            if (hideProject) {
                cols--;
            }

            return cols;
        }
    });

    pagingFooter = new StyledPagingNavigator("footerPaging", dataView);
    pagingFooter.setOutputMarkupPlaceholderTag(true);
    inlineForm.add(pagingFooter.add(colspanModifier).setVisible(issues.size() > ITEMS_PER_PAGE));
    pagingHeader = new StyledPagingNavigator("headerPaging", dataView);
    pagingHeader.setOutputMarkupPlaceholderTag(true);
    inlineForm.add(pagingHeader.add(colspanModifier).setVisible(issues.size() > ITEMS_PER_PAGE));

    inlineForm.add(new OrderByBorder("orderById", "id.id", issues));

    inlineForm.add(quickAdd);

    inlineForm.add(new OrderByBorder("orderBySummary", "summary", issues));
    inlineForm.add(new OrderByBorder("orderByStatus", "status", issues));
    inlineForm.add(new OrderByBorder("orderByPriority", "priority", issues));
    inlineForm.add(new OrderByBorder("orderByOrder", "rank", issues));
    inlineForm.add(new OrderByBorder("orderByAssigned", "assignee", issues));
    inlineForm.add(new OrderByBorder("orderByMilestone", "milestone.name", issues).setVisible(!hideMilestone));
    inlineForm.add(new OrderByBorder("orderByProject", "id.project.id", issues).setVisible(!hideProject));

    final WebMarkupContainer totalRow = new WebMarkupContainer("totals");
    inlineForm.add(totalRow.setVisible(issues.size() > ITEMS_PER_PAGE || timeEnabled));

    final WebMarkupContainer allCell = new WebMarkupContainer("allCell");
    totalRow.add(allCell.add(new AttributeModifier("colspan", true, new Model<Integer>() {
        @Override
        public Integer getObject() {
            int cols = 7;
            if (hideMilestone) {
                cols--;
            }
            if (hideProject) {
                cols--;
            }

            return cols;
        }
    })));
    allCell.add(new Link("allLink") {
        @Override
        public void onClick() {
            dataView.setItemsPerPage(Integer.MAX_VALUE);

            setVisible(false);
            totalRow.setVisible(timeEnabled);
            pagingFooter.setVisible(false);
            pagingHeader.setVisible(false);
        }
    }.setVisible(issues.size() > ITEMS_PER_PAGE));

    totalRow.add(new WebMarkupContainer("requiredlabel").setVisible(timeEnabled));
    totalRow.add(new Label("hours",
            new IssueTotalHoursModel((Iterator<Issue>) issues.iterator(0, issues.size()), page.getProject()) {
                @Override
                public String getObject() {
                    setIssues(issues.iterator(0, dataView.getItemCount()));
                    // we could do this if the total is suppose to reflect the current page
                    //                setIssues( issues.iterator( dataView.getCurrentPage() * dataView.getItemsPerPage(), dataView.getItemsPerPage() ) );
                    return super.getObject();
                }
            }).setVisible(timeEnabled));
}