Search in sources :

Example 1 with PrismPropertyWrapper

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

the class NotificationConfigTabPanel method initLayout.

protected void initLayout() {
    PrismPropertyWrapperModel<NotificationConfigurationType, MailConfigurationType> mailConfig = PrismPropertyWrapperModel.fromContainerWrapper(getModel(), NotificationConfigurationType.F_MAIL);
    add(createHeader(ID_MAIL_CONFIG_HEADER, mailConfig));
    PropertyModel<MailConfigurationType> mailConfigType = new ItemRealValueModel<>(new PropertyModel<>(mailConfig, "values[0]"));
    if (mailConfigType.getObject() == null) {
        // TODO: This fails for deprecated "mail" element if it's missing, so it's not deprecated yet.
        // Reason: mailConfig.getObject() == null
        // Root cause: ItemWrapperFactoryImpl.skipCreateWrapper() has a code to skip empty & deprecated stuff.
        // The object for mailConfig can't be created with createItemWrapper either as it would be skipped again and return null.
        // Let's create new GUI for the new transport configuration first without to-be deprecated components.
        mailConfigType.setObject(new MailConfigurationType());
    }
    add(new TextFormGroup(ID_DEFAULT_FROM, new PropertyModel<>(mailConfigType, "defaultFrom"), createStringResource(mailConfig.getObject().getTypeName().getLocalPart() + ".defaultFrom"), "", getInputCssClass(), false, true));
    add(new TextFormGroup(ID_REDIRECT_TO_FILE, new PropertyModel<>(mailConfigType, "redirectToFile"), createStringResource(mailConfig.getObject().getTypeName().getLocalPart() + ".redirectToFile"), "", getInputCssClass(), false, true));
    add(new TextFormGroup(ID_LOG_TO_FILE, new PropertyModel<>(mailConfigType, "logToFile"), createStringResource(mailConfig.getObject().getTypeName().getLocalPart() + ".logToFile"), "", getInputCssClass(), false, true));
    add(new TriStateFormGroup(ID_DEBUG, new PropertyModel<>(mailConfigType, "debug"), createStringResource(mailConfig.getObject().getTypeName().getLocalPart() + ".debug"), "", getInputCssClass(), false, true));
    add(createHeader(ID_MAIL_SERVER_CONFIG_HEADER, MailServerConfigurationType.COMPLEX_TYPE.getLocalPart() + ".details"));
    add(initServersTable(mailConfigType));
    add(createHeader(ID_FILE_CONFIG_HEADER, FileConfigurationType.COMPLEX_TYPE.getLocalPart() + ".details"));
    IModel<PrismPropertyWrapper<FileConfigurationType>> fileConfig = PrismPropertyWrapperModel.fromContainerWrapper(getModel(), NotificationConfigurationType.F_FILE);
    WebMarkupContainer files = new WebMarkupContainer(ID_FILE_CONFIG);
    files.setOutputMarkupId(true);
    add(files);
    ListView<PrismPropertyValueWrapper<FileConfigurationType>> values = new ListView<>("values", new PropertyModel<>(fileConfig, "values")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<PrismPropertyValueWrapper<FileConfigurationType>> item) {
            FileConfigurationType fileConfigType = item.getModelObject().getRealValue();
            item.add(createHeader(ID_VALUE_HEADER, fileConfigType == null || fileConfigType.getName() == null || fileConfigType.getName().isEmpty() ? (FileConfigurationType.COMPLEX_TYPE.getLocalPart() + ".details") : fileConfigType.getName()));
            AjaxLink<Void> removeButton = new AjaxLink<>(ID_REMOVE_BUTTON) {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    ((PrismPropertyValue<FileConfigurationType>) item.getModelObject()).setValue(null);
                    item.getParent().remove(item.getId());
                    target.add(files);
                }
            };
            item.add(removeButton);
            TextFormGroup name = new TextFormGroup(ID_FILE_NAME, fileConfigType != null ? new PropertyModel<>(fileConfigType, "name") : Model.of(""), createStringResource(fileConfigType == null ? "" : (fileConfigType.COMPLEX_TYPE.getLocalPart() + ".name")), "", getInputCssClass(), false, true);
            name.getField().add(new OnChangeAjaxBehavior() {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    item.getModelObject().getRealValue().setName(name.getModelObject());
                }
            });
            item.add(name);
            TextFormGroup file = new TextFormGroup(ID_FILE_PATH, fileConfigType != null ? new PropertyModel<>(fileConfigType, "file") : Model.of(""), createStringResource(fileConfigType == null ? "" : (fileConfigType.COMPLEX_TYPE.getLocalPart() + ".file")), "", getInputCssClass(), false, true);
            file.getField().add(new OnChangeAjaxBehavior() {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    item.getModelObject().getRealValue().setFile(file.getModelObject());
                }
            });
            item.add(file);
            item.add(new VisibleEnableBehaviour() {

                @Override
                public boolean isVisible() {
                    return fileConfigType != null;
                }
            });
        }
    };
    values.add(new AttributeModifier("class", "col-md-6"));
    values.setReuseItems(true);
    files.add(values);
    AjaxLink<Void> addButton = new AjaxLink<>(ID_ADD_BUTTON) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            PrismPropertyWrapper<FileConfigurationType> propertyWrapper = fileConfig.getObject();
            PrismPropertyValue<FileConfigurationType> newValue = getPrismContext().itemFactory().createPropertyValue();
            PrismPropertyValueWrapper<FileConfigurationType> newValueWrapper = WebPrismUtil.createNewValueWrapper(propertyWrapper, newValue, getPageBase(), target);
            // TODO: do we really need to set real value?? why??
            newValueWrapper.setRealValue(new FileConfigurationType());
            target.add(files);
        }
    };
    add(addButton);
}
Also used : TextFormGroup(com.evolveum.midpoint.web.component.form.TextFormGroup) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) PrismPropertyValueWrapper(com.evolveum.midpoint.gui.impl.prism.wrapper.PrismPropertyValueWrapper) ListView(org.apache.wicket.markup.html.list.ListView) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) PrismPropertyWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismPropertyWrapper) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) ItemRealValueModel(com.evolveum.midpoint.gui.impl.factory.panel.ItemRealValueModel) PropertyModel(org.apache.wicket.model.PropertyModel) TriStateFormGroup(com.evolveum.midpoint.gui.impl.component.form.TriStateFormGroup) AttributeModifier(org.apache.wicket.AttributeModifier) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ListItem(org.apache.wicket.markup.html.list.ListItem)

