use of org.eclipse.sirius.components.forms.elements.SelectElementProps in project sirius-components by eclipse-sirius.
the class SelectComponent method render.
@Override
public Element render() {
VariableManager variableManager = this.props.getVariableManager();
SelectDescription selectDescription = this.props.getSelectDescription();
String id = selectDescription.getIdProvider().apply(variableManager);
String label = selectDescription.getLabelProvider().apply(variableManager);
List<?> optionCandidates = selectDescription.getOptionsProvider().apply(variableManager);
String value = selectDescription.getValueProvider().apply(variableManager);
List<Element> children = List.of(new Element(DiagnosticComponent.class, new DiagnosticComponentProps(selectDescription, variableManager)));
List<SelectOption> options = new ArrayList<>(optionCandidates.size());
for (Object candidate : optionCandidates) {
VariableManager optionVariableManager = variableManager.createChild();
optionVariableManager.put(CANDIDATE_VARIABLE, candidate);
String optionId = selectDescription.getOptionIdProvider().apply(optionVariableManager);
String optionLabel = selectDescription.getOptionLabelProvider().apply(optionVariableManager);
// @formatter:off
SelectOption option = SelectOption.newSelectOption(optionId).label(optionLabel).build();
// @formatter:on
options.add(option);
}
Function<String, IStatus> specializedHandler = newValue -> {
return selectDescription.getNewValueHandler().apply(variableManager, newValue);
};
// @formatter:off
SelectElementProps selectElementProps = SelectElementProps.newSelectElementProps(id).label(label).options(options).value(value).newValueHandler(specializedHandler).children(children).build();
return new Element(SelectElementProps.TYPE, selectElementProps);
// @formatter:on
}
Aggregations