Search in sources :

Example 21 with AjaxSubmitButton

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

the class MappingEditorDialog method initLayout.

public void initLayout(WebMarkupContainer content) {
    Form form = new MidpointForm(ID_MAIN_FORM);
    form.setOutputMarkupId(true);
    content.add(form);
    TextFormGroup name = new TextFormGroup(ID_NAME, new PropertyModel<>(model, MappingTypeDto.F_MAPPING + ".name"), createStringResource("MappingEditorDialog.label.name"), ID_LABEL_SIZE, ID_INPUT_SIZE, false);
    name.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    form.add(name);
    TextAreaFormGroup description = new TextAreaFormGroup(ID_DESCRIPTION, new PropertyModel<>(model, MappingTypeDto.F_MAPPING + ".description"), createStringResource("MappingEditorDialog.label.description"), ID_LABEL_SIZE, ID_INPUT_SIZE, false);
    description.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    form.add(description);
    CheckFormGroup authoritative = new CheckFormGroup(ID_AUTHORITATIVE, new PropertyModel<>(model, MappingTypeDto.F_MAPPING + ".authoritative"), createStringResource("MappingEditorDialog.label.authoritative"), "SchemaHandlingStep.mapping.tooltip.authoritative", ID_LABEL_SIZE, ID_INPUT_SIZE);
    authoritative.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    form.add(authoritative);
    CheckFormGroup exclusive = new CheckFormGroup(ID_EXCLUSIVE, new PropertyModel<>(model, MappingTypeDto.F_MAPPING + ".exclusive"), createStringResource("MappingEditorDialog.label.exclusive"), "SchemaHandlingStep.mapping.tooltip.exclusive", ID_LABEL_SIZE, ID_INPUT_SIZE);
    exclusive.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    form.add(exclusive);
    DropDownFormGroup strength = new DropDownFormGroup<>(ID_STRENGTH, new PropertyModel<>(model, MappingTypeDto.F_MAPPING + ".strength"), WebComponentUtil.createReadonlyModelFromEnum(MappingStrengthType.class), new EnumChoiceRenderer<>(this), createStringResource("MappingEditorDialog.label.strength"), "SchemaHandlingStep.mapping.tooltip.strength", ID_LABEL_SIZE, ID_INPUT_SIZE, false);
    strength.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    form.add(strength);
    MultiValueDropDownPanel channel = new MultiValueDropDownPanel<String>(ID_CHANNEL, new PropertyModel<>(model, MappingTypeDto.F_MAPPING + ".channel"), true, readOnlyModel) {

        @Override
        protected String createNewEmptyItem() {
            return "";
        }

        @Override
        protected IModel<List<String>> createChoiceList() {
            return new IModel<List<String>>() {

                @Override
                public List<String> getObject() {
                    return WebComponentUtil.getChannelList();
                }
            };
        }

        @Override
        protected IChoiceRenderer<String> createRenderer() {
            return CHANNEL_RENDERER;
        }
    };
    form.add(channel);
    MultiValueDropDownPanel exceptChannel = new MultiValueDropDownPanel<String>(ID_EXCEPT_CHANNEL, new PropertyModel<>(model, MappingTypeDto.F_MAPPING + ".exceptChannel"), true, readOnlyModel) {

        @Override
        protected String createNewEmptyItem() {
            return "";
        }

        @Override
        protected IModel<List<String>> createChoiceList() {
            return new IModel<List<String>>() {

                @Override
                public List<String> getObject() {
                    return WebComponentUtil.getChannelList();
                }
            };
        }

        @Override
        protected IChoiceRenderer<String> createRenderer() {
            return CHANNEL_RENDERER;
        }
    };
    form.add(exceptChannel);
    // TODO - create some nice ItemPathType editor in near future
    MultiValueTextPanel source = new MultiValueTextPanel<>(ID_SOURCE, new PropertyModel<List<String>>(model, MappingTypeDto.F_SOURCE), readOnlyModel, true);
    form.add(source);
    // TODO - create some nice ItemPathType editor in near future
    TextFormGroup target = new TextFormGroup(ID_TARGET, new PropertyModel<>(model, MappingTypeDto.F_TARGET), createStringResource("MappingEditorDialog.label.target"), "SchemaHandlingStep.mapping.tooltip.target", ID_LABEL_SIZE, ID_INPUT_SIZE, false, isTargetRequired);
    target.setOutputMarkupId(true);
    target.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    form.add(target);
    DropDownFormGroup<ExpressionUtil.ExpressionEvaluatorType> expressionType = new DropDownFormGroup<ExpressionUtil.ExpressionEvaluatorType>(ID_EXPRESSION_TYPE, new PropertyModel<>(model, MappingTypeDto.F_EXPRESSION_TYPE), WebComponentUtil.createReadonlyModelFromEnum(ExpressionUtil.ExpressionEvaluatorType.class), new EnumChoiceRenderer<>(this), createStringResource("MappingEditorDialog.label.expressionType"), "SchemaHandlingStep.mapping.tooltip.expressionType", ID_LABEL_SIZE, ID_INPUT_SIZE, false) {

        @Override
        protected DropDownChoice createDropDown(String id, IModel<List<ExpressionUtil.ExpressionEvaluatorType>> choices, IChoiceRenderer<ExpressionUtil.ExpressionEvaluatorType> renderer, boolean required) {
            return new DropDownChoice<>(id, getModel(), choices, renderer);
        }
    };
    expressionType.getInput().add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            model.getObject().updateExpression();
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_EXPRESSION));
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_EXPRESSION_LANG));
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_EXPRESSION_POLICY_REF));
        }
    });
    expressionType.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    form.add(expressionType);
    DropDownFormGroup expressionLanguage = new DropDownFormGroup<>(ID_EXPRESSION_LANG, new PropertyModel<>(model, MappingTypeDto.F_EXPRESSION_LANG), WebComponentUtil.createReadonlyModelFromEnum(ExpressionUtil.Language.class), new EnumChoiceRenderer<>(this), createStringResource("MappingEditorDialog.label.language"), "SchemaHandlingStep.mapping.tooltip.expressionLanguage", ID_LABEL_SIZE, ID_INPUT_SIZE, false);
    expressionLanguage.setOutputMarkupId(true);
    expressionLanguage.setOutputMarkupPlaceholderTag(true);
    expressionLanguage.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return ExpressionUtil.ExpressionEvaluatorType.SCRIPT.equals(model.getObject().getExpressionType());
        }

        @Override
        public boolean isEnabled() {
            return !readOnlyModel.getObject();
        }
    });
    form.add(expressionLanguage);
    expressionLanguage.getInput().add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            model.getObject().updateExpressionLanguage();
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_EXPRESSION));
        }
    });
    DropDownFormGroup<ObjectReferenceType> expressionGeneratePolicy = new DropDownFormGroup<ObjectReferenceType>(ID_EXPRESSION_POLICY_REF, new PropertyModel<>(model, MappingTypeDto.F_EXPRESSION_POLICY_REF), new IModel<List<ObjectReferenceType>>() {

        @Override
        public List<ObjectReferenceType> getObject() {
            return WebModelServiceUtils.createObjectReferenceList(ValuePolicyType.class, getPageBase(), policyMap);
        }
    }, new ObjectReferenceChoiceRenderer(policyMap), createStringResource("MappingEditorDialog.label.passPolicyRef"), "SchemaHandlingStep.mapping.tooltip.expressionValuePolicyRef", ID_LABEL_SIZE, ID_INPUT_SIZE, false) {

        @Override
        protected DropDownChoice createDropDown(String id, IModel<List<ObjectReferenceType>> choices, IChoiceRenderer<ObjectReferenceType> renderer, boolean required) {
            return new DropDownChoice<>(id, getModel(), choices, renderer);
        }
    };
    expressionGeneratePolicy.setOutputMarkupId(true);
    expressionGeneratePolicy.setOutputMarkupPlaceholderTag(true);
    expressionGeneratePolicy.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return ExpressionUtil.ExpressionEvaluatorType.GENERATE.equals(model.getObject().getExpressionType());
        }

        @Override
        public boolean isEnabled() {
            return !readOnlyModel.getObject();
        }
    });
    expressionGeneratePolicy.getInput().add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            model.getObject().updateExpressionGeneratePolicy();
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_EXPRESSION));
        }
    });
    form.add(expressionGeneratePolicy);
    AceEditorFormGroup expression = new AceEditorFormGroup(ID_EXPRESSION, new PropertyModel<>(model, MappingTypeDto.F_EXPRESSION), createStringResource("MappingEditorDialog.label.expression"), "SchemaHandlingStep.mapping.tooltip.expression", ID_LABEL_SIZE, ID_INPUT_SIZE, false, CODE_ROW_COUNT);
    expression.setOutputMarkupId(true);
    expression.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    form.add(expression);
    DropDownFormGroup<ExpressionUtil.ExpressionEvaluatorType> conditionType = new DropDownFormGroup<ExpressionUtil.ExpressionEvaluatorType>(ID_CONDITION_TYPE, new PropertyModel<>(model, MappingTypeDto.F_CONDITION_TYPE), WebComponentUtil.createReadonlyModelFromEnum(ExpressionUtil.ExpressionEvaluatorType.class), new EnumChoiceRenderer<>(this), createStringResource("MappingEditorDialog.label.conditionType"), "SchemaHandlingStep.mapping.tooltip.conditionType", ID_LABEL_SIZE, ID_INPUT_SIZE, false) {

        @Override
        protected DropDownChoice createDropDown(String id, IModel<List<ExpressionUtil.ExpressionEvaluatorType>> choices, IChoiceRenderer<ExpressionUtil.ExpressionEvaluatorType> renderer, boolean required) {
            return new DropDownChoice<>(id, getModel(), choices, renderer);
        }
    };
    conditionType.getInput().add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            model.getObject().updateCondition();
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_CONDITION));
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_CONDITION_LANG));
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_CONDITION_POLICY_REF));
        }
    });
    form.add(conditionType);
    conditionType.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    DropDownFormGroup conditionLanguage = new DropDownFormGroup<>(ID_CONDITION_LANG, new PropertyModel<>(model, MappingTypeDto.F_CONDITION_LANG), WebComponentUtil.createReadonlyModelFromEnum(ExpressionUtil.Language.class), new EnumChoiceRenderer<>(this), createStringResource("MappingEditorDialog.label.language"), "SchemaHandlingStep.mapping.tooltip.conditionLanguage", ID_LABEL_SIZE, ID_INPUT_SIZE, false);
    conditionLanguage.setOutputMarkupId(true);
    conditionLanguage.setOutputMarkupPlaceholderTag(true);
    conditionLanguage.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return ExpressionUtil.ExpressionEvaluatorType.SCRIPT.equals(model.getObject().getConditionType());
        }

        @Override
        public boolean isEnabled() {
            return !readOnlyModel.getObject();
        }
    });
    conditionLanguage.getInput().add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            model.getObject().updateConditionLanguage();
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_CONDITION));
        }
    });
    form.add(conditionLanguage);
    DropDownFormGroup<ObjectReferenceType> conditionGeneratePolicy = new DropDownFormGroup<ObjectReferenceType>(ID_CONDITION_POLICY_REF, new PropertyModel<>(model, MappingTypeDto.F_CONDITION_POLICY_REF), new IModel<List<ObjectReferenceType>>() {

        @Override
        public List<ObjectReferenceType> getObject() {
            return WebModelServiceUtils.createObjectReferenceList(ValuePolicyType.class, getPageBase(), policyMap);
        }
    }, new ObjectReferenceChoiceRenderer(policyMap), createStringResource("MappingEditorDialog.label.passPolicyRef"), "SchemaHandlingStep.mapping.tooltip.conditionValuePolicyRef", ID_LABEL_SIZE, ID_INPUT_SIZE, false) {

        @Override
        protected DropDownChoice createDropDown(String id, IModel<List<ObjectReferenceType>> choices, IChoiceRenderer<ObjectReferenceType> renderer, boolean required) {
            return new DropDownChoice<>(id, getModel(), choices, renderer);
        }
    };
    conditionGeneratePolicy.setOutputMarkupId(true);
    conditionGeneratePolicy.setOutputMarkupPlaceholderTag(true);
    conditionGeneratePolicy.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return ExpressionUtil.ExpressionEvaluatorType.GENERATE.equals(model.getObject().getConditionType());
        }

        @Override
        public boolean isEnabled() {
            return !readOnlyModel.getObject();
        }
    });
    conditionGeneratePolicy.getInput().add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            model.getObject().updateConditionGeneratePolicy();
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_CONDITION));
        }
    });
    form.add(conditionGeneratePolicy);
    AceEditorFormGroup condition = new AceEditorFormGroup(ID_CONDITION, new PropertyModel<>(model, MappingTypeDto.F_CONDITION), createStringResource("MappingEditorDialog.label.condition"), "SchemaHandlingStep.mapping.tooltip.condition", ID_LABEL_SIZE, ID_INPUT_SIZE, false, CODE_ROW_COUNT);
    condition.setOutputMarkupId(true);
    condition.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    form.add(condition);
    Label channelTooltip = new Label(ID_T_CHANNEL);
    channelTooltip.add(new InfoTooltipBehavior());
    form.add(channelTooltip);
    Label exceptChannelTooltip = new Label(ID_T_EXCEPT_CHANNEL);
    exceptChannelTooltip.add(new InfoTooltipBehavior());
    form.add(exceptChannelTooltip);
    Label sourceTooltip = new Label(ID_T_SOURCE);
    sourceTooltip.add(new InfoTooltipBehavior());
    form.add(sourceTooltip);
    AjaxButton cancel = new AjaxButton(ID_BUTTON_CANCEL, createStringResource("MappingEditorDialog.button.cancel")) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            cancelPerformed(target);
        }
    };
    form.add(cancel);
    AjaxSubmitButton save = new AjaxSubmitButton(ID_BUTTON_SAVE, createStringResource("MappingEditorDialog.button.apply")) {

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

        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(getPageBase().getFeedbackPanel(), getContent());
        }
    };
    save.add(WebComponentUtil.visibleIfFalse(readOnlyModel));
    form.add(save);
    setCloseButtonCallback(new CloseButtonCallback() {

        @Override
        public boolean onCloseButtonClicked(AjaxRequestTarget target) {
            cancelPerformed(target);
            return true;
        }
    });
}
Also used : IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) ObjectReferenceChoiceRenderer(com.evolveum.midpoint.web.component.input.ObjectReferenceChoiceRenderer) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) Form(org.apache.wicket.markup.html.form.Form) Label(org.apache.wicket.markup.html.basic.Label) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) MultiValueDropDownPanel(com.evolveum.midpoint.web.component.form.multivalue.MultiValueDropDownPanel) ArrayList(java.util.ArrayList) List(java.util.List) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) MultiValueTextPanel(com.evolveum.midpoint.web.component.form.multivalue.MultiValueTextPanel) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) IModel(org.apache.wicket.model.IModel) MappingStrengthType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingStrengthType) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) InfoTooltipBehavior(com.evolveum.midpoint.web.util.InfoTooltipBehavior) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) ExpressionUtil(com.evolveum.midpoint.web.util.ExpressionUtil)

