use of com.evolveum.midpoint.web.component.input.QNameChoiceRenderer in project midpoint by Evolveum.
the class SynchronizationStep method initObjectSyncEditor.
private void initObjectSyncEditor(WebMarkupContainer editor) {
Label editorLabel = new Label(ID_EDITOR_LABEL, new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
if (!isAnySelected()) {
// shouldn't occur
return null;
}
String name = syncDtoModel.getObject().getSelected().getName() != null ? syncDtoModel.getObject().getSelected().getName() : "";
return getString("SynchronizationStep.label.editSyncObject", name);
}
});
editorLabel.setOutputMarkupId(true);
editor.add(editorLabel);
TextField editorName = new TextField<>(ID_EDITOR_NAME, new PropertyModel<String>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".name"));
editorName.add(new UpdateNamesBehaviour());
parentPage.addEditingEnabledBehavior(editorName);
editor.add(editorName);
TextArea editorDescription = new TextArea<>(ID_EDITOR_DESCRIPTION, new PropertyModel<String>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".description"));
parentPage.addEditingEnabledBehavior(editorDescription);
editor.add(editorDescription);
DropDownChoice editorKind = new DropDownChoice<>(ID_EDITOR_KIND, new PropertyModel<ShadowKindType>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".kind"), WebComponentUtil.createReadonlyModelFromEnum(ShadowKindType.class), new EnumChoiceRenderer<ShadowKindType>());
editorKind.setNullValid(true);
editorKind.add(new UpdateNamesBehaviour());
parentPage.addEditingEnabledBehavior(editorKind);
editor.add(editorKind);
TextField editorIntent = new TextField<>(ID_EDITOR_INTENT, new PropertyModel<String>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".intent"));
editorIntent.add(new UpdateNamesBehaviour());
parentPage.addEditingEnabledBehavior(editorIntent);
editor.add(editorIntent);
MultiValueAutoCompleteTextPanel<QName> editorObjectClass = new MultiValueAutoCompleteTextPanel<QName>(ID_EDITOR_OBJECT_CLASS, new PropertyModel<List<QName>>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".objectClass"), true, parentPage.getReadOnlyModel()) {
@Override
protected IModel<String> createTextModel(final IModel<QName> model) {
return new PropertyModel<>(model, "localPart");
}
@Override
protected QName createNewEmptyItem() {
return new QName("");
}
@Override
protected boolean buttonsDisabled() {
return !isAnySelected();
}
@Override
protected List<QName> createObjectList() {
return syncDtoModel.getObject().getObjectClassList();
}
@Override
protected String createAutoCompleteObjectLabel(QName object) {
return object.getLocalPart();
}
@Override
protected IValidator<String> createAutoCompleteValidator() {
return createObjectClassValidator(new AbstractReadOnlyModel<List<QName>>() {
@Override
public List<QName> getObject() {
return syncDtoModel.getObject().getObjectClassList();
}
});
}
};
parentPage.addEditingEnabledBehavior(editorObjectClass);
editor.add(editorObjectClass);
// TODO: switch to ObjectTypeSelectPanel
DropDownChoice editorFocus = new DropDownChoice<>(ID_EDITOR_FOCUS, new PropertyModel<QName>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".focusType"), new AbstractReadOnlyModel<List<QName>>() {
@Override
public List<QName> getObject() {
return WebComponentUtil.createFocusTypeList();
}
}, new QNameChoiceRenderer());
editorFocus.setNullValid(true);
editorFocus.add(new UpdateNamesBehaviour());
parentPage.addEditingEnabledBehavior(editorFocus);
editor.add(editorFocus);
CheckBox editorEnabled = new CheckBox(ID_EDITOR_ENABLED, new PropertyModel<Boolean>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".enabled"));
parentPage.addEditingEnabledBehavior(editorEnabled);
editor.add(editorEnabled);
AjaxSubmitLink editorCondition = new AjaxSubmitLink(ID_EDITOR_BUTTON_CONDITION) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
conditionEditPerformed(target);
}
};
addDisableClassModifier(editorCondition);
editor.add(editorCondition);
AjaxSubmitLink editorConfirmation = new AjaxSubmitLink(ID_EDITOR_BUTTON_CONFIRMATION) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
confirmationEditPerformed(target);
}
};
addDisableClassModifier(editorConfirmation);
editor.add(editorConfirmation);
DropDownChoice editorObjectTemplate = new DropDownChoice<>(ID_EDITOR_OBJECT_TEMPLATE, new PropertyModel<ObjectReferenceType>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".objectTemplateRef"), new AbstractReadOnlyModel<List<ObjectReferenceType>>() {
@Override
public List<ObjectReferenceType> getObject() {
return WebModelServiceUtils.createObjectReferenceList(ObjectTemplateType.class, getPageBase(), syncDtoModel.getObject().getObjectTemplateMap());
}
}, new ObjectReferenceChoiceRenderer(syncDtoModel.getObject().getObjectTemplateMap()));
editorObjectTemplate.setNullValid(true);
parentPage.addEditingEnabledBehavior(editorObjectTemplate);
editor.add(editorObjectTemplate);
CheckBox editorReconcile = new CheckBox(ID_EDITOR_RECONCILE, new PropertyModel<Boolean>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".reconcile"));
parentPage.addEditingEnabledBehavior(editorReconcile);
editor.add(editorReconcile);
TriStateComboPanel opportunistic = new TriStateComboPanel(ID_EDITOR_OPPORTUNISTIC, new PropertyModel<Boolean>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".opportunistic"));
parentPage.addEditingEnabledBehavior(opportunistic);
editor.add(opportunistic);
MultiValueTextEditPanel editorCorrelation = new MultiValueTextEditPanel<ConditionalSearchFilterType>(ID_EDITOR_EDITOR_CORRELATION, new PropertyModel<List<ConditionalSearchFilterType>>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".correlation"), new PropertyModel<ConditionalSearchFilterType>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED_CORRELATION), false, true, parentPage.getReadOnlyModel()) {
@Override
protected IModel<String> createTextModel(final IModel<ConditionalSearchFilterType> model) {
return new Model<String>() {
@Override
public String getObject() {
StringBuilder sb = new StringBuilder();
ConditionalSearchFilterType searchFilter = model.getObject();
if (searchFilter != null && searchFilter.getDescription() != null) {
sb.append(searchFilter.getDescription());
}
if (sb.toString().isEmpty()) {
sb.append(getString("SynchronizationStep.label.notSpecified"));
}
return sb.toString();
}
};
}
@Override
protected ConditionalSearchFilterType createNewEmptyItem() {
return new ConditionalSearchFilterType();
}
@Override
protected void editPerformed(AjaxRequestTarget target, ConditionalSearchFilterType object) {
correlationEditPerformed(target, object);
}
@Override
protected void performAddValueHook(AjaxRequestTarget target, ConditionalSearchFilterType added) {
parentPage.refreshIssues(target);
}
@Override
protected void performRemoveValueHook(AjaxRequestTarget target, ListItem<ConditionalSearchFilterType> item) {
parentPage.refreshIssues(target);
}
@Override
protected boolean buttonsDisabled() {
return !isAnySelected();
}
};
editor.add(editorCorrelation);
MultiValueTextEditPanel editorReaction = new MultiValueTextEditPanel<SynchronizationReactionType>(ID_EDITOR_REACTION, new PropertyModel<List<SynchronizationReactionType>>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".reaction"), new PropertyModel<SynchronizationReactionType>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED_REACTION), false, true, parentPage.getReadOnlyModel()) {
@Override
protected IModel<String> createTextModel(final IModel<SynchronizationReactionType> model) {
return new Model<String>() {
@Override
public String getObject() {
SynchronizationReactionType reaction = model.getObject();
if (reaction == null) {
return "";
}
StringBuilder sb = new StringBuilder();
sb.append(reaction.getName() != null ? reaction.getName() + " " : "");
sb.append("(");
if (reaction.getSituation() != null) {
sb.append(reaction.getSituation());
}
if (Boolean.TRUE.equals(reaction.isSynchronize()) || !reaction.getAction().isEmpty()) {
sb.append(" -> ");
if (!reaction.getAction().isEmpty()) {
boolean first = true;
for (SynchronizationActionType action : reaction.getAction()) {
if (first) {
first = false;
} else {
sb.append(", ");
}
sb.append(StringUtils.substringAfter(action.getHandlerUri(), "#"));
}
} else {
// TODO i18n
sb.append("sync");
}
}
sb.append(")");
return sb.toString();
}
};
}
@Override
protected SynchronizationReactionType createNewEmptyItem() {
return new SynchronizationReactionType();
}
@Override
protected void editPerformed(AjaxRequestTarget target, SynchronizationReactionType object) {
reactionEditPerformed(target, object);
}
@Override
protected void performAddValueHook(AjaxRequestTarget target, SynchronizationReactionType added) {
parentPage.refreshIssues(target);
}
@Override
protected void performRemoveValueHook(AjaxRequestTarget target, ListItem<SynchronizationReactionType> item) {
parentPage.refreshIssues(target);
}
@Override
protected boolean buttonsDisabled() {
return !isAnySelected();
}
};
editorReaction.setOutputMarkupId(true);
editor.add(editorReaction);
Label kindTooltip = new Label(ID_T_KIND);
kindTooltip.add(new InfoTooltipBehavior());
editor.add(kindTooltip);
Label intentTooltip = new Label(ID_T_INTENT);
intentTooltip.add(new InfoTooltipBehavior());
editor.add(intentTooltip);
Label objClassTooltip = new Label(ID_T_OBJ_CLASS);
objClassTooltip.add(new InfoTooltipBehavior());
editor.add(objClassTooltip);
Label focusTooltip = new Label(ID_T_FOCUS);
focusTooltip.add(new InfoTooltipBehavior());
editor.add(focusTooltip);
Label enabledTooltip = new Label(ID_T_ENABLED);
enabledTooltip.add(new InfoTooltipBehavior());
editor.add(enabledTooltip);
Label conditionTooltip = new Label(ID_T_CONDITION);
conditionTooltip.add(new InfoTooltipBehavior());
editor.add(conditionTooltip);
Label confirmationTooltip = new Label(ID_T_CONFIRMATION);
confirmationTooltip.add(new InfoTooltipBehavior());
editor.add(confirmationTooltip);
Label objTemplateTooltip = new Label(ID_T_OBJ_TEMPLATE);
objTemplateTooltip.add(new InfoTooltipBehavior());
editor.add(objTemplateTooltip);
Label reconcileTooltip = new Label(ID_T_RECONCILE);
reconcileTooltip.add(new InfoTooltipBehavior());
editor.add(reconcileTooltip);
Label opportunisticTooltip = new Label(ID_T_OPPORTUNISTIC);
opportunisticTooltip.add(new InfoTooltipBehavior());
editor.add(opportunisticTooltip);
Label correlationTooltip = new Label(ID_T_CORRELATION);
correlationTooltip.add(new InfoTooltipBehavior());
editor.add(correlationTooltip);
Label reactionTooltip = new Label(ID_T_REACTION);
reactionTooltip.add(new InfoTooltipBehavior());
editor.add(reactionTooltip);
}
use of com.evolveum.midpoint.web.component.input.QNameChoiceRenderer in project midpoint by Evolveum.
the class RoleMemberPanel method initSearch.
@Override
protected void initSearch(Form form) {
List<QName> allowedTypes = WebComponentUtil.createFocusTypeList();
allowedTypes.add(FocusType.COMPLEX_TYPE);
DropDownChoice<QName> typeSelect = createDropDown(ID_OBJECT_TYPE, Model.of(FocusType.COMPLEX_TYPE), allowedTypes, new QNameChoiceRenderer());
add(typeSelect);
DropDownChoice<OrgType> tenant = createDropDown(ID_TENANT, new Model(), createTenantList(), new ObjectTypeChoiceRenderer<OrgType>());
add(tenant);
tenant.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return isRole();
}
});
DropDownChoice<OrgType> project = createDropDown(ID_PROJECT, new Model(), createProjectList(), new ObjectTypeChoiceRenderer<OrgType>());
add(project);
project.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return isRole();
}
});
CheckBoxPanel includeIndirectMembers = new CheckBoxPanel(ID_INDIRECT_MEMBERS, new Model<Boolean>(false)) {
private static final long serialVersionUID = 1L;
public void onUpdate(AjaxRequestTarget target) {
refreshTable(target);
}
};
add(includeIndirectMembers);
// TODO shouldn't we hide also the label?
includeIndirectMembers.add(new VisibleBehaviour(this::isRole));
}
use of com.evolveum.midpoint.web.component.input.QNameChoiceRenderer in project midpoint by Evolveum.
the class ObjectBrowserPanel method initLayout.
private void initLayout(Class<? extends O> type, final List<QName> supportedTypes, final boolean multiselect) {
WebMarkupContainer typePanel = new WebMarkupContainer(ID_TYPE_PANEL);
typePanel.setOutputMarkupId(true);
typePanel.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return supportedTypes.size() != 1;
}
});
add(typePanel);
DropDownChoice<QName> typeSelect = new DropDownChoice<QName>(ID_TYPE, typeModel, new ListModel<QName>(supportedTypes), new QNameChoiceRenderer());
typeSelect.add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
ObjectListPanel<O> listPanel = (ObjectListPanel<O>) get(ID_TABLE);
listPanel = createObjectListPanel(qnameToCompileTimeClass(typeModel.getObject()), multiselect);
addOrReplace(listPanel);
target.add(listPanel);
}
});
typePanel.add(typeSelect);
ObjectListPanel<O> listPanel = createObjectListPanel(type, multiselect);
add(listPanel);
AjaxButton addButton = new AjaxButton(ID_BUTTON_ADD, createStringResource("userBrowserDialog.button.addButton")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
List<O> selected = ((PopupObjectListPanel) getParent().get(ID_TABLE)).getSelectedObjects();
QName type = ObjectBrowserPanel.this.typeModel.getObject();
ObjectBrowserPanel.this.addPerformed(target, type, selected);
}
};
addButton.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return multiselect;
}
});
add(addButton);
}
use of com.evolveum.midpoint.web.component.input.QNameChoiceRenderer in project midpoint by Evolveum.
the class CapabilityActivationPanel method initLayout.
protected void initLayout(PageResourceWizard parentPage) {
parentPage.addEditingEnabledBehavior(this);
CheckBox validFromEnabled = new CheckBox(ID_CHECK_VALID_FROM_ENABLED, new PropertyModel<Boolean>(getModel(), "capability.validFrom.enabled"));
add(validFromEnabled);
CheckBox validFromReturned = new CheckBox(ID_CHECK_VALID_FROM_RETURNED, new PropertyModel<Boolean>(getModel(), "capability.validFrom.returnedByDefault"));
add(validFromReturned);
CheckBox validToEnabled = new CheckBox(ID_CHECK_VALID_TO_ENABLED, new PropertyModel<Boolean>(getModel(), "capability.validTo.enabled"));
add(validToEnabled);
CheckBox validToReturned = new CheckBox(ID_CHECK_VALID_TO_RETURNED, new PropertyModel<Boolean>(getModel(), "capability.validTo.returnedByDefault"));
add(validToReturned);
add(new CheckBox(ID_CHECK_STATUS_ENABLED, new PropertyModel<Boolean>(getModel(), "capability.status.enabled")));
add(new CheckBox(ID_CHECK_STATUS_RETURNED, new PropertyModel<Boolean>(getModel(), "capability.status.returnedByDefault")));
add(new CheckBox(ID_CHECK_STATUS_IGNORE, new PropertyModel<Boolean>(getModel(), "capability.status.ignoreAttribute")));
MultiValueTextPanel statusEnableList = new MultiValueTextPanel<String>(ID_STATUS_ENABLE_LIST, new PropertyModel<List<String>>(getModel(), "capability.status.enableValue"), parentPage.getReadOnlyModel(), false) {
@Override
protected StringResourceModel createEmptyItemPlaceholder() {
return createStringResource("capabilityActivationPanel.list.placeholder");
}
};
add(statusEnableList);
MultiValueTextPanel statusDisableList = new MultiValueTextPanel<String>(ID_STATUS_DISABLE_LIST, new PropertyModel<List<String>>(getModel(), "capability.status.disableValue"), parentPage.getReadOnlyModel(), false) {
@Override
protected StringResourceModel createEmptyItemPlaceholder() {
return createStringResource("capabilityActivationPanel.list.placeholder");
}
};
add(statusDisableList);
IChoiceRenderer<QName> renderer = new QNameChoiceRenderer(true);
DropDownChoice statusChoice = new DropDownChoice<>(ID_SELECT_STATUS, new PropertyModel<QName>(getModel(), "capability.status.attribute"), createAttributeChoiceModel(renderer), renderer);
add(statusChoice);
add(new CheckBox(ID_CHECK_LOCKOUT_ENABLED, new PropertyModel<Boolean>(getModel(), "capability.lockoutStatus.enabled")));
add(new CheckBox(ID_CHECK_LOCKOUT_RETURNED, new PropertyModel<Boolean>(getModel(), "capability.lockoutStatus.returnedByDefault")));
add(new CheckBox(ID_CHECK_LOCKOUT_IGNORE, new PropertyModel<Boolean>(getModel(), "capability.lockoutStatus.ignoreAttribute")));
MultiValueTextPanel lockoutNormalList = new MultiValueTextPanel<String>(ID_LOCKOUT_NORMAL_LIST, new PropertyModel<List<String>>(getModel(), "capability.lockoutStatus.normalValue"), parentPage.getReadOnlyModel(), false) {
@Override
protected StringResourceModel createEmptyItemPlaceholder() {
return createStringResource("capabilityActivationPanel.list.placeholder");
}
};
add(lockoutNormalList);
MultiValueTextPanel lockoutLockedList = new MultiValueTextPanel<String>(ID_LOCKOUT_LOCKED_LIST, new PropertyModel<List<String>>(getModel(), "capability.lockoutStatus.lockedValue"), parentPage.getReadOnlyModel(), false) {
@Override
protected StringResourceModel createEmptyItemPlaceholder() {
return createStringResource("capabilityActivationPanel.list.placeholder");
}
};
add(lockoutLockedList);
IChoiceRenderer<QName> lockoutRenderer = new QNameChoiceRenderer(true);
DropDownChoice lockoutChoice = new DropDownChoice<>(ID_SELECT_LOCKOUT, new PropertyModel<QName>(getModel(), "capability.lockoutStatus.attribute"), createAttributeChoiceModel(lockoutRenderer), lockoutRenderer);
add(lockoutChoice);
add(WebComponentUtil.createHelp(ID_T_L_ENABLED));
add(WebComponentUtil.createHelp(ID_T_L_RETURNED_BY_DEFAULT));
add(WebComponentUtil.createHelp(ID_T_L_IGNORE_ATTR));
add(WebComponentUtil.createHelp(ID_T_L_ATTR_NAME));
add(WebComponentUtil.createHelp(ID_T_L_NORMAL_LIST));
add(WebComponentUtil.createHelp(ID_T_L_LOCKED_LIST));
Label enabledTooltip = new Label(ID_T_ENABLED);
enabledTooltip.add(new InfoTooltipBehavior());
add(enabledTooltip);
Label returnTooltip = new Label(ID_T_RETURNED_BY_DEFAULT);
returnTooltip.add(new InfoTooltipBehavior());
add(returnTooltip);
Label ignoreTooltip = new Label(ID_T_IGNORE_ATTR);
ignoreTooltip.add(new InfoTooltipBehavior());
add(ignoreTooltip);
Label attributeNameTooltip = new Label(ID_T_ATTR_NAME);
attributeNameTooltip.add(new InfoTooltipBehavior());
add(attributeNameTooltip);
Label enableListTooltip = new Label(ID_T_ENABLE_LIST);
enableListTooltip.add(new InfoTooltipBehavior());
add(enableListTooltip);
Label disableListTooltip = new Label(ID_T_DISABLE_LIST);
disableListTooltip.add(new InfoTooltipBehavior());
add(disableListTooltip);
Label vFromEnabledTooltip = new Label(ID_T_V_FROM_ENABLED);
vFromEnabledTooltip.add(new InfoTooltipBehavior());
add(vFromEnabledTooltip);
Label vFromReturnTooltip = new Label(ID_T_V_FROM_RETURN);
vFromReturnTooltip.add(new InfoTooltipBehavior());
add(vFromReturnTooltip);
Label vToEnabledTooltip = new Label(ID_T_V_TO_ENABLED);
vToEnabledTooltip.add(new InfoTooltipBehavior());
add(vToEnabledTooltip);
Label vToReturnTooltip = new Label(ID_T_V_TO_RETURN);
vToReturnTooltip.add(new InfoTooltipBehavior());
add(vToReturnTooltip);
}
use of com.evolveum.midpoint.web.component.input.QNameChoiceRenderer 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);
}
Aggregations