Search in sources :

Example 6 with ItemWrapper

use of com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper in project midpoint by Evolveum.

the class ItemWrapperModel method getItemWrapperForHeader.

<ID extends ItemDefinition> ItemWrapper getItemWrapperForHeader(Class<ID> type, PageBase pageBase) {
    if (path.isEmpty()) {
        return null;
    }
    if (fromContainerValue) {
        return null;
    }
    try {
        PrismContainerDefinition container = (PrismContainerDefinition) this.parent.getObject();
        ItemDefinition<?> def = container.findItemDefinition(path, type);
        if (!type.isAssignableFrom(def.getClass())) {
            return null;
        }
        // keys are mostly useless (unless nicely specified in XSD, which is not very often)
        return createItemWrapper(def.instantiate(), pageBase);
    } catch (SchemaException e) {
        LOGGER.error("Cannot get {} with path {} from parent {}\nReason: {}", ItemWrapper.class, path, this.parent.getObject(), e.getMessage(), e);
        return null;
    }
}
Also used : ItemWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition)

Example 7 with ItemWrapper

use of com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper in project midpoint by Evolveum.

the class SchrodingerComponentInitListener method handleLocalization.

private void handleLocalization(Component component) {
    if (component instanceof PrismPropertyPanel || component instanceof PrismReferencePanel) {
        ItemPanel ppp = (ItemPanel) component;
        ItemWrapper iw = (ItemWrapper) ppp.getModel().getObject();
        String key = iw.getDisplayName();
        QName qname = iw.getItemName();
        writeDataAttribute(component, ATTR_RESOURCE_KEY, key);
        writeDataAttribute(component, ATTR_QNAME, qnameToString(qname));
        return;
    }
    if (component instanceof PrismHeaderPanel) {
        PrismHeaderPanel php = (PrismHeaderPanel) component;
        String key = php.getLabel();
        writeDataAttribute(component, ATTR_RESOURCE_KEY, key);
        return;
    }
    IModel model = null;
    if (component.getDefaultModel() instanceof StringResourceModel) {
        model = component.getDefaultModel();
    } else if (component.getInnermostModel() instanceof StringResourceModel) {
        model = component.getInnermostModel();
    } else if (component.getDefaultModel() instanceof ReadOnlyModel) {
        try {
            if (component.getDefaultModelObject() instanceof String) {
                model = component.getDefaultModel();
            }
        } catch (Exception e) {
            LOGGER.error("Schrodinger localization handling failed", e);
        }
    }
    if (model == null) {
        return;
    }
    try {
        String key = model instanceof StringResourceModel ? (String) FieldUtils.readField(model, "resourceKey", true) : (String) model.getObject();
        if (key.startsWith("${")) {
            String expression = key.substring(2, key.length() - 1);
            key = new PropertyModel<String>(FieldUtils.readField(model, "model", true), expression).getObject();
        }
        if (key != null) {
            writeDataAttribute(component, ATTR_RESOURCE_KEY, key);
        }
    } catch (Exception ex) {
    // we don't care, should be all right, unless selenium tests starts failing
    }
}
Also used : ItemWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper) PrismPropertyPanel(com.evolveum.midpoint.gui.impl.prism.panel.PrismPropertyPanel) PrismHeaderPanel(com.evolveum.midpoint.web.component.prism.PrismHeaderPanel) IModel(org.apache.wicket.model.IModel) PrismReferencePanel(com.evolveum.midpoint.gui.impl.prism.panel.PrismReferencePanel) ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) QName(javax.xml.namespace.QName) ItemPanel(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanel) PropertyModel(org.apache.wicket.model.PropertyModel) StringResourceModel(org.apache.wicket.model.StringResourceModel)

Example 8 with ItemWrapper

use of com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper in project midpoint by Evolveum.

the class AbstractGuiIntegrationTest method getServiceLocator.