Example 22 with AjaxSubmitButton

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

the class PageForgotPassword method initButtons.

private void initButtons(Form<?> form) {
    AjaxSubmitButton submit = new AjaxSubmitButton(ID_SUBMIT, createStringResource("PageForgetPassword.resetPassword")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            processResetPassword(target, form);
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(getFeedbackPanel());
        }
    };
    submit.setOutputMarkupId(true);
    form.add(submit);
    form.setDefaultButton(submit);
    AjaxButton backButton = new AjaxButton(ID_BACK, createStringResource("PageForgetPassword.back")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            setResponsePage(PageLogin.class);
        }
    };
    backButton.setOutputMarkupId(true);
    form.add(backButton);
    add(form);
    MultiLineLabel label = new MultiLineLabel(ID_PASSWORD_RESET_SUBMITED, createStringResource("PageForgotPassword.form.submited.message"));
    add(label);
    label.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return submited;
        }

        @Override
        public boolean isEnabled() {
            return submited;
        }
    });
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) MultiLineLabel(org.apache.wicket.markup.html.basic.MultiLineLabel)

Example 23 with AjaxSubmitButton

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

the class PageEvaluateMapping method initLayout.

private void initLayout() {
    Form mainForm = new MidpointForm(ID_MAIN_FORM);
    add(mainForm);
    AceEditor editorMapping = new AceEditor(ID_EDITOR_MAPPING, new PropertyModel<>(model, ExecuteMappingDto.F_MAPPING));
    editorMapping.setHeight(400);
    editorMapping.setResizeToMaxHeight(false);
    mainForm.add(editorMapping);
    AceEditor editorRequest = new AceEditor(ID_EDITOR_REQUEST, new PropertyModel<>(model, ExecuteMappingDto.F_REQUEST));
    editorRequest.setHeight(430);
    editorRequest.setResizeToMaxHeight(false);
    mainForm.add(editorRequest);
    AjaxSubmitButton evaluateMapping = new AjaxSubmitButton(ID_EXECUTE, createStringResource("PageEvaluateMapping.button.evaluateMapping")) {

        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(getFeedbackPanel());
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            executeMappingPerformed(target);
        }
    };
    mainForm.add(evaluateMapping);
    final DropDownChoice<String> sampleChoice = new DropDownChoice<>(ID_MAPPING_SAMPLE, Model.of(""), (IModel<List<String>>) () -> SAMPLES, new StringResourceChoiceRenderer("PageEvaluateMapping.sample"));
    sampleChoice.setNullValid(true);
    sampleChoice.add(new OnChangeAjaxBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            String sampleName = sampleChoice.getModelObject();
            if (StringUtils.isEmpty(sampleName)) {
                return;
            }
            model.getObject().setMapping(readResource(SAMPLES_DIR + "/" + sampleName + ".map.xml.data"));
            model.getObject().setRequest(readResource(SAMPLES_DIR + "/" + sampleName + ".req.xml.data"));
            model.getObject().setResultText("");
            target.add(PageEvaluateMapping.this);
        }

        private String readResource(String name) {
            try (InputStream is = PageEvaluateMapping.class.getResourceAsStream(name)) {
                if (is != null) {
                    return IOUtils.toString(is, StandardCharsets.UTF_8);
                } else {
                    LOGGER.warn("Resource {} containing sample couldn't be found", name);
                }
            } catch (IOException e) {
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't read sample from resource {}", e, name);
            }
            return null;
        }
    });
    mainForm.add(sampleChoice);
    AceEditor resultText = new AceEditor(ID_RESULT_TEXT, new PropertyModel<>(model, ExecuteMappingDto.F_RESULT_TEXT));
    resultText.setReadonly(true);
    resultText.setHeight(300);
    resultText.setResizeToMaxHeight(false);
    resultText.setMode(null);
    mainForm.add(resultText);
}
Also used : AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) StringResourceChoiceRenderer(com.evolveum.midpoint.web.util.StringResourceChoiceRenderer) Form(org.apache.wicket.markup.html.form.Form) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) InputStream(java.io.InputStream) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) AceEditor(com.evolveum.midpoint.web.component.AceEditor) IOException(java.io.IOException) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) List(java.util.List)