Example 2 with PrismPropertyWrapper

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

the class WrapperTestUtil method fillInPropertyWrapper.

public static <C extends Containerable, T> void fillInPropertyWrapper(ModelServiceLocator modelServiceLocator, PrismContainerValueWrapper<C> containerWrapper, ItemPath itemPath, T... newValues) throws SchemaException {
    PrismPropertyWrapper itemWrapper = containerWrapper.findProperty(itemPath);
    assertNotNull("No item wrapper for path " + itemPath + " in " + containerWrapper, itemWrapper);
    fillInPropertyWrapper(modelServiceLocator, itemWrapper, itemPath.lastName(), newValues);
}
Also used : PrismPropertyWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismPropertyWrapper)

Example 3 with PrismPropertyWrapper

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

the class ResourceAttributeRefPanelFactory method getChoicesList.

private List<ItemName> getChoicesList(PrismPropertyPanelContext<ItemPathType> ctx) {
    PrismPropertyWrapper<?> wrapper = ctx.unwrapWrapperModel();
    // attribute/ref
    if (wrapper == null) {
        return Collections.emptyList();
    }
    // attribute value
    if (wrapper.getParent() == null) {
        return Collections.emptyList();
    }
    // attribute
    ItemWrapper<?, ?> attributeWrapper = wrapper.getParent().getParent();
    if (attributeWrapper == null) {
        return Collections.emptyList();
    }
    PrismContainerValueWrapper<?> itemWrapper = attributeWrapper.getParent();
    if (itemWrapper == null) {
        return Collections.emptyList();
    }
    if (!(itemWrapper instanceof ConstructionValueWrapper)) {
        return Collections.emptyList();
    }
    ConstructionValueWrapper constructionWrapper = (ConstructionValueWrapper) itemWrapper;
    try {
        ResourceSchema schema = constructionWrapper.getRefinedSchema();
        if (schema == null) {
            return new ArrayList<>();
        }
        ResourceObjectDefinition rOcd = schema.findObjectDefinition(constructionWrapper.getKind(), constructionWrapper.getIntent());
        if (rOcd == null) {
            return Collections.emptyList();
        }
        if (ConstructionType.F_ASSOCIATION.equivalent(attributeWrapper.getItemName())) {
            Collection<ResourceAssociationDefinition> associationDefs = rOcd.getAssociationDefinitions();
            return associationDefs.stream().map(ResourceAssociationDefinition::getName).collect(Collectors.toList());
        }
        Collection<? extends ResourceAttributeDefinition<?>> attrDefs = rOcd.getAttributeDefinitions();
        return attrDefs.stream().map(a -> a.getItemName()).collect(Collectors.toList());
    } catch (SchemaException e) {
        LOGGER.warn("Cannot get resource attribute definitions");
    }
    return Collections.emptyList();
}
Also used : ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) ArrayList(java.util.ArrayList) PrismPropertyWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismPropertyWrapper) ConstructionValueWrapper(com.evolveum.midpoint.gui.impl.prism.wrapper.ConstructionValueWrapper) IModel(org.apache.wicket.model.IModel) PrismContainerValueWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Serializable(java.io.Serializable) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition) List(java.util.List) Component(org.springframework.stereotype.Component) ItemName(com.evolveum.midpoint.prism.path.ItemName) PostConstruct(javax.annotation.PostConstruct) AutoCompleteQNamePanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteQNamePanel) ItemWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) Collections(java.util.Collections) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ConstructionValueWrapper(com.evolveum.midpoint.gui.impl.prism.wrapper.ConstructionValueWrapper) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ArrayList(java.util.ArrayList) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)

Aggregations

PrismPropertyWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismPropertyWrapper)3 AutoCompleteQNamePanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteQNamePanel)1 ItemWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper)1 PrismContainerValueWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper)1 TriStateFormGroup (com.evolveum.midpoint.gui.impl.component.form.TriStateFormGroup)1 ItemRealValueModel (com.evolveum.midpoint.gui.impl.factory.panel.ItemRealValueModel)1 ConstructionValueWrapper (com.evolveum.midpoint.gui.impl.prism.wrapper.ConstructionValueWrapper)1 PrismPropertyValueWrapper (com.evolveum.midpoint.gui.impl.prism.wrapper.PrismPropertyValueWrapper)1 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)1 ItemName (com.evolveum.midpoint.prism.path.ItemName)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 ResourceAssociationDefinition (com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)1 ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)1 ResourceObjectDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)1 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 Trace (com.evolveum.midpoint.util.logging.Trace)1 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)1 TextFormGroup (com.evolveum.midpoint.web.component.form.TextFormGroup)1 InputPanel (com.evolveum.midpoint.web.component.prism.InputPanel)1