Example usage for org.apache.wicket.extensions.markup.html.repeater.data.table DataTable getColumns

List of usage examples for org.apache.wicket.extensions.markup.html.repeater.data.table DataTable getColumns

Introduction

In this page you can find the example usage for org.apache.wicket.extensions.markup.html.repeater.data.table DataTable getColumns.

Prototype

public final List<? extends IColumn<T, S>> getColumns() 

Source Link

Usage

From source file:org.artifactory.common.wicket.component.table.groupable.header.AjaxGroupableHeadersToolbar.java

License:Open Source License

public AjaxGroupableHeadersToolbar(final DataTable table, final ISortStateLocator stateLocator) {
    super(table);

    // alas, copied from HeadersToolbar
    RepeatingView headers = new RepeatingView("headers");
    add(headers);/*from w ww.ja v  a  2 s. c om*/

    final List<IColumn> columns = table.getColumns();
    int i = 0;
    for (final IColumn column : columns) {
        WebMarkupContainer item = new WebMarkupContainer(headers.newChildId());
        item.setRenderBodyOnly(true);
        headers.add(item);

        WebMarkupContainer header;
        if (column.isSortable()) {
            if (column instanceof IGroupableColumn) {
                final IGroupableColumn groupableColumn = (IGroupableColumn) column;
                header = newSortableHeader("header", groupableColumn.getSortProperty(),
                        groupableColumn.getGroupProperty(), stateLocator);
            } else {
                header = newSortableHeader("header", column.getSortProperty(), column.getSortProperty(),
                        stateLocator);
            }
        } else {
            header = new UnsortableBorder("header");
        }

        // add IStyledColumn style
        if (column instanceof IStyledColumn) {
            header.add(new CssClass(new AbstractReadOnlyModel() {
                @Override
                public Object getObject() {
                    return ((IStyledColumn) column).getCssClass();
                }
            }));
        }

        // add first/last style
        if (i == 0) {
            header.add(new CssClass("first-cell"));
        } else if (i == columns.size() - 1) {
            header.add(new CssClass("last-cell"));
        }
        item.add(header);

        // add label
        header.add(column.getHeader("label"));

        // add groupByLink
        Component groupByLink;
        WebMarkupContainer groupByText = new WebMarkupContainer("groupByText");
        if (column instanceof IGroupableColumn) {
            IGroupableColumn groupableColumn = (IGroupableColumn) column;
            String property = groupableColumn.getGroupProperty();
            groupByLink = newGroupByLink("groupByLink", stateLocator, property);

            header.add(new CssClass(new HeaderCssModel(stateLocator, property)));
        } else {
            groupByLink = new WebMarkupContainer("groupByLink").setVisible(false);
            groupByText.setVisible(false);
        }

        header.add(groupByLink);
        header.add(groupByText);
        i++;
    }
}

From source file:org.cast.cwm.admin.DocumentationToolbar.java

License:Open Source License

public <T, S> DocumentationToolbar(final DataTable<T, S> table) {
    super(table);

    RefreshingView<IColumn<T, S>> docs = new RefreshingView<IColumn<T, S>>("docs") {

        @Override/*from  ww  w.  j av a2s  .  c  o m*/
        protected Iterator<IModel<IColumn<T, S>>> getItemModels() {
            List<IModel<IColumn<T, S>>> columnsModels = new LinkedList<IModel<IColumn<T, S>>>();

            for (IColumn<T, S> column : table.getColumns()) {
                columnsModels.add(Model.of(column));
            }

            return columnsModels.iterator();
        }

        @Override
        protected void populateItem(Item<IColumn<T, S>> item) {
            final IColumn<T, S> column = item.getModelObject();
            Component header;
            if (column instanceof IDocumentedColumn) {
                header = new Label("documentation", ((IDocumentedColumn) column).getDocumentationModel());
            } else {
                header = new WebMarkupContainer("documentation");
            }
            item.add(header);
        }

    };
    add(docs);
}

From source file:org.devgateway.toolkit.forms.wicket.components.table.AjaxBootstrapNavigationToolbar.java

