Search in sources :

Example 1 with ComponentHierarchyIterator

use of org.apache.wicket.util.iterator.ComponentHierarchyIterator in project midpoint by Evolveum.

the class CheckBoxHeaderColumn method onUpdateHeader.

/**
     * This method is called after select all checkbox is clicked
     * @param target
     * @param selected
     * @param table
     */
protected void onUpdateHeader(AjaxRequestTarget target, boolean selected, DataTable table) {
    IDataProvider provider = table.getDataProvider();
    if (!(provider instanceof BaseSortableDataProvider)) {
        LOGGER.debug("Select all checkbox work only with {} provider type. Current provider is type of {}.", new Object[] { BaseSortableDataProvider.class.getName(), provider.getClass().getName() });
    }
    //update selected flag in model dto objects based on select all header state
    BaseSortableDataProvider baseProvider = (BaseSortableDataProvider) provider;
    List<T> objects = baseProvider.getAvailableData();
    for (T object : objects) {
        if (object instanceof Selectable) {
            Selectable selectable = (Selectable) object;
            selectable.setSelected(selected);
        }
    }
    //refresh rows with ajax
    ComponentHierarchyIterator iterator = table.visitChildren(SelectableDataTable.SelectableRowItem.class);
    while (iterator.hasNext()) {
        SelectableDataTable.SelectableRowItem row = (SelectableDataTable.SelectableRowItem) iterator.next();
        if (!row.getOutputMarkupId()) {
            //we skip rows that doesn't have outputMarkupId set to true (it would fail)
            continue;
        }
        target.add(row);
    }
}
Also used : ComponentHierarchyIterator(org.apache.wicket.util.iterator.ComponentHierarchyIterator) BaseSortableDataProvider(com.evolveum.midpoint.web.component.data.BaseSortableDataProvider) SelectableDataTable(com.evolveum.midpoint.web.component.data.SelectableDataTable) Selectable(com.evolveum.midpoint.web.component.util.Selectable) IDataProvider(org.apache.wicket.markup.repeater.data.IDataProvider)

Example 2 with ComponentHierarchyIterator

use of org.apache.wicket.util.iterator.ComponentHierarchyIterator in project midpoint by Evolveum.

the class CheckBoxHeaderColumn method findCheckBoxColumnHeader.

public static CheckBoxPanel findCheckBoxColumnHeader(DataTable table) {
    WebMarkupContainer topToolbars = table.getTopToolbars();
    ComponentHierarchyIterator iterator = topToolbars.visitChildren(TableHeadersToolbar.class);
    if (!iterator.hasNext()) {
        return null;
    }
    TableHeadersToolbar toolbar = (TableHeadersToolbar) iterator.next();
    // simple attempt to find checkbox which is header for our column
    // todo: this search will fail if there are more checkbox header columns (which is not supported now,
    // because Selectable.F_SELECTED is hardcoded all over the place...
    iterator = toolbar.visitChildren(CheckBoxPanel.class);
    while (iterator.hasNext()) {
        Component c = iterator.next();
        if (!c.getOutputMarkupId()) {
            continue;
        }
        return (CheckBoxPanel) c;
    }
    return null;
}
Also used : ComponentHierarchyIterator(org.apache.wicket.util.iterator.ComponentHierarchyIterator) TableHeadersToolbar(com.evolveum.midpoint.web.component.data.TableHeadersToolbar) Component(org.apache.wicket.Component) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Aggregations

ComponentHierarchyIterator (org.apache.wicket.util.iterator.ComponentHierarchyIterator)2 BaseSortableDataProvider (com.evolveum.midpoint.web.component.data.BaseSortableDataProvider)1 SelectableDataTable (com.evolveum.midpoint.web.component.data.SelectableDataTable)1 TableHeadersToolbar (com.evolveum.midpoint.web.component.data.TableHeadersToolbar)1 Selectable (com.evolveum.midpoint.web.component.util.Selectable)1 Component (org.apache.wicket.Component)1 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)1 IDataProvider (org.apache.wicket.markup.repeater.data.IDataProvider)1