Search in sources :

Example 6 with EnableBehaviour

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

the class OperationalButtonsPanel method createSaveButton.

private void createSaveButton(RepeatingView repeatingView) {
    CompositedIconBuilder iconBuilder = new CompositedIconBuilder().setBasicIcon(GuiStyleConstants.CLASS_ICON_SAVE, LayeredIconCssStyle.IN_ROW_STYLE);
    AjaxCompositedIconSubmitButton save = new AjaxCompositedIconSubmitButton(repeatingView.newChildId(), iconBuilder.build(), getPageBase().createStringResource("PageBase.button.save")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            savePerformed(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(getPageBase().getFeedbackPanel());
        }
    };
    save.add(new VisibleBehaviour(this::isSaveButtonVisible));
    save.add(new EnableBehaviour(this::isSavePreviewButtonEnabled));
    save.titleAsLabel(true);
    save.setOutputMarkupId(true);
    save.add(AttributeAppender.append("class", "btn btn-success btn-sm"));
    repeatingView.add(save);
    Form form = save.findParent(Form.class);
    if (form != null) {
        form.setDefaultButton(save);
    }
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) Form(org.apache.wicket.markup.html.form.Form) CompositedIconBuilder(com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder) AjaxCompositedIconSubmitButton(com.evolveum.midpoint.web.component.AjaxCompositedIconSubmitButton) EnableBehaviour(com.evolveum.midpoint.web.component.util.EnableBehaviour)

Example 7 with EnableBehaviour

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

the class ReferenceValueSearchPopupPanel method customizationPopoverForm.