License:Open Source License

public AjaxBootstrapNavigationToolbar(final DataTable<?, ?> table) {
    super(table);

    WebMarkupContainer span = new WebMarkupContainer("span");
    this.add(span);
    span.add(AttributeModifier.replace("colspan", new AbstractReadOnlyModel<String>() {
        private static final long serialVersionUID = 1L;

        @Override//from w w  w . j  av  a2  s  . com
        public String getObject() {
            return String.valueOf(table.getColumns().size());
        }
    }));

    span.add(new Component[] { this.newPagingNavigator("navigator", table) });
}

From source file:org.hippoecm.frontend.plugins.standards.list.datatable.ListNavigationToolBar.java

License:Apache License

public ListNavigationToolBar(DataTable table, IPagingDefinition pagingDefinition) {
    super(table);

    WebMarkupContainer span = new WebMarkupContainer("span");
    add(span);/* ww w  . j  av  a  2s. c  om*/
    span.add(new AttributeModifier("colspan", true, new Model(String.valueOf(table.getColumns().size()))));

    PagingNavigator pagingNavigator = newPagingNavigator("navigator", table, pagingDefinition);
    span.add(pagingNavigator);
    span.add(new NavigatorLabel("navigatorLabel", table));
}

From source file:org.onexus.website.api.widgets.tableviewer.HeadersToolbar.java

License:Apache License

/**
 * Constructor/*from  www  .  j  a  v  a  2  s.co  m*/
 *
 * @param table        data table this toolbar will be attached to
 * @param stateLocator locator for the ISortState implementation used by sortable
 *                     headers
 */
