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);
}
Aggregations