use of org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteSettings in project midpoint by Evolveum.
the class AutoCompleteQNamePanel method initLayout.
private void initLayout(final IModel<QName> model) {
setOutputMarkupId(true);
AutoCompleteSettings autoCompleteSettings = createAutoCompleteSettings();
final IModel<String> stringModel = new Model<String>() {
@Override
public void setObject(String object) {
super.setObject(object);
model.setObject(convertToQname(object));
}
};
// The inner autocomplete field is always String. Non-string auto-complete fields are problematic
final AutoCompleteTextField<String> input = new AutoCompleteTextField<String>(ID_INPUT, stringModel, String.class, autoCompleteSettings) {
private static final long serialVersionUID = 1L;
@Override
protected Iterator<String> getChoices(String input) {
return getIterator(input);
}
};
input.add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
String inputString = stringModel.getObject();
if (StringUtils.isBlank(inputString)) {
QName modelObject = model.getObject();
if (modelObject != null) {
model.setObject(null);
AutoCompleteQNamePanel.this.onChange(target);
}
} else {
QName inputQName = convertToQname(stringModel.getObject());
if (inputQName == null) {
// We have some input, but it does not match any QName. Just do nothing.
} else {
QName modelObject = model.getObject();
if (inputQName.equals(modelObject)) {
model.setObject(inputQName);
AutoCompleteQNamePanel.this.onChange(target);
}
}
}
}
});
add(input);
}
use of org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteSettings in project midpoint by Evolveum.
the class ResourceRelatedHandlerPanel method initLayout.
private void initLayout() {
final VisibleEnableBehaviour visibleIfEdit = new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return parentPage.isEdit();
}
};
final VisibleEnableBehaviour visibleIfView = new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return !parentPage.isEdit();
}
};
enabledIfEdit = new VisibleEnableBehaviour() {
@Override
public boolean isEnabled() {
return parentPage.isEdit();
}
};
final VisibleEnableBehaviour visibleForResourceCoordinates = new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return getTaskDto().configuresResourceCoordinates();
}
};
final WebMarkupContainer resourceRefContainer = new WebMarkupContainer(ID_RESOURCE_REF_CONTAINER);
resourceRefContainer.add(visibleForResourceCoordinates);
resourceRefContainer.setOutputMarkupId(true);
add(resourceRefContainer);
final DropDownChoice<TaskAddResourcesDto> resourceRef = new DropDownChoice<>(ID_RESOURCE_REF, new PropertyModel<TaskAddResourcesDto>(getModel(), ResourceRelatedHandlerDto.F_RESOURCE_REFERENCE), new AbstractReadOnlyModel<List<TaskAddResourcesDto>>() {
@Override
public List<TaskAddResourcesDto> getObject() {
return createResourceList();
}
}, new ChoiceableChoiceRenderer<TaskAddResourcesDto>());
resourceRef.setOutputMarkupId(true);
resourceRef.add(enabledIfEdit);
resourceRef.add(new AjaxFormComponentUpdatingBehavior("change") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
Task task = parentPage.createSimpleTask(OPERATION_LOAD_RESOURCE);
OperationResult result = task.getResult();
List<QName> objectClassList = new ArrayList<>();
TaskAddResourcesDto resourcesDto = getModelObject().getResourceRef();
if (resourcesDto != null) {
PrismObject<ResourceType> resource = WebModelServiceUtils.loadObject(ResourceType.class, resourcesDto.getOid(), parentPage, task, result);
try {
ResourceSchema schema = RefinedResourceSchemaImpl.getResourceSchema(resource, parentPage.getPrismContext());
schema.getObjectClassDefinitions();
for (Definition def : schema.getDefinitions()) {
objectClassList.add(def.getTypeName());
}
getModelObject().setObjectClassList(objectClassList);
} catch (Exception e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load object class list from resource.", e);
error("Couldn't load object class list from resource.");
}
}
target.add(resourceRefContainer);
}
});
resourceRefContainer.add(resourceRef);
WebMarkupContainer kindContainer = new WebMarkupContainer(ID_KIND_CONTAINER);
kindContainer.add(visibleForResourceCoordinates);
add(kindContainer);
final DropDownChoice kind = new DropDownChoice<>(ID_KIND, new PropertyModel<ShadowKindType>(getModel(), ResourceRelatedHandlerDto.F_KIND), WebComponentUtil.createReadonlyModelFromEnum(ShadowKindType.class), new EnumChoiceRenderer<ShadowKindType>());
kind.setOutputMarkupId(true);
kind.setNullValid(true);
kindContainer.add(kind);
WebMarkupContainer intentContainer = new WebMarkupContainer(ID_INTENT_CONTAINER);
intentContainer.add(visibleForResourceCoordinates);
add(intentContainer);
final TextField<String> intent = new TextField<>(ID_INTENT, new PropertyModel<String>(getModel(), ResourceRelatedHandlerDto.F_INTENT));
intentContainer.add(intent);
intent.setOutputMarkupId(true);
intent.add(enabledIfEdit);
WebMarkupContainer objectClassContainer = new WebMarkupContainer(ID_OBJECT_CLASS_CONTAINER);
objectClassContainer.add(visibleForResourceCoordinates);
add(objectClassContainer);
AutoCompleteSettings autoCompleteSettings = new AutoCompleteSettings();
autoCompleteSettings.setShowListOnEmptyInput(true);
final AutoCompleteTextField<String> objectClass = new AutoCompleteTextField<String>(ID_OBJECT_CLASS, new PropertyModel<String>(getModel(), ResourceRelatedHandlerDto.F_OBJECT_CLASS), autoCompleteSettings) {
@Override
protected Iterator<String> getChoices(String input) {
return prepareObjectClassChoiceList(input);
}
};
objectClass.add(enabledIfEdit);
objectClassContainer.add(objectClass);
WebMarkupContainer optionsContainer = new WebMarkupContainer(ID_OPTIONS_CONTAINER);
optionsContainer.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return getTaskDto().configuresDryRun();
}
});
add(optionsContainer);
WebMarkupContainer dryRunContainer = new WebMarkupContainer(ID_DRY_RUN_CONTAINER);
dryRunContainer.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return getTaskDto().configuresDryRun();
}
});
optionsContainer.add(dryRunContainer);
CheckBox dryRun = new CheckBox(ID_DRY_RUN, new PropertyModel<Boolean>(getModel(), ResourceRelatedHandlerDto.F_DRY_RUN));
dryRun.add(enabledIfEdit);
dryRunContainer.add(dryRun);
}
use of org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteSettings in project midpoint by Evolveum.
the class AutoCompleteQNamePanel method initLayout.
private void initLayout(final IModel<T> model) {
setOutputMarkupId(true);
AutoCompleteSettings autoCompleteSettings = createAutoCompleteSettings();
final IModel<String> stringModel = new Model<String>() {
@Override
public void setObject(String object) {
super.setObject(object);
model.setObject(convertToQname(object));
}
@Override
public String getObject() {
return (model.getObject() != null) ? model.getObject().getLocalPart() : null;
}
};
// The inner autocomplete field is always String. Non-string auto-complete fields are problematic
final AutoCompleteTextField<String> input = new AutoCompleteTextField<String>(ID_INPUT, stringModel, String.class, autoCompleteSettings) {
private static final long serialVersionUID = 1L;
@Override
protected Iterator<String> getChoices(String input) {
return getIterator(input);
}
};
input.add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
String inputString = stringModel.getObject();
if (StringUtils.isBlank(inputString)) {
T modelObject = model.getObject();
if (modelObject != null) {
model.setObject(null);
AutoCompleteQNamePanel.this.onChange(target);
}
} else {
T inputQName = convertToQname(stringModel.getObject());
if (inputQName == null) {
// We have some input, but it does not match any QName. Just do nothing.
} else {
T modelObject = model.getObject();
if (inputQName.equals(modelObject)) {
model.setObject(inputQName);
AutoCompleteQNamePanel.this.onChange(target);
}
}
}
}
});
add(input);
}
use of org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteSettings in project midpoint by Evolveum.
the class AbstractAutoCompletePanel method createAutoCompleteSettings.
protected AutoCompleteSettings createAutoCompleteSettings() {
AutoCompleteSettings autoCompleteSettings = new AutoCompleteSettings();
autoCompleteSettings.setShowListOnEmptyInput(true);
autoCompleteSettings.setShowListOnFocusGain(true);
autoCompleteSettings.setMaxHeightInPx(200);
autoCompleteSettings.setShowCompleteListOnFocusGain(true);
return autoCompleteSettings;
}
use of org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteSettings in project midpoint by Evolveum.
the class TextPopupPanel method initTextField.
private TextField initTextField() {
if (lookup == null) {
return new TextField(ID_TEXT_INPUT, new PropertyModel(getModel(), SearchValue.F_VALUE));
}
// TODO: displayName
// LookupPropertyModel<String> lookupPropertyModel = new LookupPropertyModel<String>(getModel(), SearchValue.F_VALUE, lookup.asObjectable()) {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public boolean isSupportsDisplayName() {
// return true;
// }
// };
AutoCompleteSettings settings = new AutoCompleteSettings();
settings.setShowListOnEmptyInput(true);
AutoCompleteTextField<String> textField = new AutoCompleteTextField<String>(ID_TEXT_INPUT, new PropertyModel<>(getModel(), SearchValue.F_VALUE), settings) {
private static final long serialVersionUID = 1L;
@Override
protected Iterator<String> getChoices(String input) {
return prepareAutoCompleteList(input).iterator();
}
@Override
public <C> IConverter<C> getConverter(Class<C> type) {
IConverter<C> converter = super.getConverter(type);
if (lookup == null) {
return converter;
}
return new LookupTableConverter(converter, lookup.asObjectable(), this, false) {
@Override
public Object convertToObject(String value, Locale locale) throws ConversionException {
PropertyModel<Object> label = new PropertyModel<>(TextPopupPanel.this.getModelObject(), SearchValue.F_LABEL);
label.setObject(value);
return super.convertToObject(value, locale);
}
};
}
};
return textField;
}
Aggregations