public <T, S> HeadersToolbar(final DataTable<T, S> table, final ISortStateLocator stateLocator) {
    super(table);

    table.setOutputMarkupId(true);

    RepeatingView headersGrandParents = new RepeatingView("headersGrandParents");
    RepeatingView headersParents = new RepeatingView("headersParents");
    RepeatingView headers = new RepeatingView("headers");

    //TODO Show optionally headers
    headersGrandParents.setVisible(false);
    headersParents.setVisible(false);

    add(headersGrandParents);
    add(headersParents);
    add(headers);

    final List<? extends IColumn<T, S>> columns = table.getColumns();

    WebMarkupContainer secondHeaderContainer = null;
    String lastSecondHeaderTitle = null;
    int lastSecondHeaderColspan = 0;

    WebMarkupContainer thirdHeaderContainer = null;
    String lastThirdHeaderTitle = null;
    int lastThirdHeaderColspan = 0;

    int col = 0;
    for (final IColumn<T, S> c : columns) {

        String placement = col == 0 ? "right" : (col + 1 == columns.size() ? "left" : "top");

        // Process only Track columns
        CollectionColumn column = null;
        if (c instanceof CollectionColumn) {
            column = (CollectionColumn) c;
        } else {

            if (c instanceof AbstractColumn) {
                WebMarkupContainer item = new WebMarkupContainer(headers.newChildId());
                item.setRenderBodyOnly(true);

                WebMarkupContainer parentItem = new WebMarkupContainer(headersParents.newChildId());
                parentItem.setRenderBodyOnly(true);

                WebMarkupContainer grandParentItem = new WebMarkupContainer(headersGrandParents.newChildId());
                grandParentItem.setRenderBodyOnly(true);

                headers.add(item);
                headersParents.add(parentItem);
                headersGrandParents.add(grandParentItem);

                WebMarkupContainer firstHeaderContainer = new WebMarkupContainer("header");

                WebMarkupContainer innerHeader = new WebMarkupContainer("filter");
                innerHeader.add(c.getHeader("label"));
                firstHeaderContainer.add(innerHeader);
                firstHeaderContainer.add(new AttributeModifier("style",
                        new Model<String>("font-size:12px; font-family:sans-serif;")));

                item.add(firstHeaderContainer);

                secondHeaderContainer = new WebMarkupContainer("header");
                decorateSecondParentHeader(secondHeaderContainer, null, column);

                secondHeaderContainer.add(new AttributeModifier("class", new Model<String>("empty")));
                parentItem.add(secondHeaderContainer);
                secondHeaderContainer = null;

                thirdHeaderContainer = new WebMarkupContainer("header");
                thirdHeaderContainer.add(new EmptyPanel("label"));
                thirdHeaderContainer.add(new AttributeModifier("class", new Model<String>("empty")));
                grandParentItem.add(thirdHeaderContainer);
                thirdHeaderContainer = null;
            }

            continue;
        }

        IHeader firstHeader = column.getHeaderDecorator();
        IHeader secondHeader = firstHeader == null ? null : firstHeader.getParentHeader();
        IHeader thirdHeader = secondHeader == null ? null : secondHeader.getParentHeader();

        WebMarkupContainer item = new WebMarkupContainer(headers.newChildId());
        headers.add(item);

        WebMarkupContainer firstHeaderContainer = null;
        if (column.isFilterable()) {
            firstHeaderContainer = new FilteredHeader("header", (FieldHeader) column.getHeaderDecorator());
        } else {
            firstHeaderContainer = new WebMarkupContainer("header");
        }

        WebMarkupContainer innerHeader;
        if (column.isSortable()) {
            innerHeader = newSortableHeader("filter", column.getSortProperty(), stateLocator);
        } else {
            innerHeader = new WebMarkupContainer("filter");
        }
        firstHeaderContainer.add(innerHeader);

        item.add(firstHeaderContainer);
        item.setRenderBodyOnly(true);
        innerHeader.add(firstHeader.getHeader("label"));
        if (firstHeader.getLabel() == null) {
            firstHeaderContainer.add(new AttributeModifier("class", new Model<String>("empty")));
        }

        // Add parent and grand parent headers
        String secondTitle = null;
        String thirdTitle = null;

        firstHeaderContainer.add(new AttributeModifier("title", new Model<String>(firstHeader.getTitle())));
        firstHeaderContainer.add(new AttributeModifier("rel", Model.of("tooltip")));
        firstHeaderContainer.add(new AttributeModifier("data-placement", Model.of(placement)));
        firstHeaderContainer.add(
                new AttributeModifier("style", new Model<String>("font-size:12px; font-family:sans-serif;")));

        if (secondHeader != null) {
            secondTitle = secondHeader.getLabel();
        }
        if (thirdHeader != null) {
            thirdTitle = thirdHeader.getLabel();
        }

        if (secondHeaderContainer != null
                && ((lastSecondHeaderTitle == null && secondTitle == null) || (lastSecondHeaderTitle != null
                        && secondTitle != null && lastSecondHeaderTitle.equals(secondTitle)))) {
            lastSecondHeaderColspan += 1;
            secondHeaderContainer.add(new AttributeModifier("colspan",
                    new Model<String>(Integer.toString(lastSecondHeaderColspan))));

        } else {

            // Add parentItem
            WebMarkupContainer parentItem = new WebMarkupContainer(headersParents.newChildId());
            headersParents.add(parentItem);
            secondHeaderContainer = new WebMarkupContainer("header");
            decorateSecondParentHeader(secondHeaderContainer, secondHeader, column);

            if (secondTitle == null) {
                secondHeaderContainer.add(new AttributeModifier("class", new Model<String>("empty")));
            }

            if (secondHeader != null && secondHeader.getLabel() != null) {
                secondHeaderContainer
                        .add(new AttributeModifier("title", new Model<String>(secondHeader.getTitle())));
                secondHeaderContainer.add(new AttributeModifier("rel", Model.of("tooltip")));
                secondHeaderContainer.add(new AttributeModifier("data-placement", Model.of(placement)));
            }

            secondHeaderContainer.add(new AttributeModifier("style",
                    new Model<String>("font-size:12px; font-family:sans-serif;")));
            parentItem.add(secondHeaderContainer);
            parentItem.setRenderBodyOnly(true);
            lastSecondHeaderTitle = secondTitle;
            lastSecondHeaderColspan = 1;
        }

        // GrandParents
        if (thirdHeaderContainer != null
                && ((lastThirdHeaderTitle == null && thirdTitle == null) || (lastThirdHeaderTitle != null
                        && thirdTitle != null && lastThirdHeaderTitle.equals(thirdTitle)))) {
            lastThirdHeaderColspan += 1;
            thirdHeaderContainer.add(new AttributeModifier("colspan",
                    new Model<String>(Integer.toString(lastThirdHeaderColspan))));
        } else {
            // Add grandParentItem
            WebMarkupContainer grandParentItem = new WebMarkupContainer(headersGrandParents.newChildId());
            headersGrandParents.add(grandParentItem);
            thirdHeaderContainer = new WebMarkupContainer("header");

            if (thirdTitle == null) {
                thirdHeaderContainer.add(new AttributeModifier("class", new Model<String>("empty")));
            }

            if (thirdHeader != null) {
                thirdHeaderContainer.add(thirdHeader.getHeader("label"));

                if (thirdHeader.getLabel() != null) {
                    thirdHeaderContainer
                            .add(new AttributeModifier("title", new Model<String>(thirdHeader.getTitle())));
                    thirdHeaderContainer.add(new AttributeModifier("rel", Model.of("tooltip")));
                    thirdHeaderContainer.add(new AttributeModifier("data-placement", Model.of(placement)));

                }
            } else {
                thirdHeaderContainer.add(new EmptyPanel("label"));
            }

            thirdHeaderContainer.add(new AttributeModifier("style",
                    new Model<String>("font-size:12px; font-family:sans-serif;")));
            grandParentItem.add(thirdHeaderContainer);
            grandParentItem.setRenderBodyOnly(true);
            lastThirdHeaderTitle = thirdTitle;
            lastThirdHeaderColspan = 1;

        }

        col++;

    }
}

