Search in sources :

Example 1 with PrismPropertyValueWrapper

use of com.evolveum.midpoint.gui.impl.prism.wrapper.PrismPropertyValueWrapper 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 PrismPropertyValueWrapper

use of com.evolveum.midpoint.gui.impl.prism.wrapper.PrismPropertyValueWrapper in project midpoint by Evolveum.

the class WebComponentUtil method getAssociationExpression.

// TODO refactor..
@Deprecated
public static ExpressionType getAssociationExpression(PrismContainerValueWrapper<AssignmentType> assignmentValueWrapper, boolean createIfNotExist, PrismContext prismContext, PageBase pageBase) {
    if (assignmentValueWrapper == null) {
        return null;
    }
    if (createIfNotExist && prismContext == null) {
        throw new IllegalArgumentException("createIfNotExist is set but prismContext is null");
    }
    PrismContainerWrapper<ResourceObjectAssociationType> association;
    try {
        association = assignmentValueWrapper.findContainer(ItemPath.create(AssignmentType.F_CONSTRUCTION, ConstructionType.F_ASSOCIATION));
    } catch (SchemaException e) {
        LOGGER.error("Cannot find association wrapper, reason: {}", e.getMessage(), e);
        pageBase.getSession().error("Cannot find association wrapper, reason: " + e.getMessage());
        return null;
    }
    if (association == null || association.getValues() == null || association.getValues().size() == 0) {
        return null;
    }
    PrismContainerValueWrapper<ResourceObjectAssociationType> associationValueWrapper = association.getValues().get(0);
    PrismPropertyWrapper<ExpressionType> expressionWrapper;
    try {
        expressionWrapper = associationValueWrapper.findProperty(ItemPath.create(ResourceObjectAssociationType.F_OUTBOUND, MappingType.F_EXPRESSION));
    } catch (SchemaException e) {
        LOGGER.error("Cannot find expression wrapper, reason: {}", e.getMessage(), e);
        pageBase.getSession().error("Cannot find expression wrapper, reason: " + e.getMessage());
        return null;
    }
    if (expressionWrapper == null) {
        return null;
    }
    List<PrismPropertyValueWrapper<ExpressionType>> expressionValues = expressionWrapper.getValues();
    if (expressionValues == null || expressionValues.size() == 0) {
        return null;
    }
    try {
        ExpressionType expression = expressionValues.get(0).getRealValue();
        if (expression == null && createIfNotExist) {
            expression = new ExpressionType();
            PrismPropertyValue<ExpressionType> exp = prismContext.itemFactory().createPropertyValue(expression);
            WrapperContext context = new WrapperContext(null, null);
            PrismPropertyValueWrapper<ExpressionType> val = (PrismPropertyValueWrapper<ExpressionType>) pageBase.createValueWrapper(expressionWrapper, exp, ValueStatus.ADDED, context);
            // ValueWrapperOld<ExpressionType> val = new
            // ValueWrapperOld<>(expressionWrapper, exp, prismContext);
            expressionValues.remove(0);
            expressionValues.add(0, val);
        }
    } catch (SchemaException e) {
        // TODO erro handling
        return null;
    }
    return expressionValues.get(0).getRealValue();
}
Also used : PrismPropertyValueWrapper(com.evolveum.midpoint.gui.impl.prism.wrapper.PrismPropertyValueWrapper) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)

Example 3 with PrismPropertyValueWrapper

use of com.evolveum.midpoint.gui.impl.prism.wrapper.PrismPropertyValueWrapper in project midpoint by Evolveum.

the class TestIntegrationObjectWrapperFactory method modifyPropertyWrapper.

private void modifyPropertyWrapper(ModelServiceLocator modelServiceLocator, PrismContainerValueWrapper<OrgType> mainContainerValueWrapper, ItemPath propPath, String newValue) throws SchemaException {
    PrismPropertyWrapper propertyWrapper = mainContainerValueWrapper.findProperty(propPath);
    List<PrismPropertyValueWrapper<String>> values = propertyWrapper.getValues();
    if (values.size() == 1) {
        values.get(0).setRealValue(newValue);
    } else if (values.isEmpty()) {
        PrismPropertyValue<String> pval = prismContext.itemFactory().createPropertyValue(newValue);
        WrapperContext context = new WrapperContext(modelServiceLocator.getPageTask(), modelServiceLocator.getPageTask().getResult());
        context.setShowEmpty(true);
        context.setCreateIfEmpty(true);
        PrismValueWrapper<String> newValueWrapper = modelServiceLocator.createValueWrapper(propertyWrapper, pval, ValueStatus.ADDED, context);
        newValueWrapper.setRealValue(newValue);
        propertyWrapper.getItem().add(pval);
        propertyWrapper.getValues().add(newValueWrapper);
    } else {
        throw new IllegalArgumentException("Cannot use on multivalue props");
    }
}
Also used : PrismPropertyValueWrapper(com.evolveum.midpoint.gui.impl.prism.wrapper.PrismPropertyValueWrapper) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)

Aggregations

PrismPropertyValueWrapper (com.evolveum.midpoint.gui.impl.prism.wrapper.PrismPropertyValueWrapper)3 WrapperContext (com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)2 PrismPropertyWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismPropertyWrapper)1 TriStateFormGroup (com.evolveum.midpoint.gui.impl.component.form.TriStateFormGroup)1 ItemRealValueModel (com.evolveum.midpoint.gui.impl.factory.panel.ItemRealValueModel)1 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)1 TextFormGroup (com.evolveum.midpoint.web.component.form.TextFormGroup)1 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)1 AttributeModifier (org.apache.wicket.AttributeModifier)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 OnChangeAjaxBehavior (org.apache.wicket.ajax.form.OnChangeAjaxBehavior)1 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)1 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)1 ListItem (org.apache.wicket.markup.html.list.ListItem)1 ListView (org.apache.wicket.markup.html.list.ListView)1 PropertyModel (org.apache.wicket.model.PropertyModel)1