Search in sources :

Example 16 with EnableBehaviour

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

the class ExpressionTypeSelectPopup method initLayout.

private void initLayout() {
    setOutputMarkupId(true);
    IModel<Boolean> shadowSelectModel = Model.of(false);
    IModel<Boolean> assocTargetSearchSelectModel = Model.of(false);
    AjaxCheckBox shadowRefCheckbox = new AjaxCheckBox(ID_SHADOW_REF_CHECKBOX, shadowSelectModel) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(ExpressionTypeSelectPopup.this);
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.setEventPropagation(AjaxRequestAttributes.EventPropagation.BUBBLE);
        }
    };
    shadowRefCheckbox.setOutputMarkupId(true);
    shadowRefCheckbox.add(new EnableBehaviour(() -> !assocTargetSearchSelectModel.getObject()));
    add(shadowRefCheckbox);
    AjaxCheckBox associationTargetSearchCheckbox = new AjaxCheckBox(ID_ASSOCIATION_TARGET_SEARCH_CHECKBOX, assocTargetSearchSelectModel) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(ExpressionTypeSelectPopup.this);
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.setEventPropagation(AjaxRequestAttributes.EventPropagation.BUBBLE);
        }
    };
    associationTargetSearchCheckbox.setOutputMarkupId(true);
    associationTargetSearchCheckbox.add(new EnableBehaviour(() -> !shadowSelectModel.getObject()));
    add(associationTargetSearchCheckbox);
    AjaxButton select = new AjaxButton(ID_ADD_BUTTON, new StringResourceModel("ExpressionTypeSelectPopup.addButton")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            ExpressionValueTypes expressionType = getShadowRefCheckbox().getModelObject() ? ExpressionValueTypes.SHADOW_REF_EXPRESSION : (getAssociationTargetSearchCheckbox().getModelObject() ? ExpressionValueTypes.ASSOCIATION_TARGET_SEARCH_EXPRESSION : null);
            addExpressionPerformed(target, expressionType);
        }
    };
    add(select);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) AjaxCheckBox(org.apache.wicket.ajax.markup.html.form.AjaxCheckBox) StringResourceModel(org.apache.wicket.model.StringResourceModel) EnableBehaviour(com.evolveum.midpoint.web.component.util.EnableBehaviour)

Example 17 with EnableBehaviour

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

the class RelationSearchItem method createSpecialSearchPanel.

@Override
public SearchSpecialItemPanel createSpecialSearchPanel(String id) {
    return new SearchSpecialItemPanel(id, new PropertyModel<>(searchBoxConfiguration, SearchBoxConfigurationHelper.F_RELATION_ITEM)) {

        @Override
        protected WebMarkupContainer initSearchItemField(String id) {
            ReadOnlyModel<List<QName>> availableRelations = new ReadOnlyModel<>(() -> {
                List<QName> choices = new ArrayList();
                IModel<RelationSearchItemConfigurationType> relationItem = getModelValue();
                List<QName> relations = relationItem.getObject().getSupportedRelations();
                if (relations != null && relations.size() > 1) {
                    choices.add(PrismConstants.Q_ANY);
                }
                choices.addAll(relations);
                return choices;
            });
            DropDownChoicePanel inputPanel = new DropDownChoicePanel(id, new PropertyModel(getModelValue(), RelationSearchItemConfigurationType.F_DEFAULT_VALUE.getLocalPart()), availableRelations, new QNameIChoiceRenderer() {

                private static final long serialVersionUID = 1L;

                @Override
                public Object getDisplayValue(QName relation) {
                    RelationDefinitionType relationDef = WebComponentUtil.getRelationDefinition(relation);
                    if (relationDef != null) {
                        DisplayType display = relationDef.getDisplay();
                        if (display != null) {
                            PolyStringType label = display.getLabel();
                            if (PolyStringUtils.isNotEmpty(label)) {
                                return WebComponentUtil.getTranslatedPolyString(label);
                            }
                        }
                    }
                    if (QNameUtil.match(PrismConstants.Q_ANY, relation)) {
                        return new ResourceModel("RelationTypes.ANY", relation.getLocalPart()).getObject();
                    }
                    return super.getDisplayValue(relation);
                }
            }, false);
            inputPanel.getBaseFormComponent().add(WebComponentUtil.getSubmitOnEnterKeyDownBehavior("searchSimple"));
            inputPanel.getBaseFormComponent().add(AttributeAppender.append("style", "width: 100px; max-width: 400px !important;"));
            inputPanel.getBaseFormComponent().add(new EnableBehaviour(() -> availableRelations.getObject().size() > 1));
            inputPanel.setOutputMarkupId(true);
            return inputPanel;
        }

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

        @Override
        protected IModel<String> createHelpModel() {
            return Model.of(WebComponentUtil.getTranslatedPolyString(getReltaionConfig().getDisplay().getHelp()));
        }
    };
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) DropDownChoicePanel(com.evolveum.midpoint.web.component.input.DropDownChoicePanel) QNameIChoiceRenderer(com.evolveum.midpoint.gui.impl.component.input.QNameIChoiceRenderer) DisplayType(com.evolveum.midpoint.xml.ns._public.common.common_3.DisplayType) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) PropertyModel(org.apache.wicket.model.PropertyModel) RelationDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.RelationDefinitionType) ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) ResourceModel(org.apache.wicket.model.ResourceModel) ArrayList(java.util.ArrayList) List(java.util.List) RelationSearchItemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.RelationSearchItemConfigurationType) 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