Search in sources :

Example 1 with ExpressionModel

use of com.evolveum.midpoint.gui.impl.factory.panel.ExpressionModel in project midpoint by Evolveum.

the class SwitchablePropertyValuePanel method initLayout.

private void initLayout() {
    setOutputMarkupId(true);
    WebMarkupContainer valueContainer = new WebMarkupContainer(ID_PROPERTY_VALUE_PANEL);
    valueContainer.setOutputMarkupId(true);
    add(valueContainer);
    Component valueField = getValueField(ID_VALUE_FIELD);
    valueField.add(new VisibleBehaviour(() -> !isExpressionMode));
    valueContainer.add(valueField);
    ExpressionWrapper expression = getExpressionWrapper();
    ExpressionType expressionType = null;
    if (expression != null) {
        Object expressionValue = expression.getExpression();
        if (expressionValue instanceof ExpressionType) {
            expressionType = (ExpressionType) expressionValue;
        }
    }
    AceEditorPanel expressionField = new AceEditorPanel(ID_EXPRESSION_FIELD, null, new ExpressionModel(Model.of(expressionType), getPageBase()), 200);
    expressionField.getEditor().add(new EmptyOnBlurAjaxFormUpdatingBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            getModelObject().getValue().setExpression(new ExpressionWrapper(getPropertyItemDefinition().getItemName(), ((ExpressionModel) expressionField.getModel()).getBaseModel().getObject()));
        }
    });
    expressionField.getEditor().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
    expressionField.add(new VisibleBehaviour(() -> isExpressionMode));
    valueContainer.add(expressionField);
    AjaxButton switchButton = new AjaxButton(ID_SWITCH_BUTTON) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (isExpressionMode) {
                tempExpressionWrapper = SwitchablePropertyValuePanel.this.getModelObject().getValue().getExpression();
                SwitchablePropertyValuePanel.this.getModelObject().getValue().setExpression(null);
                SwitchablePropertyValuePanel.this.getModelObject().getValue().setValue(tempValue);
            // if (isReferenceFilterValue()) {
            // SwitchablePropertyValuePanel.this.getModelObject().getValue().setValue(new ObjectReferenceType());
            // }
            } else {
                tempValue = SwitchablePropertyValuePanel.this.getModelObject().getValue().getValue();
                SwitchablePropertyValuePanel.this.getModelObject().getValue().setExpression(tempExpressionWrapper);
                SwitchablePropertyValuePanel.this.getModelObject().getValue().setValue(null);
            }
            isExpressionMode = !isExpressionMode;
            target.add(SwitchablePropertyValuePanel.this);
        }
    };
    switchButton.setOutputMarkupId(true);
    switchButton.add(new VisibleBehaviour(() -> {
        ItemDefinition propertyDef = getPropertyItemDefinition();
        return propertyDef == null || propertyDef.getTypeClass() != null && !boolean.class.equals(propertyDef.getTypeClass()) && !Boolean.class.isAssignableFrom(propertyDef.getTypeClass());
    }));
    switchButton.add(AttributeAppender.append("title", new LoadableModel<String>() {

        @Override
        protected String load() {
            // todo
            return "";
        }
    }));
    valueContainer.add(switchButton);
}
Also used : VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) AceEditorPanel(com.evolveum.midpoint.web.page.admin.reports.component.AceEditorPanel) ExpressionModel(com.evolveum.midpoint.gui.impl.factory.panel.ExpressionModel) EmptyOnBlurAjaxFormUpdatingBehaviour(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) EmptyOnChangeAjaxFormUpdatingBehavior(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) Component(org.apache.wicket.Component) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)

Aggregations

LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)1 ExpressionModel (com.evolveum.midpoint.gui.impl.factory.panel.ExpressionModel)1 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)1 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)1 EmptyOnBlurAjaxFormUpdatingBehaviour (com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour)1 EmptyOnChangeAjaxFormUpdatingBehavior (com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior)1 AceEditorPanel (com.evolveum.midpoint.web.page.admin.reports.component.AceEditorPanel)1 ExpressionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)1 Component (org.apache.wicket.Component)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)1