Search in sources :

Example 1 with BaseSortableDataProvider

use of com.evolveum.midpoint.web.component.data.BaseSortableDataProvider in project midpoint by Evolveum.

the class MultipleAssignmentSelector method getListDataProvider.

public <T extends FocusType> BaseSortableDataProvider getListDataProvider(final FocusType focus) {
    BaseSortableDataProvider provider;
    provider = new ListDataProvider<AssignmentEditorDto>(this, new IModel<List<AssignmentEditorDto>>() {

        @Override
        public List<AssignmentEditorDto> getObject() {
            return getAvailableAssignmentsDataList(focus);
        }

        @Override
        public void setObject(List<AssignmentEditorDto> list) {
        }

        @Override
        public void detach() {
        }
    });
    return provider;
}
Also used : IModel(org.apache.wicket.model.IModel) BaseSortableDataProvider(com.evolveum.midpoint.web.component.data.BaseSortableDataProvider) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with BaseSortableDataProvider

use of com.evolveum.midpoint.web.component.data.BaseSortableDataProvider in project midpoint by Evolveum.

the class WebComponentUtil method getSelectedData.

public static <T extends Selectable> List<T> getSelectedData(Table table) {
    DataTable dataTable = table.getDataTable();
    BaseSortableDataProvider<T> provider = (BaseSortableDataProvider<T>) dataTable.getDataProvider();
    List<T> selected = new ArrayList<T>();
    for (T bean : provider.getAvailableData()) {
        if (bean.isSelected()) {
            selected.add(bean);
        }
    }
    return selected;
}
Also used : DataTable(org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable) BaseSortableDataProvider(com.evolveum.midpoint.web.component.data.BaseSortableDataProvider)

Example 3 with BaseSortableDataProvider

use of com.evolveum.midpoint.web.component.data.BaseSortableDataProvider in project midpoint by Evolveum.

the class PageConnectorHosts method deleteHostConfirmedPerformed.

private void deleteHostConfirmedPerformed(AjaxRequestTarget target) {
    Table hostTable = getConnectorHostTable();
    List<SelectableBean<ConnectorHostType>> selected = WebComponentUtil.getSelectedData(hostTable);
    OperationResult result = new OperationResult(OPERATION_DELETE_HOSTS);
    for (SelectableBean<ConnectorHostType> selectable : selected) {
        try {
            Task task = createSimpleTask(OPERATION_DELETE_HOSTS);
            if (selectable.getValue() != null) {
                ObjectDelta<ConnectorHostType> delta = ObjectDelta.createDeleteDelta(ConnectorHostType.class, selectable.getValue().getOid(), getPrismContext());
                getModelService().executeChanges(WebComponentUtil.createDeltaCollection(delta), null, task, result);
            }
        } catch (Exception ex) {
            result.recordPartialError("Couldn't delete host.", ex);
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete host", ex);
        }
    }
    result.recomputeStatus();
    if (result.isSuccess()) {
        result.recordStatus(OperationResultStatus.SUCCESS, "The resource(s) have been successfully deleted.");
    }
    BaseSortableDataProvider provider = (BaseSortableDataProvider) hostTable.getDataTable().getDataProvider();
    provider.clearCache();
    showResult(result);
    target.add(getFeedbackPanel(), (Component) hostTable);
}
Also used : ConnectorHostType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorHostType) Task(com.evolveum.midpoint.task.api.Task) Table(com.evolveum.midpoint.web.component.data.Table) DataTable(org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable) BaseSortableDataProvider(com.evolveum.midpoint.web.component.data.BaseSortableDataProvider) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 4 with BaseSortableDataProvider

use of com.evolveum.midpoint.web.component.data.BaseSortableDataProvider 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 5 with BaseSortableDataProvider

use of com.evolveum.midpoint.web.component.data.BaseSortableDataProvider in project midpoint by Evolveum.

the class CheckBoxHeaderColumn method shouldBeHeaderSelected.

public static <T> boolean shouldBeHeaderSelected(DataTable table) {
    boolean selectedAll = true;
    BaseSortableDataProvider baseProvider = (BaseSortableDataProvider) table.getDataProvider();
    List<T> objects = baseProvider.getAvailableData();
    if (objects == null || objects.isEmpty()) {
        return false;
    }
    for (T object : objects) {
        if (object instanceof Selectable) {
            Selectable selectable = (Selectable) object;
            selectedAll &= selectable.isSelected();
        }
    }
    return selectedAll;
}
Also used : BaseSortableDataProvider(com.evolveum.midpoint.web.component.data.BaseSortableDataProvider) Selectable(com.evolveum.midpoint.web.component.util.Selectable)

Aggregations

BaseSortableDataProvider (com.evolveum.midpoint.web.component.data.BaseSortableDataProvider)5 Selectable (com.evolveum.midpoint.web.component.util.Selectable)2 DataTable (org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 Task (com.evolveum.midpoint.task.api.Task)1 SelectableDataTable (com.evolveum.midpoint.web.component.data.SelectableDataTable)1 Table (com.evolveum.midpoint.web.component.data.Table)1 SelectableBean (com.evolveum.midpoint.web.component.util.SelectableBean)1 ConnectorHostType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorHostType)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IDataProvider (org.apache.wicket.markup.repeater.data.IDataProvider)1 IModel (org.apache.wicket.model.IModel)1 ComponentHierarchyIterator (org.apache.wicket.util.iterator.ComponentHierarchyIterator)1