Search in sources :

Example 6 with SelectableBean

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

the class MultipleAssignmentSelector method createRowLink.

private Component createRowLink(String id, final IModel<SelectableBean<AssignmentEditorDto>> rowModel) {
    AjaxLink<SelectableBean<AssignmentEditorDto>> button = new AjaxLink<SelectableBean<AssignmentEditorDto>>(id, rowModel) {

        @Override
        public IModel<?> getBody() {
            AssignmentEditorDto dto = (AssignmentEditorDto) rowModel.getObject();
            String name = StringUtils.isNotEmpty(dto.getNameForTargetObject()) ? dto.getNameForTargetObject() : dto.getName();
            return new Model<>(name);
        }

        @Override
        public void onClick(AjaxRequestTarget target) {
            LOGGER.trace("{} CLICK: {}", this, rowModel.getObject());
            toggleRow(rowModel);
            target.add(this);
        }

        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            if (rowModel.getObject().isSelected()) {
                tag.put("class", "list-group-item active");
                tag.put("style", "background-color: #eee; border-color: #d6d6d6; color: #000;");
            } else {
                tag.put("class", "list-group-item");
            }
            String description = ((AssignmentEditorDto) rowModel.getObject()).getDescription();
            if (description != null) {
                tag.put("title", description);
            }
        }
    };
    button.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return ((AssignmentEditorDto) rowModel.getObject()).getStatus() != UserDtoStatus.DELETE;
        }
    });
    button.setOutputMarkupId(true);
    return button;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ComponentTag(org.apache.wicket.markup.ComponentTag) IModel(org.apache.wicket.model.IModel) Model(org.apache.wicket.model.Model) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink)

Example 7 with SelectableBean

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

the class ObjectDataProvider method getSelectedData.

public List<T> getSelectedData() {
    for (Serializable s : super.getAvailableData()) {
        if (s instanceof SelectableBean) {
            SelectableBean<T> selectable = (SelectableBean<T>) s;
            if (selectable.isSelected() && selectable.getValue() != null) {
                selected.add(selectable.getValue());
            }
        }
    }
    List<T> allSelected = new ArrayList<>();
    allSelected.addAll(selected);
    return allSelected;
}
Also used : Serializable(java.io.Serializable) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean)

Example 8 with SelectableBean

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

the class ObjectNameColumn method populateItem.

@Override
public void populateItem(final Item<ICellPopulator<SelectableBean<O>>> cellItem, String componentId, final IModel<SelectableBean<O>> rowModel) {
    IModel<String> labelModel = new AbstractReadOnlyModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            SelectableBean<O> selectableBean = rowModel.getObject();
            O value = selectableBean.getValue();
            if (value == null) {
                OperationResult result = selectableBean.getResult();
                OperationResultStatusPresentationProperties props = OperationResultStatusPresentationProperties.parseOperationalResultStatus(result.getStatus());
                return cellItem.getString(props.getStatusLabelKey());
            } else {
                String name = WebComponentUtil.getName(value);
                if (selectableBean.getResult() != null) {
                    StringBuilder complexName = new StringBuilder();
                    complexName.append(name);
                    complexName.append(" (");
                    complexName.append(selectableBean.getResult().getStatus());
                    complexName.append(")");
                    return complexName.toString();
                }
                return name;
            }
        }
    };
    if (isClickable(rowModel)) {
        // beware: rowModel is very probably resolved at this moment; but it seems to cause no problems
        cellItem.add(new LinkPanel(componentId, labelModel) {

            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                SelectableBean<O> selectableBean = rowModel.getObject();
                O value = selectableBean.getValue();
                if (value == null) {
                    OperationResult result = selectableBean.getResult();
                    throw new RestartResponseException(new PageOperationResult(result));
                } else {
                    if (selectableBean.getResult() != null) {
                        throw new RestartResponseException(new PageOperationResult(selectableBean.getResult()));
                    } else {
                        ObjectNameColumn.this.onClick(target, rowModel);
                    }
                }
            }
        });
    } else {
        cellItem.add(new Label(componentId, labelModel));
    }
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Label(org.apache.wicket.markup.html.basic.Label) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PageOperationResult(com.evolveum.midpoint.web.page.error.PageOperationResult) OperationResultStatusPresentationProperties(com.evolveum.midpoint.web.page.admin.server.dto.OperationResultStatusPresentationProperties) PageOperationResult(com.evolveum.midpoint.web.page.error.PageOperationResult) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) RestartResponseException(org.apache.wicket.RestartResponseException) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean)

Example 9 with SelectableBean

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

the class SelectableBeanObjectDataProvider method internalIterator.