@Override
protected void customizationPopoverForm(MidpointForm midpointForm) {
    FeedbackAlerts feedback = new FeedbackAlerts(ID_FEEDBACK);
    feedback.setOutputMarkupId(true);
    midpointForm.add(feedback);
    PropertyModel<String> oidModel = new PropertyModel<>(getModel(), "oid") {

        @Override
        public void setObject(String object) {
            super.setObject(object);
            if (StringUtils.isBlank(object)) {
                ReferenceValueSearchPopupPanel.this.getModelObject().asReferenceValue().setObject(null);
                ReferenceValueSearchPopupPanel.this.getModelObject().setTargetName(null);
                ReferenceValueSearchPopupPanel.this.getModelObject().setRelation(null);
            }
        }
    };
    TextField<String> oidField = new TextField<>(ID_OID, oidModel);
    oidField.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    oidField.setOutputMarkupId(true);
    oidField.add(new EnableBehaviour(this::isItemPanelEnabled));
    midpointForm.add(oidField);
    ReferenceAutocomplete nameField = new ReferenceAutocomplete(ID_NAME, Model.of(getModelObject()), new AutoCompleteReferenceRenderer(), getPageBase()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected boolean isAllowedNotFoundObjectRef() {
            return ReferenceValueSearchPopupPanel.this.isAllowedNotFoundObjectRef();
        }

        @Override
        protected <O extends ObjectType> Class<O> getReferenceTargetObjectType() {
            if (getModelObject() != null && getModelObject().getType() != null) {
                return (Class<O>) WebComponentUtil.qnameToClass(PrismContext.get(), getModelObject().getType());
            }
            return super.getReferenceTargetObjectType();
        }
    };
    feedback.setFilter(new ComponentFeedbackMessageFilter(nameField));
    nameField.getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("blur") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            updateModel(nameField.getBaseFormComponent().getModelObject(), midpointForm, target);
        }
    });
    nameField.setOutputMarkupId(true);
    nameField.add(new EnableBehaviour(this::isItemPanelEnabled));
    midpointForm.add(nameField);
    DropDownChoicePanel<QName> type = new DropDownChoicePanel<>(ID_TYPE, new PropertyModel<>(getModel(), "type"), Model.ofList(getSupportedTargetList()), new QNameObjectTypeChoiceRenderer(), true);
    type.setOutputMarkupId(true);
    type.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isEnabled() {
            return getSupportedTargetList().size() > 1 && isItemPanelEnabled();
        }
    });
    type.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    type.getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("change") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            ObjectReferenceType ref = nameField.getAutoCompleteConverter(ObjectReferenceType.class, null).convertToObject(nameField.getBaseFormComponent().getValue(), WebComponentUtil.getCurrentLocale());
            updateModel(ref, midpointForm, target);
            target.add(oidField);
            target.add(ReferenceValueSearchPopupPanel.this);
        }
    });
    midpointForm.add(type);
    WebMarkupContainer relationContainer = new WebMarkupContainer(ID_RELATION_CONTAINER);
    midpointForm.add(relationContainer);
    relationContainer.add(new VisibleBehaviour(() -> getAllowedRelations().size() > 0));
    List<QName> allowedRelations = new ArrayList<>(getAllowedRelations());
    DropDownChoicePanel<QName> relation = new DropDownChoicePanel<>(ID_RELATION, new PropertyModel<>(getModel(), "relation"), Model.ofList(allowedRelations), new QNameObjectTypeChoiceRenderer(), true);
    relation.setOutputMarkupId(true);
    relation.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isEnabled() {
            return getAllowedRelations().size() > 1 && isItemPanelEnabled();
        }
    });
    relation.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    relationContainer.add(relation);
    AjaxButton selectObject = new AjaxButton(ID_SELECT_OBJECT_BUTTON, createStringResource("ReferenceValueSearchPopupPanel.selectObject")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            List<QName> supportedTypes = getSupportedTargetList();
            if (CollectionUtils.isEmpty(supportedTypes)) {
                supportedTypes = WebComponentUtil.createObjectTypeList();
            }
            ObjectBrowserPanel<O> objectBrowserPanel = new ObjectBrowserPanel<>(getPageBase().getMainPopupBodyId(), null, supportedTypes, false, getPageBase(), null) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onSelectPerformed(AjaxRequestTarget target, O object) {
                    getPageBase().hideMainPopup(target);
                    if (ReferenceValueSearchPopupPanel.this.getModel().getObject() == null) {
                        ReferenceValueSearchPopupPanel.this.getModel().setObject(new ObjectReferenceType());
                    }
                    ReferenceValueSearchPopupPanel.this.getModelObject().setOid(object.getOid());
                    ReferenceValueSearchPopupPanel.this.getModelObject().setTargetName(object.getName());
                    ReferenceValueSearchPopupPanel.this.getModelObject().setType(object.asPrismObject().getComplexTypeDefinition().getTypeName());
                    target.add(oidField);
                    target.add(nameField);
                    target.add(type);
                }
            };
            getPageBase().showMainPopup(objectBrowserPanel, target);
        }
    };
    selectObject.add(new VisibleBehaviour(() -> getPageBase().getMainPopup().getContentComponent() == null));
    midpointForm.add(selectObject);
}
Also used : DropDownChoicePanel(com.evolveum.midpoint.web.component.input.DropDownChoicePanel) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) EmptyOnBlurAjaxFormUpdatingBehaviour(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour) ArrayList(java.util.ArrayList) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) AutoCompleteReferenceRenderer(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteReferenceRenderer) TextField(org.apache.wicket.markup.html.form.TextField) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) EnableBehaviour(com.evolveum.midpoint.web.component.util.EnableBehaviour) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) QName(javax.xml.namespace.QName) PropertyModel(org.apache.wicket.model.PropertyModel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ComponentFeedbackMessageFilter(org.apache.wicket.feedback.ComponentFeedbackMessageFilter) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) FeedbackAlerts(com.evolveum.midpoint.web.component.message.FeedbackAlerts) ObjectBrowserPanel(com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel) QNameObjectTypeChoiceRenderer(com.evolveum.midpoint.web.component.input.QNameObjectTypeChoiceRenderer)

Example 8 with EnableBehaviour

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

the class PolyStringEditorPanel method initLayout.

