use of org.eclipse.sirius.components.forms.elements.RadioElementProps in project sirius-components by eclipse-sirius.
the class RadioComponent method render.
@Override
public Element render() {
VariableManager variableManager = this.props.getVariableManager();
RadioDescription radioDescription = this.props.getRadioDescription();
String id = radioDescription.getIdProvider().apply(variableManager);
String label = radioDescription.getLabelProvider().apply(variableManager);
List<?> optionCandidates = radioDescription.getOptionsProvider().apply(variableManager);
List<Element> children = List.of(new Element(DiagnosticComponent.class, new DiagnosticComponentProps(radioDescription, variableManager)));
List<RadioOption> options = new ArrayList<>(optionCandidates.size());
for (Object candidate : optionCandidates) {
VariableManager optionVariableManager = variableManager.createChild();
optionVariableManager.put(CANDIDATE_VARIABLE, candidate);
String optionId = radioDescription.getOptionIdProvider().apply(optionVariableManager);
String optionLabel = radioDescription.getOptionLabelProvider().apply(optionVariableManager);
Boolean optionSelected = radioDescription.getOptionSelectedProvider().apply(optionVariableManager);
// @formatter:off
RadioOption option = RadioOption.newRadioOption(optionId).label(optionLabel).selected(optionSelected).build();
// @formatter:on
options.add(option);
}
BiFunction<VariableManager, String, IStatus> genericHandler = radioDescription.getNewValueHandler();
Function<String, IStatus> specializedHandler = newValue -> {
return genericHandler.apply(variableManager, newValue);
};
// @formatter:off
RadioElementProps radioElementProps = RadioElementProps.newRadioElementProps(id).label(label).options(options).newValueHandler(specializedHandler).children(children).build();
return new Element(RadioElementProps.TYPE, radioElementProps);
// @formatter:on
}
Aggregations