Search in sources :

Example 6 with GenericMultiValueLabelEditPanel

use of com.evolveum.midpoint.web.component.form.multivalue.GenericMultiValueLabelEditPanel in project midpoint by Evolveum.

the class ConstructionAssociationPanel method initLayout.

protected void initLayout() {
    ListView<ResourceAssociationDefinition> associationsPanel = new ListView<ResourceAssociationDefinition>(ID_ASSOCIATIONS, refinedAssociationDefinitionsModel) {

        @Override
        protected void populateItem(ListItem<ResourceAssociationDefinition> item) {
            GenericMultiValueLabelEditPanel associationReferencesPanel = new GenericMultiValueLabelEditPanel<ObjectReferenceType>(ID_ASSOCIATION_REFERENCE_PANEL, getShadowReferencesModel(item.getModelObject()), Model.of(WebComponentUtil.getAssociationDisplayName(item.getModelObject())), ID_LABEL_SIZE, ID_INPUT_SIZE, true) {

                private static final long serialVersionUID = 1L;

                @Override
                protected boolean isEditButtonEnabled() {
                    return false;
                }

                @Override
                protected void addValuePerformed(AjaxRequestTarget target) {
                    addNewShadowRefValuePerformed(target, item.getModelObject());
                }

                protected void addFirstPerformed(AjaxRequestTarget target) {
                    addNewShadowRefValuePerformed(target, item.getModelObject());
                }

                @Override
                protected IModel<String> createTextModel(final IModel<ObjectReferenceType> model) {
                    return new IModel<String>() {

                        private static final long serialVersionUID = 1L;

                        @Override
                        public String getObject() {
                            ObjectReferenceType obj = model.getObject();
                            if (obj == null) {
                                return "";
                            }
                            return WebComponentUtil.getDisplayNameOrName(obj, getPageBase(), OPERATION_LOAD_SHADOW_DISPLAY_NAME);
                        }
                    };
                }

                @Override
                protected void removeValuePerformed(AjaxRequestTarget target, ListItem<ObjectReferenceType> item) {
                    try {
                        ObjectReferenceType removedShadowRef = item.getModelObject();
                        PrismContainerWrapper<ConstructionType> constructionContainerWrapper = ConstructionAssociationPanel.this.getModelObject();
                        PrismContainerWrapper<ResourceObjectAssociationType> associationWrapper = constructionContainerWrapper.findContainer(ConstructionType.F_ASSOCIATION);
                        associationWrapper.getValues().forEach(associationValueWrapper -> {
                            if (ValueStatus.DELETED.equals(associationValueWrapper.getStatus())) {
                                return;
                            }
                            ResourceObjectAssociationType associationValue = associationValueWrapper.getRealValue();
                            // ResourceObjectAssociationType assoc = (ResourceObjectAssociationType) associationValue.asContainerable();
                            if (associationValue == null || associationValue.getOutbound() == null || associationValue.getOutbound().getExpression() == null || ExpressionUtil.getShadowRefValue(associationValue.getOutbound().getExpression(), ConstructionAssociationPanel.this.getPageBase().getPrismContext()) == null) {
                                return;
                            }
                            List<ObjectReferenceType> shadowRefList = ExpressionUtil.getShadowRefValue(associationValue.getOutbound().getExpression(), ConstructionAssociationPanel.this.getPageBase().getPrismContext());
                            shadowRefList.forEach(shadowRef -> {
                                if (shadowRef.equals(removedShadowRef)) {
                                    associationValueWrapper.setStatus(ValueStatus.DELETED);
                                }
                            });
                        });
                    } catch (SchemaException ex) {
                        LOGGER.error("Couldn't remove association value: {}", ex.getLocalizedMessage());
                    }
                    super.removeValuePerformed(target, item);
                }
            };
            associationReferencesPanel.setOutputMarkupId(true);
            item.add(associationReferencesPanel);
        }
    };
    associationsPanel.setOutputMarkupId(true);
    add(associationsPanel);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IModel(org.apache.wicket.model.IModel) GenericMultiValueLabelEditPanel(com.evolveum.midpoint.web.component.form.multivalue.GenericMultiValueLabelEditPanel) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ListView(org.apache.wicket.markup.html.list.ListView) ListItem(org.apache.wicket.markup.html.list.ListItem)

Aggregations

GenericMultiValueLabelEditPanel (com.evolveum.midpoint.web.component.form.multivalue.GenericMultiValueLabelEditPanel)6 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)6 IModel (org.apache.wicket.model.IModel)6 List (java.util.List)3 ListItem (org.apache.wicket.markup.html.list.ListItem)3 ObjectBrowserPanel (com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel)2 MultiplicityPolicyPanel (com.evolveum.midpoint.web.page.admin.roles.component.MultiplicityPolicyPanel)2 MultiplicityPolicyConstraintType (com.evolveum.midpoint.xml.ns._public.common.common_3.MultiplicityPolicyConstraintType)2 PolicyConstraintsType (com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyConstraintsType)2 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 ResourceAssociationDefinition (com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 RichHyperlinkType (com.evolveum.midpoint.xml.ns._public.common.common_3.RichHyperlinkType)1 RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)1 ListView (org.apache.wicket.markup.html.list.ListView)1 PropertyModel (org.apache.wicket.model.PropertyModel)1