Search in sources :

Example 11 with AceEditor

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

the class PageRepositoryQuery method initLayout.

private void initLayout() {
    Form mainForm = new Form(ID_MAIN_FORM);
    add(mainForm);
    List<QName> objectTypeList = WebComponentUtil.createObjectTypeList();
    Collections.sort(objectTypeList, new Comparator<QName>() {

        @Override
        public int compare(QName o1, QName o2) {
            return String.CASE_INSENSITIVE_ORDER.compare(o1.getLocalPart(), o2.getLocalPart());
        }
    });
    DropDownChoice<QName> objectTypeChoice = new DropDownChoice<>(ID_OBJECT_TYPE, new PropertyModel<QName>(model, RepoQueryDto.F_OBJECT_TYPE), new ListModel<>(objectTypeList), new QNameChoiceRenderer());
    objectTypeChoice.setOutputMarkupId(true);
    objectTypeChoice.setNullValid(true);
    objectTypeChoice.add(new OnChangeAjaxBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(get(ID_MAIN_FORM).get(ID_MIDPOINT_QUERY_BUTTON_BAR));
        }
    });
    mainForm.add(objectTypeChoice);
    AceEditor editorMidPoint = new AceEditor(ID_EDITOR_MIDPOINT, new PropertyModel<String>(model, RepoQueryDto.F_MIDPOINT_QUERY));
    editorMidPoint.setHeight(400);
    editorMidPoint.setResizeToMaxHeight(false);
    mainForm.add(editorMidPoint);
    AceEditor editorHibernate = new AceEditor(ID_EDITOR_HIBERNATE, new PropertyModel<String>(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_HIBERNATE_PARAMETERS, new PropertyModel<String>(model, RepoQueryDto.F_HIBERNATE_PARAMETERS));
    hibernateParameters.setReadonly(true);
    hibernateParameters.setHeight(100);
    hibernateParameters.setResizeToMaxHeight(false);
    hibernateParameters.setMode(null);
    mainForm.add(hibernateParameters);
    WebMarkupContainer hibernateParametersNote = new WebMarkupContainer(ID_HIBERNATE_PARAMETERS_NOTE);
    hibernateParametersNote.setVisible(isAdmin);
    mainForm.add(hibernateParametersNote);
    WebMarkupContainer midPointQueryButtonBar = new WebMarkupContainer(ID_MIDPOINT_QUERY_BUTTON_BAR);
    midPointQueryButtonBar.setOutputMarkupId(true);
    mainForm.add(midPointQueryButtonBar);
    AjaxSubmitButton executeMidPoint = new AjaxSubmitButton(ID_EXECUTE_MIDPOINT, createStringResource("PageRepositoryQuery.button.translateAndExecute")) {

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(getFeedbackPanel());
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            queryPerformed(Action.EXECUTE_MIDPOINT, target);
        }
    };
    midPointQueryButtonBar.add(executeMidPoint);
    AjaxSubmitButton compileMidPoint = new AjaxSubmitButton(ID_COMPILE_MIDPOINT, createStringResource("PageRepositoryQuery.button.translate")) {

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(getFeedbackPanel());
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            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, Form<?> form) {
            target.add(getFeedbackPanel());
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            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 DropDownChoice<String> sampleChoice = new DropDownChoice<>(ID_QUERY_SAMPLE, Model.of(""), new AbstractReadOnlyModel<List<String>>() {

        @Override
        public List<String> getObject() {
            return SAMPLES;
        }
    }, new StringResourceChoiceRenderer("PageRepositoryQuery.sample"));
    sampleChoice.setNullValid(true);
    sampleChoice.add(new OnChangeAjaxBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            String sampleName = sampleChoice.getModelObject();
            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));
                    model.getObject().setMidPointQuery(IOUtils.toString(is, "UTF-8"));
                    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, Form<?> form) {
            target.add(getFeedbackPanel());
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            queryPerformed(Action.EXECUTE_HIBERNATE, target);
        }
    };
    executeHibernate.setVisible(isAdmin);
    mainForm.add(executeHibernate);
    Label resultLabel = new Label(ID_RESULT_LABEL, new AbstractReadOnlyModel<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<String>(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 : Form(org.apache.wicket.markup.html.form.Form) 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) 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)