private void initLayout() {
    setOutputMarkupId(true);
    String localizedValue = getLocalizedPolyStringValue();
    WebMarkupContainer localizedValueContainer = new WebMarkupContainer(ID_LOCALIZED_VALUE_CONTAINER);
    localizedValueContainer.setOutputMarkupId(true);
    localizedValueContainer.add(getInputFieldClassAppenderForContainer());
    localizedValueContainer.add(new VisibleBehaviour(() -> showFullData || StringUtils.isNotEmpty(localizedValue)));
    add(localizedValueContainer);
    Label localizedValueLabel = new Label(ID_LOCALIZED_VALUE_LABEL, ((PageBase) getPage()).createStringResource("PolyStringEditorPanel.localizedValue"));
    localizedValueLabel.setOutputMarkupId(true);
    localizedValueLabel.add(new VisibleBehaviour(() -> showFullData));
    localizedValueContainer.add(localizedValueLabel);
    WebMarkupContainer localizedValueWithButton = new WebMarkupContainer(ID_LOCALIZED_VALUE_WITH_BUTTON);
    localizedValueWithButton.setOutputMarkupId(true);
    localizedValueWithButton.add(getInputFieldClassAppender());
    localizedValueContainer.add(localizedValueWithButton);
    TextPanel<String> localizedValuePanel = new TextPanel<>(ID_LOCALIZED_VALUE_PANEL, Model.of(localizedValue));
    localizedValuePanel.setOutputMarkupId(true);
    localizedValuePanel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    localizedValuePanel.add(new EnableBehaviour(() -> false));
    localizedValueWithButton.add(localizedValuePanel);
    AjaxButton showHideLanguagesLocalizedButton = new AjaxButton(ID_SHOW_HIDE_LANGUAGES_LOCALIZED) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            showHideLanguagesPerformed(target);
        }
    };
    showHideLanguagesLocalizedButton.setOutputMarkupId(true);
    // showHideLanguagesLocalizedButton.add(AttributeAppender.append("style", "cursor: pointer;"));
    localizedValueWithButton.add(showHideLanguagesLocalizedButton);
    WebMarkupContainer originValueContainer = new WebMarkupContainer(ID_ORIGIN_VALUE_CONTAINER);
    originValueContainer.setOutputMarkupId(true);
    originValueContainer.add(getInputFieldClassAppenderForContainer());
    originValueContainer.add(new VisibleBehaviour(() -> showFullData || StringUtils.isEmpty(localizedValue)));
    add(originValueContainer);
    Label origValueLabel = new Label(ID_ORIG_VALUE_LABEL, ((PageBase) getPage()).createStringResource("PolyStringEditorPanel.origValue"));
    origValueLabel.setOutputMarkupId(true);
    origValueLabel.add(new VisibleBehaviour(() -> showFullData));
    originValueContainer.add(origValueLabel);
    WebMarkupContainer origValueWithButton = new WebMarkupContainer(ID_ORIG_VALUE_WITH_BUTTON);
    origValueWithButton.add(getInputFieldClassAppender());
    origValueWithButton.setOutputMarkupId(true);
    originValueContainer.add(origValueWithButton);
    InputPanel origValuePanel;
    IModel<String> origValueModel = new IModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return getModelObject() != null ? getModelObject().getOrig() : null;
        }

        @Override
        public void setObject(String object) {
            PolyString oldModelObject = getModelObject();
            if (oldModelObject != null && (oldModelObject.getTranslation() != null || MapUtils.isNotEmpty(oldModelObject.getLang()))) {
                getModel().setObject(new PolyString(object, oldModelObject.getNorm(), oldModelObject.getTranslation(), oldModelObject.getLang()));
            } else if (StringUtils.isNotBlank(object)) {
                getModel().setObject(new PolyString(object));
            } else {
                getModel().setObject(null);
            }
        }

        @Override
        public void detach() {
        }
    };
    if (predefinedValuesLookupTable == null) {
        origValuePanel = new TextPanel<>(ID_ORIG_VALUE, origValueModel, String.class, false);
    } else {
        origValuePanel = new AutoCompleteTextPanel<String>(ID_ORIG_VALUE, origValueModel, String.class, hasValueEnumerationRef, predefinedValuesLookupTable) {

            private static final long serialVersionUID = 1L;

            @Override
            public Iterator<String> getIterator(String input) {
                return getPredefinedValuesIterator(input).iterator();
            }
        };
    }
    origValuePanel.setOutputMarkupId(true);
    origValuePanel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    origValueWithButton.add(origValuePanel);
    WebMarkupContainer fullDataContainer = new WebMarkupContainer(ID_FULL_DATA_CONTAINER);
    fullDataContainer.setOutputMarkupId(true);
    fullDataContainer.add(new VisibleBehaviour(() -> showFullData));
    add(fullDataContainer);
    TextPanel<String> keyValue = new TextPanel<>(ID_KEY_VALUE, new IModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return getModelObject() != null && getModelObject().getTranslation() != null ? getModelObject().getTranslation().getKey() : null;
        }

        @Override
        public void setObject(String object) {
            if (getModelObject() == null) {
                getModel().setObject(new PolyString(""));
            }
            if (getModelObject().getTranslation() == null) {
                getModelObject().setTranslation(new PolyStringTranslationType());
            }
            getModelObject().getTranslation().setKey(object);
        }

        @Override
        public void detach() {
        }
    });
    keyValue.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    keyValue.setOutputMarkupId(true);
    fullDataContainer.add(keyValue);
    IModel<String> langChoiceModel = Model.of();
    WebMarkupContainer languageEditorContainer = new WebMarkupContainer(ID_LANGUAGE_EDITOR);
    languageEditorContainer.setOutputMarkupId(true);
    languageEditorContainer.add(new VisibleBehaviour(() -> CollectionUtils.isNotEmpty(getLanguageChoicesModel().getObject())));
    fullDataContainer.add(languageEditorContainer);
    final DropDownChoicePanel<String> languageChoicePanel = new DropDownChoicePanel<>(ID_LANGUAGES_LIST, langChoiceModel, getLanguageChoicesModel(), true);
    languageChoicePanel.setOutputMarkupId(true);
    languageChoicePanel.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
    languageChoicePanel.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
            removeLanguageValue(currentlySelectedLang.toString());
            clearSelectedLanguageValue();
            currentlySelectedLang.append(getLanguagesChoicePanel().getBaseFormComponent().getModelObject());
        }
    });
    languageEditorContainer.add(languageChoicePanel);
    final TextPanel<String> newLanguageValue = new TextPanel<>(ID_VALUE_TO_ADD, Model.of());
    newLanguageValue.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            updateLanguageValue(languageChoicePanel.getBaseFormComponent().getModelObject(), newLanguageValue.getBaseFormComponent().getValue());
        }
    });
    languageChoicePanel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            updateLanguageValue(languageChoicePanel.getBaseFormComponent().getModelObject(), newLanguageValue.getBaseFormComponent().getValue());
        }
    });
    newLanguageValue.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
            updateLanguageValue(languageChoicePanel.getBaseFormComponent().getModelObject(), newLanguageValue.getBaseFormComponent().getValue());
        }
    });
    newLanguageValue.setOutputMarkupId(true);
    languageEditorContainer.add(newLanguageValue);
    AjaxLink<Void> addLanguageButton = new AjaxLink<Void>(ID_ADD_LANGUAGE_VALUE_BUTTON) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            updateLanguageValue(languageChoicePanel.getModel().getObject(), newLanguageValue.getBaseFormComponent().getModelObject());
            languageChoicePanel.getModel().setObject(null);
            newLanguageValue.getBaseFormComponent().getModel().setObject(null);
            clearSelectedLanguageValue();
            target.add(PolyStringEditorPanel.this);
        }
    };
    addLanguageButton.add(AttributeAppender.append("style", "cursor: pointer;"));
    addLanguageButton.setOutputMarkupId(true);
    languageEditorContainer.add(addLanguageButton);
    ListView<String> languagesContainer = new ListView<String>(ID_LANGUAGES_REPEATER, getLanguagesListModel()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<String> listItem) {
            TextPanel<String> languageName = new TextPanel<>(ID_LANGUAGE_NAME, listItem.getModel());
            languageName.add(new EnableBehaviour(() -> false));
            languageName.setOutputMarkupId(true);
            listItem.add(languageName);
            TextPanel<String> translation = new TextPanel<>(ID_TRANSLATION, Model.of(getLanguageValueByKey(listItem.getModelObject())));
            translation.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour() {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    updateLanguageValue(languageName.getBaseFormComponent().getValue(), translation.getBaseFormComponent().getValue());
                }
            });
            translation.setOutputMarkupId(true);
            translation.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior() {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
                    updateLanguageValue(languageName.getBaseFormComponent().getValue(), translation.getBaseFormComponent().getValue());
                }
            });
            listItem.add(translation);
            AjaxLink<Void> removeButton = new AjaxLink<Void>(ID_REMOVE_LANGUAGE_BUTTON) {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    removeLanguageValue(listItem.getModelObject());
                    target.add(PolyStringEditorPanel.this);
                }
            };
            removeButton.setOutputMarkupId(true);
            listItem.add(removeButton);
        }
    };
    languagesContainer.setOutputMarkupId(true);
    fullDataContainer.add(languagesContainer);
    AjaxButton showHideLanguagesButton = new AjaxButton(ID_SHOW_HIDE_LANGUAGES_ORIG) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            showHideLanguagesPerformed(target);
        }
    };
    showHideLanguagesButton.setOutputMarkupId(true);
    // showHideLanguagesButton.add(AttributeAppender.append("style", "cursor: pointer;"));
    origValueWithButton.add(showHideLanguagesButton);
}
Also used : DropDownChoicePanel(com.evolveum.midpoint.web.component.input.DropDownChoicePanel) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) Label(org.apache.wicket.markup.html.basic.Label) EmptyOnBlurAjaxFormUpdatingBehaviour(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour) AutoCompleteTextPanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel) TextPanel(com.evolveum.midpoint.web.component.input.TextPanel) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) EmptyOnChangeAjaxFormUpdatingBehavior(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) ListView(org.apache.wicket.markup.html.list.ListView) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) PolyStringTranslationType(com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType) EnableBehaviour(com.evolveum.midpoint.web.component.util.EnableBehaviour) IModel(org.apache.wicket.model.IModel) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ListItem(org.apache.wicket.markup.html.list.ListItem)