From source file:org.opensingular.form.wicket.mapper.masterdetail.MasterDetailNoRecordsToolbar.java

License:Apache License

MasterDetailNoRecordsToolbar(DataTable<?, ?> table) {
    super(table);
    final WebMarkupContainer td = new WebMarkupContainer("td");
    add(td);//from w  ww .j  a  va  2  s.c  om
    td.add(AttributeModifier.replace("colspan", new AbstractReadOnlyModel<String>() {
        @Override
        public String getObject() {
            return String.valueOf(table.getColumns().size()).intern();
        }
    }));
    td.add(new Label("msg", $m.ofValue("Nenhum item foi adicionado.")));
}

From source file:org.sakaiproject.sitestats.tool.wicket.components.SakaiNavigationToolBar.java

License:Educational Community License

/**
 * Constructor//from www .j  a va  2s.c o m
 * 
 * @param table
 *            data table this toolbar will be attached to
 */
public SakaiNavigationToolBar(final DataTable table) {
    super(table);

    WebMarkupContainer span = (WebMarkupContainer) get("span");
    span.add(new AttributeModifier("colspan", new Model(String.valueOf(table.getColumns().size()))));

    span.get("navigator").replaceWith(newPagingNavigator("navigator", table));
    span.get("navigatorLabel").replaceWith(newNavigatorLabel("navigatorLabel", table));
}

From source file:org.sakaiproject.wicket.markup.html.repeater.data.table.BasicHeadersToolbar.java

License:Educational Community License

