use of org.eclipse.sirius.components.forms.elements.MultiSelectElementProps in project sirius-components by eclipse-sirius.
the class MultiSelectComponent method render.
@Override
public Element render() {
VariableManager variableManager = this.props.getVariableManager();
MultiSelectDescription multiSelectDescription = this.props.getMultiSelectDescription();
String id = multiSelectDescription.getIdProvider().apply(variableManager);
String label = multiSelectDescription.getLabelProvider().apply(variableManager);
List<?> optionCandidates = multiSelectDescription.getOptionsProvider().apply(variableManager);
List<String> values = multiSelectDescription.getValuesProvider().apply(variableManager);
List<Element> children = List.of(new Element(DiagnosticComponent.class, new DiagnosticComponentProps(multiSelectDescription, variableManager)));
List<SelectOption> options = new ArrayList<>(optionCandidates.size());
for (Object candidate : optionCandidates) {
VariableManager optionVariableManager = variableManager.createChild();
optionVariableManager.put(CANDIDATE_VARIABLE, candidate);
String optionId = multiSelectDescription.getOptionIdProvider().apply(optionVariableManager);
String optionLabel = multiSelectDescription.getOptionLabelProvider().apply(optionVariableManager);
// @formatter:off
SelectOption option = SelectOption.newSelectOption(optionId).label(optionLabel).build();
// @formatter:on
options.add(option);
}
Function<List<String>, IStatus> newValuesHandler = newValues -> {
return multiSelectDescription.getNewValuesHandler().apply(variableManager, newValues);
};
// @formatter:off
MultiSelectElementProps selectElementProps = MultiSelectElementProps.newMultiSelectElementProps(id).label(label).options(options).values(values).newValuesHandler(newValuesHandler).children(children).build();
return new Element(MultiSelectElementProps.TYPE, selectElementProps);
// @formatter:on
}
Aggregations