Example 24 with AjaxSubmitButton

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

the class PageRepositoryQuery method initLayout.

private void initLayout() {
    Form mainForm = new MidpointForm(ID_MAIN_FORM);
    add(mainForm);
    Label repositoryQueryLabel = new Label(ID_REPOSITORY_QUERY_LABEL, createStringResource("PageRepositoryQuery.midPoint", WebComponentUtil.getMidpointCustomSystemName(PageRepositoryQuery.this, "MidPoint")));
    repositoryQueryLabel.setOutputMarkupId(true);
    mainForm.add(repositoryQueryLabel);
    DropDownChoicePanel<QName> objectTypeChoice = new DropDownChoicePanel<>(ID_OBJECT_TYPE, new PropertyModel<>(model, RepoQueryDto.F_OBJECT_TYPE), new ListModel<>(WebComponentUtil.createObjectTypeList()), new QNameChoiceRenderer());
    objectTypeChoice.setOutputMarkupId(true);
    objectTypeChoice.getBaseFormComponent().setNullValid(true);
    objectTypeChoice.getBaseFormComponent().add(new OnChangeAjaxBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(get(ID_MAIN_FORM).get(ID_MIDPOINT_QUERY_BUTTON_BAR));
        }
    });
    mainForm.add(objectTypeChoice);
    CheckFormGroup distinctCheck = new CheckFormGroup(ID_DISTINCT, new PropertyModel<>(model, RepoQueryDto.F_DISTINCT), createStringResource("PageRepositoryQuery.checkBox.distinct"), "col-xs-3", "col-xs-1");
    mainForm.add(distinctCheck);
    AceEditor editorMidPoint = new AceEditor(ID_EDITOR_MIDPOINT, new PropertyModel<>(model, RepoQueryDto.F_MIDPOINT_QUERY));
    editorMidPoint.setHeight(400);
    editorMidPoint.setResizeToMaxHeight(false);
    mainForm.add(editorMidPoint);
    Label queryLabel = new Label(ID_QUERY_LABEL, createQueryLabelModel());
    mainForm.add(queryLabel);
    AceEditor editorHibernate = new AceEditor(ID_QUERY_EDITOR, new PropertyModel<>(model, RepoQueryDto.F_HIBERNATE_QUERY));
    editorHibernate.setHeight(300);
    editorHibernate.setResizeToMaxHeight(false);
    editorHibernate.setReadonly(!isAdmin);
    editorHibernate.setMode(null);
    mainForm.add(editorHibernate);
    AceEditor hibernateParameters = new AceEditor(ID_PARAMETERS, new PropertyModel<>(model, RepoQueryDto.F_HIBERNATE_PARAMETERS));
    hibernateParameters.setReadonly(true);
    hibernateParameters.setHeight(100);
    hibernateParameters.setResizeToMaxHeight(false);
    hibernateParameters.setMode(null);
    mainForm.add(hibernateParameters);
    Label hibernateParametersNote = new Label(ID_HIBERNATE_PARAMETERS_NOTE, createStringResource("PageRepositoryQuery.hibernateParametersNote", WebComponentUtil.getMidpointCustomSystemName(PageRepositoryQuery.this, "midPoint")));
    hibernateParametersNote.setVisible(isAdmin && !isNativeRepo());
    mainForm.add(hibernateParametersNote);
    Label queryVsFilterNote = new Label(ID_QUERY_VS_FILTER_NOTE, createStringResource("PageRepositoryQuery.queryVsFilterNote", WebComponentUtil.getMidpointCustomSystemName(PageRepositoryQuery.this, "midPoint")));
    queryVsFilterNote.setOutputMarkupId(true);
    mainForm.add(queryVsFilterNote);
    WebMarkupContainer midPointQueryButtonBar = new WebMarkupContainer(ID_MIDPOINT_QUERY_BUTTON_BAR);
    midPointQueryButtonBar.setOutputMarkupId(true);
    mainForm.add(midPointQueryButtonBar);
    DataLanguagePanel<QueryType> dataLanguagePanel = new DataLanguagePanel<>(ID_VIEW_BUTTON_PANEL, dataLanguage, QueryType.class, PageRepositoryQuery.this) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onLanguageSwitched(AjaxRequestTarget target, int updatedIndex, String updatedLanguage, String objectString) {
            model.getObject().setMidPointQuery(objectString);
            dataLanguage = updatedLanguage;
            target.add(mainForm);
        }

        @Override
        protected String getObjectStringRepresentation() {
            return model.getObject().getMidPointQuery();
        }
    };
    dataLanguagePanel.setOutputMarkupId(true);
    mainForm.add(dataLanguagePanel);
    AjaxSubmitButton executeMidPoint = new AjaxSubmitButton(ID_EXECUTE_MIDPOINT, createStringResource("PageRepositoryQuery.button.translateAndExecute")) {

        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(getFeedbackPanel());
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            queryPerformed(Action.EXECUTE_MIDPOINT, target);
        }
    };
    midPointQueryButtonBar.add(executeMidPoint);
    AjaxSubmitButton compileMidPoint = new AjaxSubmitButton(ID_COMPILE_MIDPOINT, createCompileMidpointLabelModel()) {

        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(getFeedbackPanel());
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            queryPerformed(Action.TRANSLATE_ONLY, target);
        }
    };
    midPointQueryButtonBar.add(compileMidPoint);
    AjaxSubmitButton useInObjectList = new AjaxSubmitButton(ID_USE_IN_OBJECT_LIST, createStringResource("PageRepositoryQuery.button.useInObjectList")) {

        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(getFeedbackPanel());
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            useInObjectListPerformed(target);
        }
    };
    useInObjectList.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return USE_IN_OBJECT_LIST_AVAILABLE_FOR.contains(model.getObject().getObjectType());
        }
    });
    midPointQueryButtonBar.add(useInObjectList);
    final DropDownChoicePanel<String> sampleChoice = new DropDownChoicePanel<>(ID_QUERY_SAMPLE, Model.of(""), Model.ofList(SAMPLES), new StringResourceChoiceRenderer("PageRepositoryQuery.sample"), true);
    sampleChoice.getBaseFormComponent().setNullValid(true);
    sampleChoice.getBaseFormComponent().add(new OnChangeAjaxBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            String sampleName = sampleChoice.getModel().getObject();
            if (StringUtils.isEmpty(sampleName)) {
                return;
            }
            String resourceName = SAMPLES_DIR + "/" + sampleName + ".xml.data";
            InputStream is = PageRepositoryQuery.class.getResourceAsStream(resourceName);
            if (is != null) {
                try {
                    String localTypeName = StringUtils.substringBefore(sampleName, "_");
                    model.getObject().setObjectType(new QName(SchemaConstants.NS_C, localTypeName));
                    String xml = IOUtils.toString(is, StandardCharsets.UTF_8);
                    String serialization;
                    if (PrismContext.LANG_XML.equals(dataLanguage)) {
                        serialization = xml;
                    } else {
                        PrismContext prismContext = getPrismContext();
                        try {
                            QueryType parsed = prismContext.parserFor(xml).xml().parseRealValue(QueryType.class);
                            serialization = prismContext.serializerFor(dataLanguage).serializeRealValue(parsed);
                        } catch (Throwable t) {
                            serialization = "Couldn't serialize sample: " + t.getMessage();
                        }
                    }
                    model.getObject().setMidPointQuery(serialization);
                    model.getObject().setHibernateQuery("");
                    model.getObject().setHibernateParameters("");
                    model.getObject().setQueryResultObject(null);
                    model.getObject().resetQueryResultText();
                    target.add(PageRepositoryQuery.this);
                } catch (IOException e) {
                    LoggingUtils.logUnexpectedException(LOGGER, "Couldn't read sample from resource {}", e, resourceName);
                }
            } else {
                LOGGER.warn("Resource {} containing sample couldn't be found", resourceName);
            }
        }
    });
    mainForm.add(sampleChoice);
    AjaxSubmitButton executeHibernate = new AjaxSubmitButton(ID_EXECUTE_HIBERNATE, createStringResource("PageRepositoryQuery.button.execute")) {

        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(getFeedbackPanel());
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            queryPerformed(Action.EXECUTE_HIBERNATE, target);
        }
    };
    executeHibernate.setVisible(isAdmin && !isNativeRepo());
    mainForm.add(executeHibernate);
    Label resultLabel = new Label(ID_RESULT_LABEL, new IModel<String>() {

        @Override
        public String getObject() {
            if (model.getObject().getQueryResultText() == null) {
                return "";
            }
            Object queryResult = model.getObject().getQueryResultObject();
            if (queryResult instanceof List) {
                return getString("PageRepositoryQuery.resultObjects", ((List) queryResult).size());
            } else if (queryResult instanceof Throwable) {
                return getString("PageRepositoryQuery.resultException", queryResult.getClass().getName());
            } else {
                // including null
                return getString("PageRepositoryQuery.result");
            }
        }
    });
    mainForm.add(resultLabel);
    WebMarkupContainer incompleteResultsNote = new WebMarkupContainer(ID_INCOMPLETE_RESULTS_NOTE);
    incompleteResultsNote.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return !isAdmin && model.getObject().getQueryResultText() != null;
        }
    });
    mainForm.add(incompleteResultsNote);
    AceEditor resultText = new AceEditor(ID_RESULT_TEXT, new PropertyModel<>(model, RepoQueryDto.F_QUERY_RESULT_TEXT));
    resultText.setReadonly(true);
    resultText.setHeight(300);
    resultText.setResizeToMaxHeight(false);
    resultText.setMode(null);
    resultText.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return model.getObject().getQueryResultText() != null;
        }
    });
    mainForm.add(resultText);
}
Also used : DropDownChoicePanel(com.evolveum.midpoint.web.component.input.DropDownChoicePanel) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) Form(org.apache.wicket.markup.html.form.Form) PrismContext(com.evolveum.midpoint.prism.PrismContext) Label(org.apache.wicket.markup.html.basic.Label) AceEditor(com.evolveum.midpoint.web.component.AceEditor) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) QNameChoiceRenderer(com.evolveum.midpoint.web.component.input.QNameChoiceRenderer) AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) StringResourceChoiceRenderer(com.evolveum.midpoint.web.util.StringResourceChoiceRenderer) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) DataLanguagePanel(com.evolveum.midpoint.web.component.input.DataLanguagePanel) IOException(java.io.IOException) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior) CheckFormGroup(com.evolveum.midpoint.web.component.form.CheckFormGroup) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType)