public BasicHeadersToolbar(DataTable table, ISortStateLocator stateLocator) {
    super(table);

    setRenderBodyOnly(true);/* w w w . j a  v a 2s. com*/

    RepeatingView headers = new RepeatingView("headers");
    add(headers);

    final IColumn[] columns = table.getColumns();
    for (int i = 0; i < columns.length; i++) {
        final IColumn column = columns[i];

        WebMarkupContainer item = new WebMarkupContainer(headers.newChildId());
        headers.add(item);

        WebMarkupContainer header = null;
        if (column.isSortable()) {
            header = newSortableHeader("header", column.getSortProperty(), stateLocator);
        } else {
            header = new WebMarkupContainer("header");
        }

        if (column instanceof PropertyColumn) {
            String expression = ((PropertyColumn) column).getPropertyExpression();

            if (expression != null)
                header.setMarkupId(expression);
        }

        if (column instanceof IStyledColumn) {
            header.add(new CssAttributeBehavior() {
                private static final long serialVersionUID = 1L;

                protected String getCssClass() {
                    return ((IStyledColumn) column).getCssClass();
                }
            });
        }

        final ISortState state = stateLocator.getSortState();

        Image indicatorImage = new Image("indicator") {
            private static final long serialVersionUID = 1L;

            protected ResourceReference getImageResourceReference() {
                int sortOrder = ISortState.NONE;

                if (column.isSortable() && column.getSortProperty() != null)
                    sortOrder = state.getPropertySortOrder(column.getSortProperty());

                if (sortOrder == ISortState.DESCENDING)
                    return upArrowReference;
                else if (sortOrder == ISortState.ASCENDING)
                    return downArrowReference;

                return noArrowReference;
            }
        };

        header.add(indicatorImage);

        indicatorImage.setVisible(column.isSortable() && column.getSortProperty() != null);

        item.add(header);
        item.setRenderBodyOnly(true);
        header.add(column.getHeader("label"));

    }
}

From source file:org.sakaiproject.wicket.markup.html.repeater.data.table.ClassicNavigationToolbar.java

License:Educational Community License

public ClassicNavigationToolbar(DataTable table) {
    super(table);
    this.table = table;

    span = new WebMarkupContainer("span");
    add(span);//w  w  w .ja  va 2s .c  om
    span.add(new AttributeModifier("colspan", true, new Model(String.valueOf(table.getColumns().length))));

    span.add(newPagingNavigator("navigator", table));
    span.add(newNavigatorLabel("navigatorLabel", table));
}

From source file:org.wicketstuff.datatables.columns.SpanHeadersToolbar.java

License:Apache License

/**
 * Constructor//from ww w  .  j a  v  a2  s .  com
 *
  * @param table
  *            data table this toolbar will be attached to
  * @param columns
  */
public <T> SpanHeadersToolbar(final DataTable<T, S> table, final IDataTablesColumn<T, S>... columns) {
    super(table);

    RefreshingView<IColumn<T, S>> headers = new RefreshingView<IColumn<T, S>>("headers") {
        private static final long serialVersionUID = 1L;

        @Override
        protected Iterator<IModel<IColumn<T, S>>> getItemModels() {
            List<IModel<IColumn<T, S>>> columnsModels = new LinkedList<>();

            List<? extends IColumn<T, S>> tableColumns = (columns != null && columns.length > 0)
                    ? Arrays.asList(columns)
                    : table.getColumns();
            for (IColumn<T, S> column : tableColumns) {
                columnsModels.add(Model.of(column));
            }

            return columnsModels.iterator();
        }

        @Override
        protected void populateItem(Item<IColumn<T, S>> item) {
            final IColumn<T, S> column = item.getModelObject();

            WebMarkupContainer header = new WebMarkupContainer("header");
            if (column instanceof IDataTablesColumn) {
                IDataTablesColumn<T, S> dtColumn = (IDataTablesColumn<T, S>) column;
                if (dtColumn.getColspan() > 0) {
                    header.add(AttributeModifier.replace("colspan", dtColumn.getColspan()));
                }

                if (dtColumn.getRowspan() > 0) {
                    header.add(AttributeModifier.replace("rowspan", dtColumn.getRowspan() - 1));
                }
            }

            if (column instanceof IStyledColumn) {
                Behavior cssAttributeBehavior = new Behavior() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void onComponentTag(final Component component, final ComponentTag tag) {
                        super.onComponentTag(component, tag);

                        String cssClass = ((IStyledColumn<?, S>) column).getCssClass();
                        if (!Strings.isEmpty(cssClass)) {
                            tag.append("class", cssClass, " ");
                        }
                    }
                };

                header.add(cssAttributeBehavior);
            }

            item.add(header);
            item.setRenderBodyOnly(true);
            header.add(column.getHeader("label"));
        }
    };
    add(headers);
}