Example 12 with AceEditor

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

the class ExpressionEditorPanel method initLayout.

protected void initLayout(PageResourceWizard parentPage) {
    parentPage.addEditingEnabledBehavior(this);
    setOutputMarkupId(true);
    loadDtoModel();
    Label descriptionLabel = new Label(ID_LABEL_DESCRIPTION, createStringResource(getDescriptionLabelKey()));
    add(descriptionLabel);
    TextArea description = new TextArea<>(ID_DESCRIPTION, new PropertyModel<String>(dtoModel, ExpressionTypeDto.F_DESCRIPTION));
    description.setOutputMarkupId(true);
    //parentPage.addEditingEnabledBehavior(description);
    add(description);
    Label typeLabel = new Label(ID_LABEL_TYPE, createStringResource(getTypeLabelKey()));
    add(typeLabel);
    DropDownChoice type = new DropDownChoice<>(ID_TYPE, new PropertyModel<ExpressionUtil.ExpressionEvaluatorType>(dtoModel, ExpressionTypeDto.F_TYPE), WebComponentUtil.createReadonlyModelFromEnum(ExpressionUtil.ExpressionEvaluatorType.class), new EnumChoiceRenderer<ExpressionUtil.ExpressionEvaluatorType>(this));
    //parentPage.addEditingEnabledBehavior(type);
    type.add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            dtoModel.getObject().updateExpressionType();
            //target.add(get(ID_LANGUAGE_CONTAINER), get(ID_POLICY_CONTAINER), get(ID_EXPRESSION));
            // because of ACE editor
            target.add(ExpressionEditorPanel.this);
        }
    });
    type.setOutputMarkupId(true);
    type.setOutputMarkupPlaceholderTag(true);
    type.setNullValid(true);
    add(type);
    WebMarkupContainer languageContainer = new WebMarkupContainer(ID_LANGUAGE_CONTAINER);
    languageContainer.setOutputMarkupId(true);
    languageContainer.setOutputMarkupPlaceholderTag(true);
    languageContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return ExpressionUtil.ExpressionEvaluatorType.SCRIPT.equals(dtoModel.getObject().getType());
        }
    });
    //parentPage.addEditingEnabledBehavior(languageContainer);
    add(languageContainer);
    DropDownChoice language = new DropDownChoice<>(ID_LANGUAGE, new PropertyModel<ExpressionUtil.Language>(dtoModel, ExpressionTypeDto.F_LANGUAGE), WebComponentUtil.createReadonlyModelFromEnum(ExpressionUtil.Language.class), new EnumChoiceRenderer<ExpressionUtil.Language>(this));
    //parentPage.addEditingEnabledBehavior(language);
    language.add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            dtoModel.getObject().updateExpressionLanguage();
            //target.add(get(ID_LANGUAGE_CONTAINER), get(ID_POLICY_CONTAINER), get(ID_EXPRESSION));
            // because of ACE editor
            target.add(ExpressionEditorPanel.this);
        }
    });
    language.setNullValid(false);
    languageContainer.add(language);
    WebMarkupContainer policyContainer = new WebMarkupContainer(ID_POLICY_CONTAINER);
    policyContainer.setOutputMarkupId(true);
    policyContainer.setOutputMarkupPlaceholderTag(true);
    policyContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return ExpressionUtil.ExpressionEvaluatorType.GENERATE.equals(dtoModel.getObject().getType());
        }
    });
    add(policyContainer);
    DropDownChoice policyRef = new DropDownChoice<>(ID_POLICY_REF, new PropertyModel<ObjectReferenceType>(dtoModel, ExpressionTypeDto.F_POLICY_REF), new AbstractReadOnlyModel<List<ObjectReferenceType>>() {

        @Override
        public List<ObjectReferenceType> getObject() {
            return WebModelServiceUtils.createObjectReferenceList(ValuePolicyType.class, getPageBase(), policyMap);
        }
    }, new ObjectReferenceChoiceRenderer(policyMap));
    //parentPage.addEditingEnabledBehavior(policyRef);
    policyRef.add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            dtoModel.getObject().updateExpressionValuePolicyRef();
            target.add(get(ID_LANGUAGE_CONTAINER), get(ID_POLICY_CONTAINER), get(ID_EXPRESSION));
        }
    });
    policyRef.setNullValid(true);
    policyContainer.add(policyRef);
    Label expressionLabel = new Label(ID_LABEL_EXPRESSION, createStringResource(getExpressionLabelKey()));
    add(expressionLabel);
    AceEditor expression = new AceEditor(ID_EXPRESSION, new PropertyModel<String>(dtoModel, ExpressionTypeDto.F_EXPRESSION));
    expression.setOutputMarkupId(true);
    //parentPage.addEditingEnabledBehavior(expression);
    add(expression);
    AjaxSubmitLink update = new AjaxSubmitLink(ID_BUTTON_UPDATE) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            updateExpressionPerformed(target);
        }
    };
    Label updateLabel = new Label(ID_LABEL_UPDATE, createStringResource(getUpdateLabelKey()));
    updateLabel.setRenderBodyOnly(true);
    update.add(updateLabel);
    parentPage.addEditingVisibleBehavior(update);
    add(update);
    add(WebComponentUtil.createHelp(ID_T_TYPE));
    languageContainer.add(WebComponentUtil.createHelp(ID_T_LANGUAGE));
    policyContainer.add(WebComponentUtil.createHelp(ID_T_POLICY));
    add(WebComponentUtil.createHelp(ID_T_EXPRESSION));
}
Also used : ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) TextArea(org.apache.wicket.markup.html.form.TextArea) Form(org.apache.wicket.markup.html.form.Form) Label(org.apache.wicket.markup.html.basic.Label) AceEditor(com.evolveum.midpoint.web.component.AceEditor) AjaxSubmitLink(org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) List(java.util.List) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice)