Example 25 with AjaxSubmitButton

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

the class PageBulkAction method initLayout.

private void initLayout() {
    Form mainForm = new MidpointForm(ID_MAIN_FORM);
    add(mainForm);
    CheckBox async = new CheckBox(ID_ASYNC, new PropertyModel<>(model, BulkActionDto.F_ASYNC));
    mainForm.add(async);
    AceEditor editor = new AceEditor(ID_EDITOR, new PropertyModel<>(model, BulkActionDto.F_SCRIPT));
    mainForm.add(editor);
    AjaxSubmitButton start = new AjaxSubmitButton(ID_START, createStringResource("PageBulkAction.button.start")) {

        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(getFeedbackPanel());
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            startPerformed(target);
        }
    };
    mainForm.add(start);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) Form(org.apache.wicket.markup.html.form.Form) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) CheckBox(org.apache.wicket.markup.html.form.CheckBox) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) AceEditor(com.evolveum.midpoint.web.component.AceEditor)

Aggregations

AjaxSubmitButton (com.evolveum.midpoint.web.component.AjaxSubmitButton)67 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)65 Form (org.apache.wicket.markup.html.form.Form)27 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)23 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)23 MidpointForm (com.evolveum.midpoint.web.component.form.MidpointForm)20 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)12 ArrayList (java.util.ArrayList)9 List (java.util.List)8 Label (org.apache.wicket.markup.html.basic.Label)8 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)7 ListItem (org.apache.wicket.markup.html.list.ListItem)5 CheckFormGroup (com.evolveum.midpoint.web.component.form.CheckFormGroup)4 AceEditor (com.evolveum.midpoint.web.component.AceEditor)3 Form (com.evolveum.midpoint.web.component.form.Form)3 QNameChoiceRenderer (com.evolveum.midpoint.web.component.input.QNameChoiceRenderer)3 TextPanel (com.evolveum.midpoint.web.component.input.TextPanel)3 FeedbackAlerts (com.evolveum.midpoint.web.component.message.FeedbackAlerts)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3