Search in sources :

Example 1 with DataLanguagePanel

use of com.evolveum.midpoint.web.component.input.DataLanguagePanel 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 2 with DataLanguagePanel

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

the class PageImportObject method initLayout.

private void initLayout() {
    Form<?> mainForm = new MidpointForm<>(ID_MAIN_FORM);
    mainForm.setMultiPart(true);
    add(mainForm);
    ImportOptionsPanel importOptions = new ImportOptionsPanel(ID_IMPORT_OPTIONS, optionsModel, fullProcessingModel);
    mainForm.add(importOptions);
    final WebMarkupContainer input = new WebMarkupContainer(ID_INPUT);
    input.setOutputMarkupId(true);
    mainForm.add(input);
    WebMarkupContainer buttonBar = new WebMarkupContainer(ID_BUTTON_BAR);
    buttonBar.setOutputMarkupId(true);
    mainForm.add(buttonBar);
    final IModel<Integer> groupModel = new Model<>(INPUT_FILE);
    RadioGroup<Integer> 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<Integer> fileRadio = new Radio<>(ID_FILE_RADIO, new Model<>(INPUT_FILE), importRadioGroup);
    importRadioGroup.add(fileRadio);
    Radio<Integer> 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);
    dataLanguage = determineDataLanguage();
    DataLanguagePanel<List> languagePanel = new DataLanguagePanel<List>(ID_LANGUAGE_PANEL, dataLanguage, List.class, this) {

        @Override
        protected void onLanguageSwitched(AjaxRequestTarget target, int index, String updatedLanguage, String objectString) {
            dataLanguage = updatedLanguage;
            xmlEditorModel.setObject(objectString);
            addOrReplaceEditor(inputAce);
            target.add(mainForm);
        }

        @Override
        protected String getObjectStringRepresentation() {
            return xmlEditorModel.getObject();
        }
    };
    inputAce.add(languagePanel);
    addOrReplaceEditor(inputAce);
    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 : RadioGroup(org.apache.wicket.markup.html.form.RadioGroup) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) Radio(org.apache.wicket.markup.html.form.Radio) DataLanguagePanel(com.evolveum.midpoint.web.component.input.DataLanguagePanel) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ImportOptionsPanel(com.evolveum.midpoint.web.page.admin.configuration.component.ImportOptionsPanel) IModel(org.apache.wicket.model.IModel) Model(org.apache.wicket.model.Model) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) List(java.util.List) AjaxFormChoiceComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior)

Aggregations

MidpointForm (com.evolveum.midpoint.web.component.form.MidpointForm)2 DataLanguagePanel (com.evolveum.midpoint.web.component.input.DataLanguagePanel)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)2 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)1 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 AceEditor (com.evolveum.midpoint.web.component.AceEditor)1 AjaxSubmitButton (com.evolveum.midpoint.web.component.AjaxSubmitButton)1 CheckFormGroup (com.evolveum.midpoint.web.component.form.CheckFormGroup)1 DropDownChoicePanel (com.evolveum.midpoint.web.component.input.DropDownChoicePanel)1 QNameChoiceRenderer (com.evolveum.midpoint.web.component.input.QNameChoiceRenderer)1 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)1 ImportOptionsPanel (com.evolveum.midpoint.web.page.admin.configuration.component.ImportOptionsPanel)1 StringResourceChoiceRenderer (com.evolveum.midpoint.web.util.StringResourceChoiceRenderer)1 QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 List (java.util.List)1 QName (javax.xml.namespace.QName)1 AjaxFormChoiceComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior)1