Example 13 with AceEditor

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

the class SearchFilterPanel method initLayout.

protected void initLayout(NonEmptyModel<Boolean> readOnlyModel) {
    TextArea<String> description = new TextArea<>(ID_DESCRIPTION, new PropertyModel<String>(getModel(), SearchFilterType.F_DESCRIPTION.getLocalPart()));
    description.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    add(description);
    AceEditor clause = new AceEditor(ID_FILTER_CLAUSE, clauseStringModel);
    clause.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    add(clause);
    AjaxSubmitLink update = new AjaxSubmitLink(ID_BUTTON_UPDATE) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            updateClausePerformed(target);
        }
    };
    update.add(WebComponentUtil.visibleIfFalse(readOnlyModel));
    add(update);
    Label clauseTooltip = new Label(ID_T_CLAUSE);
    clauseTooltip.add(new InfoTooltipBehavior());
    add(clauseTooltip);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) InfoTooltipBehavior(com.evolveum.midpoint.web.util.InfoTooltipBehavior) TextArea(org.apache.wicket.markup.html.form.TextArea) Form(org.apache.wicket.markup.html.form.Form) Label(org.apache.wicket.markup.html.basic.Label) AceEditor(com.evolveum.midpoint.web.component.AceEditor) AjaxSubmitLink(org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink)

Example 14 with AceEditor

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

the class PageNewReport method initLayout.

