use of org.apache.wicket.markup.html.form.IChoiceRenderer in project midpoint by Evolveum.
the class WebComponentUtil method createTriStateCombo.
public static DropDownChoice<Boolean> createTriStateCombo(String id, IModel<Boolean> model) {
final IChoiceRenderer<Boolean> renderer = new IChoiceRenderer<Boolean>() {
@Override
public Boolean getObject(String id, IModel<? extends List<? extends Boolean>> choices) {
return id != null ? choices.getObject().get(Integer.parseInt(id)) : null;
}
@Override
public String getDisplayValue(Boolean object) {
String key;
if (object == null) {
key = KEY_BOOLEAN_NULL;
} else {
key = object ? KEY_BOOLEAN_TRUE : KEY_BOOLEAN_FALSE;
}
StringResourceModel model = PageBase.createStringResourceStatic(null, key);
return model.getString();
}
@Override
public String getIdValue(Boolean object, int index) {
return Integer.toString(index);
}
};
DropDownChoice<Boolean> dropDown = new DropDownChoice<Boolean>(id, model, createChoices(), renderer) {
@Override
protected CharSequence getDefaultChoice(String selectedValue) {
StringResourceModel model = PageBase.createStringResourceStatic(null, KEY_BOOLEAN_NULL);
return model.getString();
}
};
dropDown.setNullValid(true);
return dropDown;
}
use of org.apache.wicket.markup.html.form.IChoiceRenderer in project midpoint by Evolveum.
the class SynchronizationActionEditorDialog method initLayout.
private void initLayout(WebMarkupContainer content) {
Form form = new MidpointForm(ID_MAIN_FORM);
form.setOutputMarkupId(true);
content.add(form);
TextFormGroup name = new TextFormGroup(ID_NAME, new PropertyModel<>(model, SynchronizationActionTypeDto.F_ACTION_OBJECT + ".name"), createStringResource("SynchronizationActionEditorDialog.label.name"), ID_LABEL_SIZE, ID_INPUT_SIZE, false);
form.add(name);
TextAreaFormGroup description = new TextAreaFormGroup(ID_DESCRIPTION, new PropertyModel<>(model, SynchronizationActionTypeDto.F_ACTION_OBJECT + ".description"), createStringResource("SynchronizationActionEditorDialog.label.description"), ID_LABEL_SIZE, ID_INPUT_SIZE, false);
form.add(description);
DropDownFormGroup<SynchronizationActionTypeDto.HandlerUriActions> handlerUri = new DropDownFormGroup<SynchronizationActionTypeDto.HandlerUriActions>(ID_HANDLER_URI, new PropertyModel<>(model, SynchronizationActionTypeDto.F_HANDLER_URI), WebComponentUtil.createReadonlyModelFromEnum(SynchronizationActionTypeDto.HandlerUriActions.class), new EnumChoiceRenderer<>(this), createStringResource("SynchronizationActionEditorDialog.label.handlerUri"), createStringResource("SynchronizationStep.action.tooltip.handlerUri", WebComponentUtil.getMidpointCustomSystemName((PageResourceWizard) getPage(), "midpoint.default.system.name")), ID_LABEL_SIZE, ID_INPUT_SIZE, false, false) {
@Override
protected DropDownChoice createDropDown(String id, IModel<List<SynchronizationActionTypeDto.HandlerUriActions>> choices, IChoiceRenderer<SynchronizationActionTypeDto.HandlerUriActions> renderer, boolean required) {
DropDownChoice choice = new DropDownChoice<>(id, getModel(), choices, renderer);
choice.setNullValid(true);
return choice;
}
};
form.add(handlerUri);
DropDownFormGroup<BeforeAfterType> order = new DropDownFormGroup<BeforeAfterType>(ID_ORDER, new PropertyModel<>(model, SynchronizationActionTypeDto.F_ACTION_OBJECT + ".order"), WebComponentUtil.createReadonlyModelFromEnum(BeforeAfterType.class), new EnumChoiceRenderer<>(this), createStringResource("SynchronizationActionEditorDialog.label.order"), createStringResource("SynchronizationStep.action.tooltip.order", WebComponentUtil.getMidpointCustomSystemName((PageResourceWizard) getPage(), "midpoint.default.system.name")), ID_LABEL_SIZE, ID_INPUT_SIZE, false, false) {
@Override
protected DropDownChoice createDropDown(String id, IModel<List<BeforeAfterType>> choices, IChoiceRenderer<BeforeAfterType> renderer, boolean required) {
DropDownChoice choice = new DropDownChoice<>(id, getModel(), choices, renderer);
choice.setNullValid(true);
return choice;
}
};
form.add(order);
initButtons(form);
}
use of org.apache.wicket.markup.html.form.IChoiceRenderer in project midpoint by Evolveum.
the class SwitchablePropertyValuePanel method getValueField.
private <T> Component getValueField(String id) {
Component searchItemField = null;
ItemDefinition propertyDef = getPropertyItemDefinition();
if (propertyDef != null) {
PrismObject<LookupTableType> lookupTable = WebComponentUtil.findLookupTable(propertyDef, getPageBase());
if (propertyDef instanceof PrismReferenceDefinition) {
searchItemField = new ReferenceValueSearchPanel(id, new PropertyModel<>(getModel(), "value.value"), (PrismReferenceDefinition) propertyDef) {
private static final long serialVersionUID = 1L;
@Override
protected void referenceValueUpdated(ObjectReferenceType ort, AjaxRequestTarget target) {
SwitchablePropertyValuePanel.this.getModelObject().getValue().setValue(ort);
}
};
} else if (propertyDef instanceof PrismPropertyDefinition) {
List<DisplayableValue> allowedValues = new ArrayList<>();
if (((PrismPropertyDefinition) propertyDef).getAllowedValues() != null) {
allowedValues.addAll(((PrismPropertyDefinition) propertyDef).getAllowedValues());
} else if (propertyDef.getTypeClass().equals(boolean.class) || Boolean.class.isAssignableFrom(propertyDef.getTypeClass())) {
allowedValues.add(new SearchValue<>(Boolean.TRUE, getString("Boolean.TRUE")));
allowedValues.add(new SearchValue<>(Boolean.FALSE, getString("Boolean.FALSE")));
}
if (lookupTable != null) {
searchItemField = new AutoCompleteTextPanel<String>(id, new PropertyModel<>(getModel(), "value." + ValueSearchFilterItem.F_VALUE), String.class, true, lookupTable.asObjectable()) {
private static final long serialVersionUID = 1L;
@Override
public Iterator<String> getIterator(String input) {
return WebComponentUtil.prepareAutoCompleteList(lookupTable.asObjectable(), input, ((PageBase) getPage()).getLocalizationService()).iterator();
}
};
} else if (CollectionUtils.isNotEmpty(allowedValues)) {
List<T> allowedValuesList = new ArrayList<>();
allowedValues.forEach(val -> allowedValuesList.add((T) val.getValue()));
searchItemField = new DropDownChoicePanel<T>(id, new PropertyModel<>(getModel(), "value." + ValueSearchFilterItem.F_VALUE), Model.ofList(allowedValuesList), new IChoiceRenderer<T>() {
private static final long serialVersionUID = 1L;
@Override
public Object getDisplayValue(T val) {
if (val instanceof DisplayableValue) {
return ((DisplayableValue) val).getLabel();
}
return val;
}
@Override
public String getIdValue(T val, int index) {
return Integer.toString(index);
}
@Override
public T getObject(String id, IModel<? extends List<? extends T>> choices) {
return StringUtils.isNotBlank(id) ? choices.getObject().get(Integer.parseInt(id)) : null;
}
}, true);
} else {
searchItemField = new TextPanel<String>(id, new PropertyModel<>(getModel(), "value." + ValueSearchFilterItem.F_VALUE));
}
}
}
if (searchItemField instanceof InputPanel) {
((InputPanel) searchItemField).getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
}
return searchItemField != null ? searchItemField : new WebMarkupContainer(id);
}
use of org.apache.wicket.markup.html.form.IChoiceRenderer in project midpoint by Evolveum.
the class NameStep method createConnectorDropDown.
private DropDownFormGroup<PrismObject<ConnectorType>> createConnectorDropDown() {
return new DropDownFormGroup<PrismObject<ConnectorType>>(ID_CONNECTOR, selectedConnectorModel, relevantConnectorsModel, new IChoiceRenderer<PrismObject<ConnectorType>>() {
@Override
public PrismObject<ConnectorType> getObject(String id, IModel<? extends List<? extends PrismObject<ConnectorType>>> choices) {
return StringUtils.isNotBlank(id) ? choices.getObject().get(Integer.parseInt(id)) : null;
}
@Override
public Object getDisplayValue(PrismObject<ConnectorType> object) {
return WebComponentUtil.getName(object);
}
@Override
public String getIdValue(PrismObject<ConnectorType> object, int index) {
if (index < 0) {
// noinspection unchecked
List<PrismObject<ConnectorType>> connectors = (List<PrismObject<ConnectorType>>) getConnectorDropDown().getInput().getChoices();
for (PrismObject<ConnectorType> connector : connectors) {
if (connector.getOid().equals(selectedConnectorModel.getObject().getOid())) {
return Integer.toString(connectors.indexOf(connector));
}
}
}
return Integer.toString(index);
}
}, createStringResource("NameStep.connectorType"), "col-md-3", "col-md-6", true) {
@Override
protected DropDownChoice<PrismObject<ConnectorType>> createDropDown(String id, IModel<List<PrismObject<ConnectorType>>> choices, IChoiceRenderer<PrismObject<ConnectorType>> renderer, boolean required) {
DropDownChoice<PrismObject<ConnectorType>> choice = super.createDropDown(id, choices, renderer, required);
choice.add(new AjaxFormComponentUpdatingBehavior("change") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(getConnectorDropDown().getAdditionalInfoComponent());
}
});
choice.setOutputMarkupId(true);
return choice;
}
@Override
protected Component createAdditionalInfoComponent(String id) {
Label l = new Label(id, schemaChangeWarningModel);
l.add(new AttributeAppender("class", "text-danger"));
l.setOutputMarkupId(true);
return l;
}
};
}
use of org.apache.wicket.markup.html.form.IChoiceRenderer in project midpoint by Evolveum.
the class NameStep method createHostDropDown.
@NotNull
private DropDownFormGroup<PrismObject<ConnectorHostType>> createHostDropDown() {
return new DropDownFormGroup<PrismObject<ConnectorHostType>>(ID_CONNECTOR_HOST, selectedHostModel, allHostsModel, new IChoiceRenderer<PrismObject<ConnectorHostType>>() {
@Override
public PrismObject<ConnectorHostType> getObject(String id, IModel<? extends List<? extends PrismObject<ConnectorHostType>>> choices) {
if (StringUtils.isBlank(id)) {
return null;
}
return choices.getObject().get(Integer.parseInt(id));
}
@Override
public Object getDisplayValue(PrismObject<ConnectorHostType> object) {
if (object == null) {
return NameStep.this.getString("NameStep.hostNotUsed");
}
return ConnectorHostTypeComparator.getUserFriendlyName(object);
}
@Override
public String getIdValue(PrismObject<ConnectorHostType> object, int index) {
return Integer.toString(index);
}
}, createStringResource("NameStep.connectorHost"), "col-md-3", "col-md-6", false) {
@Override
protected DropDownChoice<PrismObject<ConnectorHostType>> createDropDown(String id, IModel<List<PrismObject<ConnectorHostType>>> choices, IChoiceRenderer<PrismObject<ConnectorHostType>> renderer, boolean required) {
DropDownChoice<PrismObject<ConnectorHostType>> choice = super.createDropDown(id, choices, renderer, required);
choice.add(new AjaxFormComponentUpdatingBehavior("change") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
discoverConnectorsPerformed(target);
}
});
return choice;
}
};
}
Aggregations