protected ModelServiceLocator getServiceLocator(final Task pageTask) {
    return new ModelServiceLocator() {

        @Override
        public ModelService getModelService() {
            return modelService;
        }

        @Override
        public ModelInteractionService getModelInteractionService() {
            return modelInteractionService;
        }

        @Override
        public DashboardService getDashboardService() {
            return dashboardService;
        }

        @Override
        public Task createSimpleTask(String operationName) {
            MidPointPrincipal user = AuthUtil.getPrincipalUser();
            if (user == null) {
                throw new IllegalStateException("No authenticated user");
            }
            return WebModelServiceUtils.createSimpleTask(operationName, SchemaConstants.CHANNEL_USER_URI, user.getFocus().asPrismObject(), taskManager);
        }

        @Override
        public PrismContext getPrismContext() {
            return prismContext;
        }

        @Override
        public SecurityEnforcer getSecurityEnforcer() {
            return securityEnforcer;
        }

        @Override
        public SecurityContextManager getSecurityContextManager() {
            return securityContextManager;
        }

        @NotNull
        @Override
        public CompiledGuiProfile getCompiledGuiProfile() {
            Task task = createSimpleTask("getCompiledGuiProfile");
            try {
                return getModelInteractionService().getCompiledGuiProfile(task, task.getResult());
            } catch (ObjectNotFoundException | SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException e) {
                throw new SystemException(e.getMessage(), e);
            }
        }

        @Override
        public Task getPageTask() {
            return pageTask;
        }

        @Override
        public ExpressionFactory getExpressionFactory() {
            return expressionFactory;
        }

        @Override
        public LocalizationService getLocalizationService() {
            return localizationService;
        }

        @Override
        public Locale getLocale() {
            return Locale.US;
        }

        @Override
        public GuiComponentRegistry getRegistry() {
            return registry;
        }

        @Override
        public <O extends ObjectType> PrismObjectWrapperFactory<O> findObjectWrapperFactory(PrismObjectDefinition<O> objectDef) {
            return registry.getObjectWrapperFactory(objectDef);
        }

        @Override
        public <I extends Item, IW extends ItemWrapper> IW createItemWrapper(I item, ItemStatus status, WrapperContext ctx) throws SchemaException {
            ItemWrapperFactory<IW, ?, ?> factory = registry.findWrapperFactory(item.getDefinition(), null);
            ctx.setCreateIfEmpty(true);
            return factory.createWrapper(null, item, status, ctx);
        }

        @Override
        public <IW extends ItemWrapper, VW extends PrismValueWrapper, PV extends PrismValue> VW createValueWrapper(IW parentWrapper, PV newValue, ValueStatus status, WrapperContext context) throws SchemaException {
            ItemWrapperFactory<IW, VW, PV> factory = registry.findWrapperFactory(parentWrapper, null);
            return factory.createValueWrapper(parentWrapper, newValue, status, context);
        }

        @Override
        public MidpointFormValidatorRegistry getFormValidatorRegistry() {
            return null;
        }

        @Override
        public AdminGuiConfigurationMergeManager getAdminGuiConfigurationMergeManager() {
            return null;
        }

        @Override
        public CorrelationService getCorrelationService() {
            return null;
        }
    };
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) Task(com.evolveum.midpoint.task.api.Task) ItemWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) PrismValueWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismValueWrapper) ValueStatus(com.evolveum.midpoint.web.component.prism.ValueStatus) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) ModelServiceLocator(com.evolveum.midpoint.gui.api.util.ModelServiceLocator)

Example 9 with ItemWrapper

use of com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper in project midpoint by Evolveum.

the class ShadowAssociationWrapperImpl method getDelta.

