Search in sources :

Example 1 with MultiStateHorizontalButton

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

the class PageDebugView method initViewButton.

private void initViewButton(Form mainForm) {
    List<String> propertyKeysList = Arrays.asList("PageDebugView.xmlViewButton", "PageDebugView.xmlJsonButton", "PageDebugView.xmlYamlButton");
    int selectedIndex = 0;
    if (PrismContext.LANG_JSON.equals(dataLanguage)) {
        selectedIndex = 1;
    } else if (PrismContext.LANG_YAML.equals(dataLanguage)) {
        selectedIndex = 2;
    }
    MultiStateHorizontalButton viewButtonPanel = new MultiStateHorizontalButton(ID_VIEW_BUTTON_PANEL, selectedIndex, propertyKeysList, PageDebugView.this) {

        @Override
        protected void onStateChanged(int index, AjaxRequestTarget target) {
            OperationResult result = new OperationResult(OPERATION_VALIDATE_OBJECT);
            Holder<PrismObject<ObjectType>> objectHolder = new Holder<>(null);
            try {
                validateObject(result, objectHolder);
                if (result.isAcceptable()) {
                    if (index == 1) {
                        dataLanguage = PrismContext.LANG_JSON;
                    } else if (index == 2) {
                        dataLanguage = PrismContext.LANG_YAML;
                    } else {
                        dataLanguage = PrismContext.LANG_XML;
                    }
                    PrismObject<ObjectType> updatedObject = objectHolder.getValue();
                    PrismContext context = getMidpointApplication().getPrismContext();
                    String objectStr = context.serializerFor(dataLanguage).serialize(updatedObject);
                    objectViewDto.setXml(objectStr);
                    setSelectedIndex(index);
                    addOrReplaceEditor();
                    target.add(mainForm);
                    target.add(getFeedbackPanel());
                } else {
                    showResult(result);
                    target.add(getFeedbackPanel());
                }
            } catch (Exception ex) {
                result.recordFatalError("Couldn't change the language.", ex);
                showResult(result);
                target.add(getFeedbackPanel());
            }
        }
    };
    viewButtonPanel.setOutputMarkupId(true);
    mainForm.add(viewButtonPanel);
}
Also used : MultiStateHorizontalButton(com.evolveum.midpoint.web.component.input.MultiStateHorizontalButton) PrismContext(com.evolveum.midpoint.prism.PrismContext) Holder(com.evolveum.midpoint.util.Holder) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RestartResponseException(org.apache.wicket.RestartResponseException) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Aggregations

PrismContext (com.evolveum.midpoint.prism.PrismContext)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 Holder (com.evolveum.midpoint.util.Holder)1 MultiStateHorizontalButton (com.evolveum.midpoint.web.component.input.MultiStateHorizontalButton)1 RestartResponseException (org.apache.wicket.RestartResponseException)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1