Search in sources :

Example 1 with Selectable

use of com.evolveum.midpoint.web.component.util.Selectable 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 Selectable

use of com.evolveum.midpoint.web.component.util.Selectable 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)

Example 3 with Selectable

use of com.evolveum.midpoint.web.component.util.Selectable in project midpoint by Evolveum.

the class PageProcessInstances method stopProcessInstancesPerformed.

private void stopProcessInstancesPerformed(AjaxRequestTarget target) {
    MidPointPrincipal user = SecurityUtils.getPrincipalUser();
    List<ProcessInstanceDto> selectedStoppableInstances = new ArrayList<>();
    for (Selectable row : WebComponentUtil.getSelectedData(getTable())) {
        ProcessInstanceDto instance = (ProcessInstanceDto) row;
        if (instance.getEndTimestamp() == null) {
            selectedStoppableInstances.add(instance);
        }
    }
    if (!isSomeItemSelected(selectedStoppableInstances, true, target)) {
        return;
    }
    OperationResult result = new OperationResult(OPERATION_STOP_PROCESS_INSTANCES);
    WorkflowService workflowService = getWorkflowService();
    for (ProcessInstanceDto instance : selectedStoppableInstances) {
        try {
            workflowService.stopProcessInstance(instance.getProcessInstanceId(), WebComponentUtil.getOrigStringFromPoly(user.getName()), result);
        } catch (SchemaException | ObjectNotFoundException | SecurityViolationException | RuntimeException ex) {
            result.createSubresult(OPERATION_STOP_PROCESS_INSTANCE).recordPartialError("Couldn't stop process instance " + instance.getName(), ex);
        }
    }
    if (result.isUnknown()) {
        result.recomputeStatus();
    }
    if (result.isSuccess()) {
        result.recordStatus(OperationResultStatus.SUCCESS, "Selected process instance(s) have been successfully stopped.");
    }
    showResult(result);
    ProcessInstanceDtoProvider provider = (ProcessInstanceDtoProvider) getTable().getDataTable().getDataProvider();
    provider.clearCache();
    //refresh feedback and table
    target.add(getFeedbackPanel());
    target.add(getTable());
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ProcessInstanceDto(com.evolveum.midpoint.web.page.admin.workflow.dto.ProcessInstanceDto) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ProcessInstanceDtoProvider(com.evolveum.midpoint.web.page.admin.workflow.dto.ProcessInstanceDtoProvider) Selectable(com.evolveum.midpoint.web.component.util.Selectable) WorkflowService(com.evolveum.midpoint.model.api.WorkflowService) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Aggregations

Selectable (com.evolveum.midpoint.web.component.util.Selectable)3 BaseSortableDataProvider (com.evolveum.midpoint.web.component.data.BaseSortableDataProvider)2 WorkflowService (com.evolveum.midpoint.model.api.WorkflowService)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)1 SelectableDataTable (com.evolveum.midpoint.web.component.data.SelectableDataTable)1 ProcessInstanceDto (com.evolveum.midpoint.web.page.admin.workflow.dto.ProcessInstanceDto)1 ProcessInstanceDtoProvider (com.evolveum.midpoint.web.page.admin.workflow.dto.ProcessInstanceDtoProvider)1 ArrayList (java.util.ArrayList)1 IDataProvider (org.apache.wicket.markup.repeater.data.IDataProvider)1 ComponentHierarchyIterator (org.apache.wicket.util.iterator.ComponentHierarchyIterator)1