@Override
public <D extends ItemDelta<?, ?>> Collection<D> getDelta() throws SchemaException {
    Collection<D> deltas = new ArrayList<D>();
    ContainerDelta<ShadowAssociationType> delta = createEmptyDelta(getDeltaPathForStatus(getStatus()));
    switch(getStatus()) {
        case ADDED:
            if (CollectionUtils.isEmpty(getValues())) {
                return null;
            }
            // we know that there is always only one value
            PrismContainerValueWrapper<ShadowAssociationType> containerValueWrappers = getValues().iterator().next();
            for (ItemWrapper itemWrapper : containerValueWrappers.getItems()) {
                if (!(itemWrapper instanceof PrismReferenceWrapper)) {
                    LOGGER.warn("Item in shadow association value wrapper is not an reference. Should not happen.");
                    continue;
                }
                PrismReferenceWrapper refWrapper = (PrismReferenceWrapper) itemWrapper;
                for (PrismReferenceValueWrapperImpl updatedRefValue : (List<PrismReferenceValueWrapperImpl>) refWrapper.getValues()) {
                    if (updatedRefValue.getNewValue().isEmpty()) {
                        continue;
                    }
                    ShadowAssociationType shadowAssociationType = new ShadowAssociationType();
                    shadowAssociationType.asPrismContainerValue().applyDefinition(getItemDefinition());
                    shadowAssociationType.setName(refWrapper.getItemName());
                    shadowAssociationType.setShadowRef(ObjectTypeUtil.createObjectRef(updatedRefValue.getNewValue()));
                    delta.addValueToAdd(shadowAssociationType.asPrismContainerValue());
                }
            }
            if (delta.isEmpty()) {
                return null;
            }
            return (Collection) MiscUtil.createCollection(delta);
        case NOT_CHANGED:
            containerValueWrappers = getValues().iterator().next();
            for (ItemWrapper itemWrapper : containerValueWrappers.getItems()) {
                if (!(itemWrapper instanceof PrismReferenceWrapper)) {
                    LOGGER.warn("Item in shadow association value wrapper is not an reference. Should not happen.");
                    continue;
                }
                PrismReferenceWrapper refWrapper = (PrismReferenceWrapper) itemWrapper;
                for (PrismReferenceValueWrapperImpl updatedRefValue : (List<PrismReferenceValueWrapperImpl>) refWrapper.getValues()) {
                    if (updatedRefValue.getNewValue().isEmpty()) {
                        continue;
                    }
                    ShadowAssociationType shadowAssociationType = new ShadowAssociationType();
                    shadowAssociationType.asPrismContainerValue().applyDefinition(getItemDefinition());
                    shadowAssociationType.setName(refWrapper.getItemName());
                    shadowAssociationType.setShadowRef(ObjectTypeUtil.createObjectRef(updatedRefValue.getNewValue()));
                    switch(updatedRefValue.getStatus()) {
                        case ADDED:
                            delta.addValueToAdd(shadowAssociationType.asPrismContainerValue());
                            break;
                        case NOT_CHANGED:
                            break;
                        case DELETED:
                            delta.addValueToDelete(shadowAssociationType.asPrismContainerValue());
                            break;
                    }
                }
            }
            break;
        case DELETED:
            containerValueWrappers = getValues().iterator().next();
            for (ItemWrapper itemWrapper : containerValueWrappers.getItems()) {
                if (!(itemWrapper instanceof PrismReferenceWrapper)) {
                    LOGGER.warn("Item in shadow association value wrapper is not an reference. Should not happen.");
                    continue;
                }
                PrismReferenceWrapper refWrapper = (PrismReferenceWrapper) itemWrapper;
                for (PrismReferenceValueWrapperImpl updatedRefValue : (List<PrismReferenceValueWrapperImpl>) refWrapper.getValues()) {
                    if (updatedRefValue.getNewValue().isEmpty()) {
                        continue;
                    }
                    ShadowAssociationType shadowAssociationType = new ShadowAssociationType();
                    shadowAssociationType.asPrismContainerValue().applyDefinition(getItemDefinition());
                    shadowAssociationType.setName(refWrapper.getItemName());
                    shadowAssociationType.setShadowRef(ObjectTypeUtil.createObjectRef((PrismReferenceValue) updatedRefValue.getNewValue()));
                    delta.addValueToDelete(shadowAssociationType.asPrismContainerValue());
                }
            }
            break;
    }
    if (!delta.isEmpty()) {
        deltas.add((D) delta);
    }
    if (deltas.isEmpty()) {
        return null;
    }
    return deltas;
}
Also used : ItemWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper) PrismReferenceWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismReferenceWrapper) ArrayList(java.util.ArrayList) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)

Example 10 with ItemWrapper

use of com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper in project midpoint by Evolveum.

the class ListMappingPanel method initLayout.