private void initLayout() {
    Form mainForm = new Form(ID_MAIN_FORM);
    add(mainForm);
    final WebMarkupContainer input = new WebMarkupContainer(ID_INPUT);
    input.setOutputMarkupId(true);
    mainForm.add(input);
    final WebMarkupContainer buttonBar = new WebMarkupContainer(ID_BUTTON_BAR);
    buttonBar.setOutputMarkupId(true);
    mainForm.add(buttonBar);
    final IModel<Integer> groupModel = new Model<Integer>(INPUT_FILE);
    RadioGroup importRadioGroup = new RadioGroup(ID_IMPORT_RADIO_GROUP, groupModel);
    importRadioGroup.add(new AjaxFormChoiceComponentUpdatingBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(input);
            target.add(buttonBar);
        }
    });
    mainForm.add(importRadioGroup);
    Radio fileRadio = new Radio(ID_FILE_RADIO, new Model(INPUT_FILE), importRadioGroup);
    importRadioGroup.add(fileRadio);
    Radio xmlRadio = new Radio(ID_XML_RADIO, new Model(INPUT_XML), importRadioGroup);
    importRadioGroup.add(xmlRadio);
    WebMarkupContainer inputAce = new WebMarkupContainer(ID_INPUT_ACE);
    addVisibileForInputType(inputAce, INPUT_XML, groupModel);
    input.add(inputAce);
    AceEditor aceEditor = new AceEditor(ID_ACE_EDITOR, xmlEditorModel);
    aceEditor.setOutputMarkupId(true);
    inputAce.add(aceEditor);
    WebMarkupContainer inputFileLabel = new WebMarkupContainer(ID_INPUT_FILE_LABEL);
    addVisibileForInputType(inputFileLabel, INPUT_FILE, groupModel);
    input.add(inputFileLabel);
    WebMarkupContainer inputFile = new WebMarkupContainer(ID_INPUT_FILE);
    addVisibileForInputType(inputFile, INPUT_FILE, groupModel);
    input.add(inputFile);
    FileUploadField fileInput = new FileUploadField(ID_FILE_INPUT);
    inputFile.add(fileInput);
    initButtons(buttonBar, groupModel);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) RadioGroup(org.apache.wicket.markup.html.form.RadioGroup) Form(org.apache.wicket.markup.html.form.Form) IModel(org.apache.wicket.model.IModel) Model(org.apache.wicket.model.Model) Radio(org.apache.wicket.markup.html.form.Radio) AceEditor(com.evolveum.midpoint.web.component.AceEditor) AjaxFormChoiceComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField)

Example 15 with AceEditor

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

the class PageResourceEdit method initLayout.

private void initLayout() {
    Form mainForm = new Form(ID_MAIN_FORM);
    add(mainForm);
    final IModel<Boolean> editable = new LoadableModel<Boolean>(false) {

        @Override
        protected Boolean load() {
            return !isEditing();
        }
    };
    mainForm.add(new AjaxCheckBox(ID_EDIT, editable) {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            editPerformed(target, editable.getObject());
        }
    });
    AceEditor editor = new AceEditor(ID_ACE_EDITOR, new PropertyModel<String>(model, ObjectViewDto.F_XML));
    editor.setReadonly(new LoadableModel<Boolean>(false) {

        @Override
        protected Boolean load() {
            return isEditing();
        }
    });
    mainForm.add(editor);
    initButtons(mainForm);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Form(org.apache.wicket.markup.html.form.Form) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) AjaxCheckBox(org.apache.wicket.ajax.markup.html.form.AjaxCheckBox) AceEditor(com.evolveum.midpoint.web.component.AceEditor)

Aggregations

AceEditor (com.evolveum.midpoint.web.component.AceEditor)16 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)9 Form (org.apache.wicket.markup.html.form.Form)8 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)5 Label (org.apache.wicket.markup.html.basic.Label)5 AjaxSubmitButton (com.evolveum.midpoint.web.component.AjaxSubmitButton)3 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)3 DropDownChoice (org.apache.wicket.markup.html.form.DropDownChoice)3 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)2 InfoTooltipBehavior (com.evolveum.midpoint.web.util.InfoTooltipBehavior)2 StringResourceChoiceRenderer (com.evolveum.midpoint.web.util.StringResourceChoiceRenderer)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 List (java.util.List)2 AjaxFormChoiceComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior)2 AjaxFormComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior)2 OnChangeAjaxBehavior (org.apache.wicket.ajax.form.OnChangeAjaxBehavior)2 AjaxSubmitLink (org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink)2 Radio (org.apache.wicket.markup.html.form.Radio)2 RadioGroup (org.apache.wicket.markup.html.form.RadioGroup)2