Example 9 with EnableBehaviour

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

the class MultiValueObjectChoosePanel method initMultiValuesListPanel.

private void initMultiValuesListPanel() {
    ListView<R> multiValuesPanel = new ListView<R>(ID_MULTI_SHADOW_REF_VALUE, MultiValueObjectChoosePanel.this.getModel()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<R> item) {
            ValueChoosePanel<R> valueChoosePanel = new ValueChoosePanel<R>(ID_REFERENCE_VALUE_INPUT, item.getModel()) {

                private static final long serialVersionUID = 1L;

                @Override
                protected ObjectFilter createCustomFilter() {
                    return MultiValueObjectChoosePanel.this.createCustomFilter();
                }

                @Override
                public List<QName> getSupportedTypes() {
                    return MultiValueObjectChoosePanel.this.getSupportedTypes();
                }

                @Override
                protected <O extends ObjectType> void choosePerformedHook(AjaxRequestTarget target, O object) {
                    chooseObjectPerformed(target, object);
                }
            };
            valueChoosePanel.setOutputMarkupId(true);
            item.add(valueChoosePanel);
            WebMarkupContainer buttonsContainer = new WebMarkupContainer(ID_BUTTONS_CONTAINER);
            buttonsContainer.setOutputMarkupId(true);
            item.add(buttonsContainer);
            AjaxButton addButton = new AjaxButton(ID_ADD_BUTTON) {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    emptyObjectPanelDisplay = true;
                    target.add(MultiValueObjectChoosePanel.this);
                // MultiValueObjectChoosePanel.this.getModelObject().add(null);
                }
            };
            addButton.setOutputMarkupId(true);
            addButton.add(new EnableBehaviour(() -> item.getModelObject() != null));
            buttonsContainer.add(addButton);
            AjaxLink<Void> removeButton = new AjaxLink<Void>(ID_REMOVE_BUTTON) {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    MultiValueObjectChoosePanel.this.getModelObject().remove(item.getModelObject());
                    target.add(MultiValueObjectChoosePanel.this);
                }
            };
            removeButton.setOutputMarkupId(true);
            removeButton.add(new EnableBehaviour(() -> item.getModelObject() != null));
            buttonsContainer.add(removeButton);
        }
    };
    multiValuesPanel.add(new VisibleBehaviour(() -> !isEmptyModel()));
    multiValuesPanel.setOutputMarkupId(true);
    add(multiValuesPanel);
}
Also used : VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) QName(javax.xml.namespace.QName) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) ListView(org.apache.wicket.markup.html.list.ListView) ListItem(org.apache.wicket.markup.html.list.ListItem) ValueChoosePanel(com.evolveum.midpoint.web.component.form.ValueChoosePanel) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) EnableBehaviour(com.evolveum.midpoint.web.component.util.EnableBehaviour)