private void initLayout() {
    MultivalueContainerListPanelWithDetailsPanel<MappingType> table = new MultivalueContainerListPanelWithDetailsPanel<MappingType>(ID_TABLE, MappingType.class) {

        @Override
        protected MultivalueContainerDetailsPanel<MappingType> getMultivalueContainerDetailsPanel(ListItem<PrismContainerValueWrapper<MappingType>> item) {
            return new MultivalueContainerDetailsPanel<>(MultivalueContainerListPanelWithDetailsPanel.ID_ITEM_DETAILS, item.getModel(), true) {

                @Override
                protected DisplayNamePanel<MappingType> createDisplayNamePanel(String displayNamePanelId) {
                    ItemRealValueModel<MappingType> displayNameModel = new ItemRealValueModel<>(item.getModel());
                    return new DisplayNamePanel<>(displayNamePanelId, displayNameModel) {

                        @Override
                        protected IModel<String> createHeaderModel() {
                            IModel<String> headerModel = super.createHeaderModel();
                            if (StringUtils.isEmpty(headerModel.getObject())) {
                                return getPageBase().createStringResource("feedbackMessagePanel.message.undefined");
                            }
                            return headerModel;
                        }
                    };
                }

                @Override
                protected ItemVisibility getBasicTabVisibity(ItemWrapper<?, ?> itemWrapper) {
                    if (itemWrapper.getPath().isSubPathOrEquivalent(ItemPath.create(ItemPath.EMPTY_PATH, MappingType.F_METADATA_MAPPING))) {
                        return ItemVisibility.HIDDEN;
                    }
                    return ItemVisibility.AUTO;
                }
            };
        }

        @Override
        protected boolean isCreateNewObjectVisible() {
            return true;
        }

        @Override
        protected IModel<PrismContainerWrapper<MappingType>> getContainerModel() {
            return ListMappingPanel.this.getModel();
        }

        @Override
        protected UserProfileStorage.TableId getTableId() {
            return null;
        }

        @Override
        protected List<IColumn<PrismContainerValueWrapper<MappingType>, String>> createDefaultColumns() {
            List<IColumn<PrismContainerValueWrapper<MappingType>, String>> columns = new ArrayList<>();
            columns.add(new PrismPropertyWrapperColumn<>(ListMappingPanel.this.getModel(), MappingType.F_DESCRIPTION, AbstractItemWrapperColumn.ColumnType.STRING, getPageBase()));
            columns.add(new PrismPropertyWrapperColumn<>(ListMappingPanel.this.getModel(), MappingType.F_ENABLED, AbstractItemWrapperColumn.ColumnType.VALUE, getPageBase()));
            columns.add(new AbstractColumn<>(createStringResource("ListMappingPanel.mappingDescription")) {

                @Override
                public void populateItem(Item<ICellPopulator<PrismContainerValueWrapper<MappingType>>> cellItem, String componentId, IModel<PrismContainerValueWrapper<MappingType>> rowModel) {
                    cellItem.add(new Label(componentId, WebComponentUtil.createMappingDescription(rowModel)));
                }
            });
            List<InlineMenuItem> items = new ArrayList<>();
            InlineMenuItem item = new InlineMenuItem(createStringResource("pageAdminFocus.button.delete")) {

                private static final long serialVersionUID = 1L;

                @Override
                public InlineMenuItemAction initAction() {
                    return new ColumnMenuAction() {

                        private static final long serialVersionUID = 1L;

                        @Override
                        public void onClick(AjaxRequestTarget target) {
                            deleteItemPerformed(target, getPerformedSelectedItems(getRowModel()));
                        }
                    };
                }
            };
            items.add(item);
            item = new ButtonInlineMenuItem(createStringResource("PageBase.button.edit")) {

                private static final long serialVersionUID = 1L;

                @Override
                public CompositedIconBuilder getIconCompositedBuilder() {
                    return getDefaultCompositedIconBuilder(GuiStyleConstants.CLASS_EDIT_MENU_ITEM);
                }

                @Override
                public InlineMenuItemAction initAction() {
                    return new ColumnMenuAction() {

                        private static final long serialVersionUID = 1L;

                        @Override
                        public void onClick(AjaxRequestTarget target) {
                            editItemPerformed(target, getRowModel(), getSelectedItems());
                            target.add(getFeedbackPanel());
                        }
                    };
                }
            };
            items.add(item);
            columns.add(new InlineMenuButtonColumn(items, getPageBase()) {

                @Override
                public String getCssClass() {
                    return "col-xs-1";
                }
            });
            return columns;
        }

        @Override
        protected IColumn<PrismContainerValueWrapper<MappingType>, String> createNameColumn(IModel<String> displayModel, GuiObjectColumnType customColumn, ItemPath itemPath, ExpressionType expression) {
            return new PrismPropertyWrapperColumn<>(ListMappingPanel.this.getModel(), MappingType.F_NAME, AbstractItemWrapperColumn.ColumnType.LINK, getPageBase()) {

                @Override
                protected void onClick(AjaxRequestTarget target, IModel<PrismContainerValueWrapper<MappingType>> model) {
                    itemDetailsPerformed(target, model);
                }
            };
        }

        @Override
        protected IColumn<PrismContainerValueWrapper<MappingType>, String> createCheckboxColumn() {
            return new CheckBoxHeaderColumn<>();
        }

        @Override
        protected PrismContainerDefinition<MappingType> getTypeDefinitionForSearch() {
            return getPrismContext().getSchemaRegistry().findContainerDefinitionByType(MappingType.COMPLEX_TYPE);
        }
    };
    add(table);
}
Also used : MultivalueContainerDetailsPanel(com.evolveum.midpoint.gui.impl.component.MultivalueContainerDetailsPanel) PrismContainerWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerWrapper) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) ItemWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper) UserProfileStorage(com.evolveum.midpoint.web.session.UserProfileStorage) DisplayNamePanel(com.evolveum.midpoint.gui.api.component.DisplayNamePanel) CheckBoxHeaderColumn(com.evolveum.midpoint.web.component.data.column.CheckBoxHeaderColumn) CompositedIconBuilder(com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) ButtonInlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem) ColumnMenuAction(com.evolveum.midpoint.web.component.data.column.ColumnMenuAction) ButtonInlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem) IModel(org.apache.wicket.model.IModel) PrismPropertyWrapperColumn(com.evolveum.midpoint.gui.impl.component.data.column.PrismPropertyWrapperColumn) InlineMenuButtonColumn(com.evolveum.midpoint.web.component.data.column.InlineMenuButtonColumn) ItemRealValueModel(com.evolveum.midpoint.gui.impl.factory.panel.ItemRealValueModel) ICellPopulator(org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) MultivalueContainerListPanelWithDetailsPanel(com.evolveum.midpoint.gui.impl.component.MultivalueContainerListPanelWithDetailsPanel) InlineMenuItemAction(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction) ListItem(org.apache.wicket.markup.html.list.ListItem) PrismContainerValueWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ItemWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper)23 ArrayList (java.util.ArrayList)9 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)8 PanelTab (com.evolveum.midpoint.gui.api.component.tabs.PanelTab)7 SingleContainerPanel (com.evolveum.midpoint.gui.impl.prism.panel.SingleContainerPanel)7 ITab (org.apache.wicket.extensions.markup.html.tabs.ITab)6 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)6 DisplayNamePanel (com.evolveum.midpoint.gui.api.component.DisplayNamePanel)5 MultivalueContainerDetailsPanel (com.evolveum.midpoint.gui.impl.component.MultivalueContainerDetailsPanel)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 ItemVisibility (com.evolveum.midpoint.web.component.prism.ItemVisibility)5 QName (javax.xml.namespace.QName)5 PrismContainerWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerWrapper)4 List (java.util.List)4 IModel (org.apache.wicket.model.IModel)4 ResourceAttributePanel (com.evolveum.midpoint.gui.impl.prism.panel.ResourceAttributePanel)3 WrapperContext (com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)2 ReadOnlyModel (com.evolveum.midpoint.gui.api.model.ReadOnlyModel)2 PrismContainerValueWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper)2 Task (com.evolveum.midpoint.task.api.Task)2