use of org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField in project midpoint by Evolveum.
the class MultiValueAutoCompleteTextPanel method initLayout.
private void initLayout(final boolean inputEnabled, final NonEmptyModel<Boolean> readOnlyModel) {
WebMarkupContainer placeholderContainer = new WebMarkupContainer(ID_PLACEHOLDER_CONTAINER);
placeholderContainer.setOutputMarkupPlaceholderTag(true);
placeholderContainer.setOutputMarkupPlaceholderTag(true);
placeholderContainer.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return getModel().getObject().isEmpty();
}
});
add(placeholderContainer);
AjaxLink placeholderAdd = new AjaxLink(ID_PLACEHOLDER_ADD) {
@Override
public void onClick(AjaxRequestTarget target) {
addValuePerformed(target);
}
};
placeholderAdd.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
if (buttonsDisabled()) {
return " " + CSS_DISABLED;
}
return "";
}
}));
placeholderAdd.setOutputMarkupId(true);
placeholderAdd.setOutputMarkupPlaceholderTag(true);
placeholderAdd.add(WebComponentUtil.visibleIfFalse(readOnlyModel));
placeholderContainer.add(placeholderAdd);
ListView repeater = new ListView<T>(ID_REPEATER, getModel()) {
@Override
protected void populateItem(final ListItem<T> item) {
AutoCompleteSettings autoCompleteSettings = new AutoCompleteSettings();
autoCompleteSettings.setShowListOnEmptyInput(true);
autoCompleteSettings.setMaxHeightInPx(200);
AutoCompleteTextField<String> autoCompleteEditor = new AutoCompleteTextField<String>(ID_TEXT, createTextModel(item.getModel()), autoCompleteSettings) {
@Override
protected Iterator<String> getChoices(String input) {
return createAutoCompleteObjectList(input);
}
};
autoCompleteEditor.add(createAutoCompleteValidator());
autoCompleteEditor.add(new AjaxFormComponentUpdatingBehavior("change") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
}
});
item.add(autoCompleteEditor);
autoCompleteEditor.add(AttributeAppender.replace("placeholder", createEmptyItemPlaceholder()));
if (!inputEnabled) {
autoCompleteEditor.add(new AttributeModifier("disabled", "disabled"));
}
item.add(autoCompleteEditor);
WebMarkupContainer buttonGroup = new WebMarkupContainer(ID_BUTTON_GROUP);
item.add(buttonGroup);
initButtons(buttonGroup, item, readOnlyModel);
}
};
repeater.setOutputMarkupId(true);
repeater.setOutputMarkupPlaceholderTag(true);
repeater.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return !getModel().getObject().isEmpty();
}
});
add(repeater);
}
use of org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField in project midpoint by Evolveum.
the class PageTaskAdd method initLayout.
private void initLayout() {
Form mainForm = new Form(ID_FORM_MAIN);
add(mainForm);
final DropDownChoice resource = new DropDownChoice<>(ID_RESOURCE, new PropertyModel<TaskAddResourcesDto>(model, TaskAddDto.F_RESOURCE), new AbstractReadOnlyModel<List<TaskAddResourcesDto>>() {
@Override
public List<TaskAddResourcesDto> getObject() {
return createResourceList();
}
}, new ChoiceableChoiceRenderer<TaskAddResourcesDto>());
resource.add(new VisibleEnableBehaviour() {
@Override
public boolean isEnabled() {
TaskAddDto dto = model.getObject();
boolean sync = TaskCategory.LIVE_SYNCHRONIZATION.equals(dto.getCategory());
boolean recon = TaskCategory.RECONCILIATION.equals(dto.getCategory());
boolean importAccounts = TaskCategory.IMPORTING_ACCOUNTS.equals(dto.getCategory());
return sync || recon || importAccounts;
}
});
resource.add(new AjaxFormComponentUpdatingBehavior("change") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
PageTaskAdd.this.loadResource();
target.add(get(ID_FORM_MAIN + ":" + ID_OBJECT_CLASS));
}
});
resource.setOutputMarkupId(true);
mainForm.add(resource);
final DropDownChoice focusType = new DropDownChoice<>(ID_FOCUS_TYPE, new PropertyModel<QName>(model, TaskAddDto.F_FOCUS_TYPE), new AbstractReadOnlyModel<List<QName>>() {
@Override
public List<QName> getObject() {
return createFocusTypeList();
}
}, new QNameChoiceRenderer());
focusType.setOutputMarkupId(true);
focusType.add(new VisibleEnableBehaviour() {
@Override
public boolean isEnabled() {
TaskAddDto dto = model.getObject();
return TaskCategory.RECOMPUTATION.equals(dto.getCategory());
}
});
mainForm.add(focusType);
final DropDownChoice kind = new DropDownChoice<>(ID_KIND, new PropertyModel<ShadowKindType>(model, TaskAddDto.F_KIND), WebComponentUtil.createReadonlyModelFromEnum(ShadowKindType.class), new EnumChoiceRenderer<ShadowKindType>());
kind.setOutputMarkupId(true);
kind.add(new VisibleEnableBehaviour() {
@Override
public boolean isEnabled() {
TaskAddDto dto = model.getObject();
boolean sync = TaskCategory.LIVE_SYNCHRONIZATION.equals(dto.getCategory());
boolean recon = TaskCategory.RECONCILIATION.equals(dto.getCategory());
boolean importAccounts = TaskCategory.IMPORTING_ACCOUNTS.equals(dto.getCategory());
return sync || recon || importAccounts;
}
});
mainForm.add(kind);
final TextField<String> intent = new TextField<>(ID_INTENT, new PropertyModel<String>(model, TaskAddDto.F_INTENT));
mainForm.add(intent);
intent.setOutputMarkupId(true);
intent.add(new VisibleEnableBehaviour() {
@Override
public boolean isEnabled() {
TaskAddDto dto = model.getObject();
boolean sync = TaskCategory.LIVE_SYNCHRONIZATION.equals(dto.getCategory());
boolean recon = TaskCategory.RECONCILIATION.equals(dto.getCategory());
boolean importAccounts = TaskCategory.IMPORTING_ACCOUNTS.equals(dto.getCategory());
return sync || recon || importAccounts;
}
});
if (model.getObject() != null && model.getObject().getResource() != null && model.getObject().getResource().getOid() != null) {
loadResource();
}
AutoCompleteSettings autoCompleteSettings = new AutoCompleteSettings();
autoCompleteSettings.setShowListOnEmptyInput(true);
autoCompleteSettings.setMaxHeightInPx(200);
final AutoCompleteTextField<String> objectClass = new AutoCompleteTextField<String>(ID_OBJECT_CLASS, new PropertyModel<String>(model, TaskAddDto.F_OBJECT_CLASS), autoCompleteSettings) {
@Override
protected Iterator<String> getChoices(String input) {
return prepareObjectClassChoiceList(input);
}
};
objectClass.add(new VisibleEnableBehaviour() {
@Override
public boolean isEnabled() {
TaskAddDto dto = model.getObject();
boolean sync = TaskCategory.LIVE_SYNCHRONIZATION.equals(dto.getCategory());
boolean recon = TaskCategory.RECONCILIATION.equals(dto.getCategory());
boolean importAccounts = TaskCategory.IMPORTING_ACCOUNTS.equals(dto.getCategory());
return sync || recon || importAccounts;
}
});
mainForm.add(objectClass);
DropDownChoice type = new DropDownChoice<>(ID_CATEGORY, new PropertyModel<String>(model, TaskAddDto.F_CATEGORY), new AbstractReadOnlyModel<List<String>>() {
@Override
public List<String> getObject() {
return WebComponentUtil.createTaskCategoryList();
}
}, new StringChoiceRenderer("pageTask.category."));
type.add(new AjaxFormComponentUpdatingBehavior("change") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(resource);
target.add(intent);
target.add(kind);
target.add(objectClass);
target.add(focusType);
}
});
type.setRequired(true);
mainForm.add(type);
TextField<String> name = new TextField<>(ID_NAME, new PropertyModel<String>(model, TaskAddDto.F_NAME));
name.setRequired(true);
mainForm.add(name);
initScheduling(mainForm);
initAdvanced(mainForm);
CheckBox dryRun = new CheckBox(ID_DRY_RUN, new PropertyModel<Boolean>(model, TaskAddDto.F_DRY_RUN));
mainForm.add(dryRun);
initButtons(mainForm);
}
use of org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField in project midpoint by Evolveum.
the class SchemaHandlingStep method initObjectTypeEditor.
private void initObjectTypeEditor(WebMarkupContainer editor) {
Label editorLabel = new Label(ID_EDITOR_NAME, new AbstractReadOnlyModel<Object>() {
@Override
public String getObject() {
ResourceObjectTypeDefinitionTypeDto selected = schemaHandlingDtoModel.getObject().getSelectedObjectTypeDto();
return selected != null ? selected.getObjectType().getDisplayName() : "";
}
});
editorLabel.setOutputMarkupId(true);
editor.add(editorLabel);
DropDownChoice editorKind = new DropDownChoice<>(ID_EDITOR_KIND, new PropertyModel<ShadowKindType>(schemaHandlingDtoModel, getExpression(ResourceObjectTypeDefinitionType.F_KIND)), WebComponentUtil.createReadonlyModelFromEnum(ShadowKindType.class), new EnumChoiceRenderer<ShadowKindType>(this));
editorKind.add(new UpdateNamesBehaviour());
parentPage.addEditingEnabledBehavior(editorKind);
editor.add(editorKind);
TextField editorIntent = new TextField<>(ID_EDITOR_INTENT, new PropertyModel<String>(schemaHandlingDtoModel, getExpression(ResourceObjectTypeDefinitionType.F_INTENT)));
editorIntent.add(new UpdateNamesBehaviour());
parentPage.addEditingEnabledBehavior(editorIntent);
editor.add(editorIntent);
TextField editorDisplayName = new TextField<>(ID_EDITOR_DISPLAY_NAME, new PropertyModel<String>(schemaHandlingDtoModel, getExpression(ResourceObjectTypeDefinitionType.F_DISPLAY_NAME)));
editorDisplayName.add(new UpdateNamesBehaviour());
parentPage.addEditingEnabledBehavior(editorDisplayName);
editor.add(editorDisplayName);
TextArea editorDescription = new TextArea<>(ID_EDITOR_DESCRIPTION, new PropertyModel<String>(schemaHandlingDtoModel, getExpression(ResourceObjectTypeDefinitionType.F_DESCRIPTION)));
parentPage.addEditingEnabledBehavior(editorDescription);
editor.add(editorDescription);
final CheckBox editorDefault = new CheckBox(ID_EDITOR_DEFAULT, new PropertyModel<Boolean>(schemaHandlingDtoModel, getExpression(ResourceObjectTypeDefinitionType.F_DEFAULT)));
editorDefault.add(new EmptyOnChangeAjaxFormUpdatingBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
Boolean newValue = editorDefault.getModelObject();
if (Boolean.TRUE.equals(newValue)) {
SchemaHandlingDto dto = schemaHandlingDtoModel.getObject();
ResourceObjectTypeDefinitionTypeDto selected = dto.getSelectedObjectTypeDto();
ShadowKindType selectedKind = fillDefault(selected.getObjectType().getKind());
for (ResourceObjectTypeDefinitionTypeDto currentObjectTypeDto : dto.getObjectTypeDtoList()) {
ShadowKindType currentKind = fillDefault(currentObjectTypeDto.getObjectType().getKind());
if (currentObjectTypeDto != selected && currentKind == selectedKind && Boolean.TRUE.equals(currentObjectTypeDto.getObjectType().isDefault())) {
currentObjectTypeDto.getObjectType().setDefault(false);
}
}
}
parentPage.refreshIssues(target);
}
});
parentPage.addEditingEnabledBehavior(editorDefault);
editor.add(editorDefault);
AjaxSubmitLink editorDependency = new AjaxSubmitLink(ID_EDITOR_BUTTON_DEPENDENCY) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
dependencyEditPerformed(target);
}
};
addDisabledClassModifier(editorDependency);
editor.add(editorDependency);
AutoCompleteSettings autoCompleteSettings = new AutoCompleteSettings();
autoCompleteSettings.setShowListOnEmptyInput(true);
autoCompleteSettings.setMaxHeightInPx(200);
AutoCompleteTextField<String> editorObjectClass = new AutoCompleteTextField<String>(ID_EDITOR_OBJECT_CLASS, new PropertyModel<String>(schemaHandlingDtoModel, SchemaHandlingDto.F_OBJECT_CLASS_NAME), autoCompleteSettings) {
@Override
protected Iterator<String> getChoices(String input) {
return getObjectClassChoices(input);
}
};
editorObjectClass.add(new UpdateNamesBehaviour());
editorObjectClass.add(createObjectClassValidator(new AbstractReadOnlyModel<List<QName>>() {
@Override
public List<QName> getObject() {
return schemaHandlingDtoModel.getObject().getObjectClassList();
}
}));
parentPage.addEditingEnabledBehavior(editorObjectClass);
editorObjectClass.setConvertEmptyInputStringToNull(true);
editor.add(editorObjectClass);
MultiValueTextEditPanel editorAttributes = new MultiValueTextEditPanel<ResourceAttributeDefinitionType>(ID_EDITOR_ATTRIBUTES, new PropertyModel<List<ResourceAttributeDefinitionType>>(schemaHandlingDtoModel, getExpression(ResourceObjectTypeDefinitionType.F_ATTRIBUTE)), new PropertyModel<ResourceAttributeDefinitionType>(schemaHandlingDtoModel, SchemaHandlingDto.F_SELECTED_ATTRIBUTE), false, true, parentPage.getReadOnlyModel()) {
@Override
protected IModel<String> createTextModel(final IModel<ResourceAttributeDefinitionType> model) {
return new Model<String>() {
@Override
public String getObject() {
if (model == null || model.getObject() == null) {
return null;
}
ResourceAttributeDefinitionType attribute = model.getObject();
return formatItemInfo(attribute, attribute.getRef(), attribute.getDisplayName(), attribute.getInbound(), attribute.getOutbound());
}
};
}
@Override
protected ResourceAttributeDefinitionType createNewEmptyItem() {
return createEmptyAttributeObject();
}
@Override
protected void performAddValueHook(AjaxRequestTarget target, ResourceAttributeDefinitionType added) {
parentPage.refreshIssues(target);
}
@Override
protected void editPerformed(AjaxRequestTarget target, ResourceAttributeDefinitionType object) {
editAttributePerformed(target, object);
}
@Override
protected boolean buttonsDisabled() {
return !isAnySelected();
}
@Override
protected void performRemoveValueHook(AjaxRequestTarget target, ListItem<ResourceAttributeDefinitionType> item) {
resetThirdRowContainer(target);
parentPage.refreshIssues(target);
}
};
editorAttributes.setOutputMarkupId(true);
editor.add(editorAttributes);
MultiValueTextEditPanel editorAssociations = new MultiValueTextEditPanel<ResourceObjectAssociationType>(ID_EDITOR_ASSOCIATIONS, new PropertyModel<List<ResourceObjectAssociationType>>(schemaHandlingDtoModel, getExpression(ResourceObjectTypeDefinitionType.F_ASSOCIATION)), new PropertyModel<ResourceObjectAssociationType>(schemaHandlingDtoModel, SchemaHandlingDto.F_SELECTED_ASSOCIATION), false, true, parentPage.getReadOnlyModel()) {
@Override
protected IModel<String> createTextModel(final IModel<ResourceObjectAssociationType> model) {
return new Model<String>() {
@Override
public String getObject() {
ResourceObjectAssociationType association = model.getObject();
if (association == null) {
return null;
}
return formatItemInfo(association, association.getRef(), association.getDisplayName(), association.getInbound(), association.getOutbound());
}
};
}
@Override
protected ResourceObjectAssociationType createNewEmptyItem() {
return createEmptyAssociationObject();
}
@Override
protected void performAddValueHook(AjaxRequestTarget target, ResourceObjectAssociationType added) {
parentPage.refreshIssues(target);
}
@Override
protected void editPerformed(AjaxRequestTarget target, ResourceObjectAssociationType object) {
editAssociationPerformed(target, object);
}
@Override
protected boolean buttonsDisabled() {
return !isAnySelected();
}
@Override
protected void performRemoveValueHook(AjaxRequestTarget target, ListItem<ResourceObjectAssociationType> item) {
resetThirdRowContainer(target);
parentPage.refreshIssues(target);
}
};
editorAssociations.setOutputMarkupId(true);
editor.add(editorAssociations);
// DropDownChoice editorAssignmentPolicyRef = new DropDownChoice<>(ID_EDITOR_ASSIGNMENT_POLICY,
// new PropertyModel<AssignmentPolicyEnforcementType>(schemaHandlingDtoModel,
// getExpression(ResourceObjectTypeDefinitionType.F_ASSIGNMENT_POLICY_ENFORCEMENT)),
// WebComponentUtil.createReadonlyModelFromEnum(AssignmentPolicyEnforcementType.class),
// new EnumChoiceRenderer<AssignmentPolicyEnforcementType>(this));
// parentPage.addEditingEnabledBehavior(editorAssignmentPolicyRef);
// editor.add(editorAssignmentPolicyRef);
AjaxSubmitLink editorIteration = new AjaxSubmitLink(ID_EDITOR_BUTTON_ITERATION) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
iterationEditPerformed(target);
}
};
addDisabledClassModifier(editorIteration);
editor.add(editorIteration);
AjaxSubmitLink editorProtected = new AjaxSubmitLink(ID_EDITOR_BUTTON_PROTECTED) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
protectedEditPerformed(target);
}
};
addDisabledClassModifier(editorProtected);
editor.add(editorProtected);
AjaxSubmitLink editorActivation = new AjaxSubmitLink(ID_EDITOR_BUTTON_ACTIVATION) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
activationEditPerformed(target);
}
};
addDisabledClassModifier(editorActivation);
editor.add(editorActivation);
AjaxSubmitLink editorCredentials = new AjaxSubmitLink(ID_EDITOR_BUTTON_CREDENTIALS) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
credentialsEditPerformed(target);
}
};
addDisabledClassModifier(editorCredentials);
editor.add(editorCredentials);
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 defaultTooltip = new Label(ID_T_DEFAULT);
defaultTooltip.add(new InfoTooltipBehavior());
editor.add(defaultTooltip);
Label dependencyTooltip = new Label(ID_T_DEPENDENCY);
dependencyTooltip.add(new InfoTooltipBehavior());
editor.add(dependencyTooltip);
Label objectClassTooltip = new Label(ID_T_OBJECT_CLASS);
objectClassTooltip.add(new InfoTooltipBehavior());
editor.add(objectClassTooltip);
Label attributesTooltip = new Label(ID_T_ATTRIBUTES);
attributesTooltip.add(new InfoTooltipBehavior());
editor.add(attributesTooltip);
Label associationsTooltip = new Label(ID_T_ASSOCIATIONS);
associationsTooltip.add(new InfoTooltipBehavior());
editor.add(associationsTooltip);
Label assignmentPolicyRefTooltip = new Label(ID_T_ASSIGNMENT_POLICY_REF);
assignmentPolicyRefTooltip.add(new InfoTooltipBehavior());
editor.add(assignmentPolicyRefTooltip);
Label iterationTooltip = new Label(ID_T_ITERATION);
iterationTooltip.add(new InfoTooltipBehavior());
editor.add(iterationTooltip);
Label protectedTooltip = new Label(ID_T_PROTECTED);
protectedTooltip.add(new InfoTooltipBehavior());
editor.add(protectedTooltip);
Label activationTooltip = new Label(ID_T_ACTIVATION);
activationTooltip.add(new InfoTooltipBehavior());
editor.add(activationTooltip);
Label credentialsTooltip = new Label(ID_T_CREDENTIALS);
credentialsTooltip.add(new InfoTooltipBehavior());
editor.add(credentialsTooltip);
}
use of org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField in project midpoint by Evolveum.
the class PrismValuePanel method createTypedInputComponent.
// normally this method returns an InputPanel;
// however, for some special readonly types (like ObjectDeltaType) it will return a Panel
private Panel createTypedInputComponent(String id) {
// ValueWrapper valueWrapper = model.getObject();
// ItemWrapper itemWrapper =
final Item item = valueWrapperModel.getObject().getItem().getItem();
Panel panel = null;
if (item instanceof PrismProperty) {
final PrismProperty property = (PrismProperty) item;
PrismPropertyDefinition definition = property.getDefinition();
final QName valueType = definition.getTypeName();
//pointing to prism property real value
final String baseExpression = "value.value";
//now it works only in description
if (ObjectType.F_DESCRIPTION.equals(definition.getName())) {
return new TextAreaPanel(id, new PropertyModel(valueWrapperModel, baseExpression), null);
}
if (ActivationType.F_ADMINISTRATIVE_STATUS.equals(definition.getName())) {
return WebComponentUtil.createEnumPanel(ActivationStatusType.class, id, new PropertyModel<ActivationStatusType>(valueWrapperModel, baseExpression), this);
} else if (ActivationType.F_LOCKOUT_STATUS.equals(definition.getName())) {
return new LockoutStatusPanel(id, valueWrapperModel.getObject(), new PropertyModel<LockoutStatusType>(valueWrapperModel, baseExpression));
} else {
if (definition.getTypeName().getLocalPart().equals(ActivationStatusType.class.getSimpleName())) {
return WebComponentUtil.createEnumPanel(ActivationStatusType.class, id, new PropertyModel<ActivationStatusType>(valueWrapperModel, baseExpression), this);
}
}
if (DOMUtil.XSD_DATETIME.equals(valueType)) {
panel = new DatePanel(id, new PropertyModel<XMLGregorianCalendar>(valueWrapperModel, baseExpression));
} else if (ProtectedStringType.COMPLEX_TYPE.equals(valueType)) {
panel = new PasswordPanel(id, new PropertyModel<ProtectedStringType>(valueWrapperModel, baseExpression), valueWrapperModel.getObject().isReadonly());
} else if (DOMUtil.XSD_BOOLEAN.equals(valueType)) {
panel = new TriStateComboPanel(id, new PropertyModel<Boolean>(valueWrapperModel, baseExpression));
} else if (SchemaConstants.T_POLY_STRING_TYPE.equals(valueType)) {
InputPanel inputPanel;
PrismPropertyDefinition def = property.getDefinition();
if (def.getValueEnumerationRef() != null) {
PrismReferenceValue valueEnumerationRef = def.getValueEnumerationRef();
String lookupTableUid = valueEnumerationRef.getOid();
Task task = pageBase.createSimpleTask("loadLookupTable");
OperationResult result = task.getResult();
Collection<SelectorOptions<GetOperationOptions>> options = WebModelServiceUtils.createLookupTableRetrieveOptions();
final PrismObject<LookupTableType> lookupTable = WebModelServiceUtils.loadObject(LookupTableType.class, lookupTableUid, options, pageBase, task, result);
if (lookupTable != null) {
inputPanel = new AutoCompleteTextPanel<String>(id, new LookupPropertyModel<String>(valueWrapperModel, baseExpression + ".orig", lookupTable.asObjectable()), String.class) {
@Override
public Iterator<String> getIterator(String input) {
return prepareAutoCompleteList(input, lookupTable).iterator();
}
};
} else {
inputPanel = new TextPanel<>(id, new PropertyModel<String>(valueWrapperModel, baseExpression + ".orig"), String.class);
}
} else {
inputPanel = new TextPanel<>(id, new PropertyModel<String>(valueWrapperModel, baseExpression + ".orig"), String.class);
}
if (ObjectType.F_NAME.equals(def.getName()) || UserType.F_FULL_NAME.equals(def.getName())) {
inputPanel.getBaseFormComponent().setRequired(true);
}
panel = inputPanel;
} else if (DOMUtil.XSD_BASE64BINARY.equals(valueType)) {
panel = new UploadDownloadPanel(id, valueWrapperModel.getObject().isReadonly()) {
@Override
public InputStream getStream() {
Object object = ((PrismPropertyValue) valueWrapperModel.getObject().getValue()).getValue();
return object != null ? new ByteArrayInputStream((byte[]) object) : new ByteArrayInputStream(new byte[0]);
// return super.getStream();
}
@Override
public void updateValue(byte[] file) {
((PrismPropertyValue) valueWrapperModel.getObject().getValue()).setValue(file);
}
@Override
public void uploadFilePerformed(AjaxRequestTarget target) {
super.uploadFilePerformed(target);
target.add(PrismValuePanel.this.get(ID_FEEDBACK));
}
@Override
public void removeFilePerformed(AjaxRequestTarget target) {
super.removeFilePerformed(target);
target.add(PrismValuePanel.this.get(ID_FEEDBACK));
}
@Override
public void uploadFileFailed(AjaxRequestTarget target) {
super.uploadFileFailed(target);
target.add(PrismValuePanel.this.get(ID_FEEDBACK));
target.add(((PageBase) getPage()).getFeedbackPanel());
}
};
} else if (ObjectDeltaType.COMPLEX_TYPE.equals(valueType)) {
panel = new ModificationsPanel(id, new AbstractReadOnlyModel<DeltaDto>() {
@Override
public DeltaDto getObject() {
if (valueWrapperModel.getObject() == null || valueWrapperModel.getObject().getValue() == null || ((PrismPropertyValue) valueWrapperModel.getObject().getValue()).getValue() == null) {
return null;
}
PrismContext prismContext = ((PageBase) getPage()).getPrismContext();
ObjectDeltaType objectDeltaType = (ObjectDeltaType) ((PrismPropertyValue) valueWrapperModel.getObject().getValue()).getValue();
try {
ObjectDelta delta = DeltaConvertor.createObjectDelta(objectDeltaType, prismContext);
return new DeltaDto(delta);
} catch (SchemaException e) {
throw new IllegalStateException("Couldn't convert object delta: " + objectDeltaType);
}
}
});
} else if (QueryType.COMPLEX_TYPE.equals(valueType) || CleanupPoliciesType.COMPLEX_TYPE.equals(valueType)) {
return new TextAreaPanel(id, new AbstractReadOnlyModel() {
@Override
public Object getObject() {
if (valueWrapperModel.getObject() == null || valueWrapperModel.getObject().getValue() == null) {
return null;
}
PrismPropertyValue ppv = (PrismPropertyValue) valueWrapperModel.getObject().getValue();
if (ppv == null || ppv.getValue() == null) {
return null;
}
QName name = property.getElementName();
if (name == null && property.getDefinition() != null) {
name = property.getDefinition().getName();
}
if (name == null) {
name = SchemaConstants.C_VALUE;
}
PrismContext prismContext = ((PageBase) getPage()).getPrismContext();
try {
return prismContext.xmlSerializer().serializeAnyData(ppv.getValue(), name);
} catch (SchemaException e) {
throw new SystemException("Couldn't serialize property value of type: " + valueType + ": " + e.getMessage(), e);
}
}
}, 10);
} else {
Class type = XsdTypeMapper.getXsdToJavaMapping(valueType);
if (type != null && type.isPrimitive()) {
type = ClassUtils.primitiveToWrapper(type);
}
if (isEnum(property)) {
return WebComponentUtil.createEnumPanel(definition, id, new PropertyModel<>(valueWrapperModel, baseExpression), this);
}
// // default QName validation is a bit weird, so let's treat QNames as strings [TODO finish this - at the parsing side]
// if (type == QName.class) {
// type = String.class;
// }
PrismPropertyDefinition def = property.getDefinition();
if (def.getValueEnumerationRef() != null) {
PrismReferenceValue valueEnumerationRef = def.getValueEnumerationRef();
String lookupTableUid = valueEnumerationRef.getOid();
Task task = pageBase.createSimpleTask("loadLookupTable");
OperationResult result = task.getResult();
Collection<SelectorOptions<GetOperationOptions>> options = WebModelServiceUtils.createLookupTableRetrieveOptions();
final PrismObject<LookupTableType> lookupTable = WebModelServiceUtils.loadObject(LookupTableType.class, lookupTableUid, options, pageBase, task, result);
if (lookupTable != null) {
panel = new AutoCompleteTextPanel<String>(id, new LookupPropertyModel<String>(valueWrapperModel, baseExpression, lookupTable == null ? null : lookupTable.asObjectable()), type) {
@Override
public Iterator<String> getIterator(String input) {
return prepareAutoCompleteList(input, lookupTable).iterator();
}
@Override
public void checkInputValue(AutoCompleteTextField input, AjaxRequestTarget target, LookupPropertyModel model) {
Iterator<String> lookupTableValuesIterator = prepareAutoCompleteList("", lookupTable).iterator();
String value = input.getInput();
boolean isValueExist = false;
if (value != null) {
if (value.trim().equals("")) {
isValueExist = true;
} else {
while (lookupTableValuesIterator.hasNext()) {
String lookupTableValue = lookupTableValuesIterator.next();
if (value.trim().equals(lookupTableValue)) {
isValueExist = true;
break;
}
}
}
}
if (isValueExist) {
input.setModelValue(new String[] { value });
target.add(PrismValuePanel.this.get(ID_FEEDBACK));
} else {
input.error("Entered value doesn't match any of available values and will not be saved.");
target.add(PrismValuePanel.this.get(ID_FEEDBACK));
}
}
};
} else {
panel = new TextPanel<>(id, new PropertyModel<String>(valueWrapperModel, baseExpression), type);
}
} else {
panel = new TextPanel<>(id, new PropertyModel<String>(valueWrapperModel, baseExpression), type);
}
}
} else if (item instanceof PrismReference) {
PrismContext prismContext = item.getPrismContext();
if (prismContext == null) {
prismContext = pageBase.getPrismContext();
}
QName targetTypeName = ((PrismReferenceDefinition) item.getDefinition()).getTargetTypeName();
Class targetClass = null;
if (targetTypeName != null && prismContext != null) {
targetClass = prismContext.getSchemaRegistry().determineCompileTimeClass(targetTypeName);
}
final Class typeClass = targetClass != null ? targetClass : (item.getDefinition().getTypeClassIfKnown() != null ? item.getDefinition().getTypeClassIfKnown() : FocusType.class);
Collection typeClasses = new ArrayList();
// HACK HACK MID-3201 MID-3231
if (isUserOrgItem(item, typeClass)) {
typeClasses.add(UserType.class);
typeClasses.add(OrgType.class);
} else {
typeClasses.add(typeClass);
}
panel = new ValueChoosePanel(id, new PropertyModel<>(valueWrapperModel, "value"), item.getValues(), false, typeClasses);
} else if (item instanceof PrismContainer<?>) {
AssociationWrapper itemWrapper = (AssociationWrapper) valueWrapperModel.getObject().getItem();
final PrismContainer container = (PrismContainer) item;
PrismContainerDefinition definition = container.getDefinition();
QName valueType = definition.getTypeName();
if (ShadowAssociationType.COMPLEX_TYPE.equals(valueType)) {
PrismContext prismContext = item.getPrismContext();
if (prismContext == null) {
prismContext = pageBase.getPrismContext();
}
ShadowType shadowType = ((ShadowType) itemWrapper.getContainer().getObject().getObject().asObjectable());
PrismObject<ResourceType> resource = shadowType.getResource().asPrismObject();
// of resources.
try {
resource.revive(prismContext);
} catch (SchemaException e) {
throw new SystemException(e.getMessage(), e);
}
RefinedResourceSchema refinedSchema;
CompositeRefinedObjectClassDefinition rOcDef;
try {
refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
rOcDef = refinedSchema.determineCompositeObjectClassDefinition(shadowType.asPrismObject());
} catch (SchemaException e) {
throw new SystemException(e.getMessage(), e);
}
RefinedAssociationDefinition assocDef = itemWrapper.getRefinedAssociationDefinition();
RefinedObjectClassDefinition assocTargetDef = assocDef.getAssociationTarget();
ObjectQuery query = getAssociationsSearchQuery(prismContext, resource, assocTargetDef.getTypeName(), assocTargetDef.getKind());
List values = item.getValues();
return new AssociationValueChoicePanel(id, valueWrapperModel, values, false, ShadowType.class, query, assocTargetDef);
}
}
return panel;
}
Aggregations