Example 10 with EnableBehaviour

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

the class IndirectSearchItem method createSpecialSearchPanel.

@Override
public SearchSpecialItemPanel createSpecialSearchPanel(String id) {
    SearchSpecialItemPanel panel = new SearchSpecialItemPanel(id, new PropertyModel(searchBoxConfiguration, SearchBoxConfigurationHelper.F_INDIRECT_ITEM + "." + IndirectSearchItemConfigurationType.F_INDIRECT.getLocalPart())) {

        @Override
        protected WebMarkupContainer initSearchItemField(String id) {
            List<Boolean> choices = new ArrayList<>();
            choices.add(Boolean.TRUE);
            choices.add(Boolean.FALSE);
            DropDownChoicePanel inputPanel = new DropDownChoicePanel(id, getModelValue(), Model.ofList(choices), new ChoiceRenderer<Boolean>() {

                private static final long serialVersionUID = 1L;

                @Override
                public Object getDisplayValue(Boolean val) {
                    if (val) {
                        return getPageBase().createStringResource("Boolean.TRUE").getString();
                    }
                    return getPageBase().createStringResource("Boolean.FALSE").getString();
                }
            }, false);
            inputPanel.getBaseFormComponent().add(WebComponentUtil.getSubmitOnEnterKeyDownBehavior("searchSimple"));
            inputPanel.getBaseFormComponent().add(AttributeAppender.append("style", "width: 68" + "px; max-width: 400px !important;"));
            inputPanel.getBaseFormComponent().add(new EnableBehaviour(() -> searchBoxConfiguration != null && !searchBoxConfiguration.isSearchScope(SearchBoxScopeType.SUBTREE)));
            inputPanel.setOutputMarkupId(true);
            return inputPanel;
        }

        @Override
        protected IModel<String> createLabelModel() {
            return Model.of(WebComponentUtil.getTranslatedPolyString(getIndirectConfig().getDisplay().getLabel()));
        }

        @Override
        protected IModel<String> createHelpModel() {
            return Model.of(WebComponentUtil.getTranslatedPolyString(getIndirectConfig().getDisplay().getHelp()));
        }
    };
    panel.add(new VisibleBehaviour(this::isPanelVisible));
    return panel;
}
Also used : DropDownChoicePanel(com.evolveum.midpoint.web.component.input.DropDownChoicePanel) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) PropertyModel(org.apache.wicket.model.PropertyModel) ArrayList(java.util.ArrayList) SearchSpecialItemPanel(com.evolveum.midpoint.web.component.search.SearchSpecialItemPanel) EnableBehaviour(com.evolveum.midpoint.web.component.util.EnableBehaviour)

Aggregations

EnableBehaviour (com.evolveum.midpoint.web.component.util.EnableBehaviour)17 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)13 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)10 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)9 ArrayList (java.util.ArrayList)7 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)6 Label (org.apache.wicket.markup.html.basic.Label)6 QName (javax.xml.namespace.QName)5 DropDownChoicePanel (com.evolveum.midpoint.web.component.input.DropDownChoicePanel)4 EmptyOnBlurAjaxFormUpdatingBehaviour (com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour)4 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)3 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)3 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)3 Form (org.apache.wicket.markup.html.form.Form)3 IModel (org.apache.wicket.model.IModel)3 CountablePanelTab (com.evolveum.midpoint.gui.api.component.tabs.CountablePanelTab)2 ReadOnlyModel (com.evolveum.midpoint.gui.api.model.ReadOnlyModel)2 CompositedIconBuilder (com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder)2 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)2 Task (com.evolveum.midpoint.task.api.Task)2