@Override
public Iterator<SelectableBean<O>> internalIterator(long offset, long pageSize) {
    LOGGER.trace("begin::iterator() offset {} pageSize {}.", new Object[] { offset, pageSize });
    //        if (pageSize > 1000000) {
    //        	// Failsafe. Do not even try this. This can have huge impact on the resource. (MID-3336)
    //        	throw new IllegalArgumentException("Requested huge page size: "+pageSize);
    //        }
    preprocessSelectedData();
    OperationResult result = new OperationResult(OPERATION_SEARCH_OBJECTS);
    try {
        ObjectPaging paging = createPaging(offset, pageSize);
        Task task = getPage().createSimpleTask(OPERATION_SEARCH_OBJECTS);
        ObjectQuery query = getQuery();
        if (query == null) {
            if (emptyListOnNullQuery) {
                return new ArrayList<SelectableBean<O>>().iterator();
            }
            query = new ObjectQuery();
        }
        query.setPaging(paging);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Query {} with {}", type.getSimpleName(), query.debugDump());
        }
        if (ResourceType.class.equals(type) && (options == null || options.isEmpty())) {
            options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
        }
        List<PrismObject<? extends O>> list = (List) getModel().searchObjects(type, query, options, task, result);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Query {} resulted in {} objects", type.getSimpleName(), list.size());
        }
        for (PrismObject<? extends O> object : list) {
            getAvailableData().add(createDataObjectWrapper(object.asObjectable()));
        }
    //            result.recordSuccess();
    } catch (Exception ex) {
        result.recordFatalError("Couldn't list objects.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't list objects", ex);
        return handleNotSuccessOrHandledErrorInIterator(result);
    } finally {
        result.computeStatusIfUnknown();
    }
    LOGGER.trace("end::iterator() {}", result);
    return getAvailableData().iterator();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RestartResponseException(org.apache.wicket.RestartResponseException) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with SelectableBean

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

the class ColumnUtils method getDefaultTaskColumns.

public static <T extends ObjectType> List<IColumn<SelectableBean<T>, String>> getDefaultTaskColumns() {
    List<IColumn<SelectableBean<T>, String>> columns = new ArrayList<IColumn<SelectableBean<T>, String>>();
    columns.add(new AbstractColumn<SelectableBean<T>, String>(createStringResource("TaskType.kind")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(Item<ICellPopulator<SelectableBean<T>>> cellItem, String componentId, IModel<SelectableBean<T>> rowModel) {
            SelectableBean<TaskType> object = (SelectableBean<TaskType>) rowModel.getObject();
            PrismProperty<ShadowKindType> pKind = object.getValue() != null ? object.getValue().asPrismObject().findProperty(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_KIND)) : null;
            if (pKind != null) {
                cellItem.add(new Label(componentId, WebComponentUtil.createLocalizedModelForEnum(pKind.getRealValue(), cellItem)));
            } else {
                cellItem.add(new Label(componentId));
            }
        }
    });
    columns.add(new AbstractColumn<SelectableBean<T>, String>(createStringResource("TaskType.intent")) {

        @Override
        public void populateItem(Item<ICellPopulator<SelectableBean<T>>> cellItem, String componentId, IModel<SelectableBean<T>> rowModel) {
            SelectableBean<TaskType> object = (SelectableBean<TaskType>) rowModel.getObject();
            PrismProperty<String> pIntent = object.getValue() != null ? object.getValue().asPrismObject().findProperty(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_INTENT)) : null;
            if (pIntent != null) {
                cellItem.add(new Label(componentId, pIntent.getRealValue()));
            } else {
                cellItem.add(new Label(componentId));
            }
        }
    });
    columns.add(new AbstractColumn<SelectableBean<T>, String>(createStringResource("TaskType.objectClass")) {

        @Override
        public void populateItem(Item<ICellPopulator<SelectableBean<T>>> cellItem, String componentId, IModel<SelectableBean<T>> rowModel) {
            SelectableBean<TaskType> object = (SelectableBean<TaskType>) rowModel.getObject();
            PrismProperty<QName> pObjectClass = object.getValue() != null ? object.getValue().asPrismObject().findProperty(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.OBJECTCLASS_PROPERTY_NAME)) : null;
            if (pObjectClass != null) {
                cellItem.add(new Label(componentId, pObjectClass.getRealValue().getLocalPart()));
            } else {
                cellItem.add(new Label(componentId, ""));
            }
        }
    });
    List<ColumnTypeDto<String>> columnsDefs = Arrays.asList(new ColumnTypeDto<String>("TaskType.executionStatus", TaskType.F_EXECUTION_STATUS.getLocalPart(), SelectableBean.F_VALUE + ".executionStatus", false));
    columns.addAll(ColumnUtils.<SelectableBean<T>>createColumns(columnsDefs));
    return columns;
}
Also used : ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) ICellPopulator(org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

SelectableBean (com.evolveum.midpoint.web.component.util.SelectableBean)73 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)39 IColumn (org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)37 IModel (org.apache.wicket.model.IModel)37 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)32 ArrayList (java.util.ArrayList)31 Label (org.apache.wicket.markup.html.basic.Label)22 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)16 ButtonInlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem)16 MainObjectListPanel (com.evolveum.midpoint.gui.api.component.MainObjectListPanel)15 UserProfileStorage (com.evolveum.midpoint.web.session.UserProfileStorage)14 ICellPopulator (org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator)12 PropertyColumn (org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn)12 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)12 Item (org.apache.wicket.markup.repeater.Item)11 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)9 SelectableBeanImpl (com.evolveum.midpoint.web.component.util.SelectableBeanImpl)8 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)8 List (java.util.List)8 MidpointForm (com.evolveum.midpoint.web.component.form.MidpointForm)7