Search in sources :

Example 1 with RadioElementProps

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
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) Element(org.eclipse.sirius.components.representations.Element) IComponent(org.eclipse.sirius.components.representations.IComponent) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) RadioElementProps(org.eclipse.sirius.components.forms.elements.RadioElementProps) IStatus(org.eclipse.sirius.components.representations.IStatus) DiagnosticComponentProps(org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps) RadioDescription(org.eclipse.sirius.components.forms.description.RadioDescription) VariableManager(org.eclipse.sirius.components.representations.VariableManager) RadioOption(org.eclipse.sirius.components.forms.RadioOption) DiagnosticComponent(org.eclipse.sirius.components.forms.validation.DiagnosticComponent) IStatus(org.eclipse.sirius.components.representations.IStatus) RadioDescription(org.eclipse.sirius.components.forms.description.RadioDescription) Element(org.eclipse.sirius.components.representations.Element) DiagnosticComponentProps(org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps) ArrayList(java.util.ArrayList) DiagnosticComponent(org.eclipse.sirius.components.forms.validation.DiagnosticComponent) RadioElementProps(org.eclipse.sirius.components.forms.elements.RadioElementProps) RadioOption(org.eclipse.sirius.components.forms.RadioOption)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Objects (java.util.Objects)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 RadioOption (org.eclipse.sirius.components.forms.RadioOption)1 RadioDescription (org.eclipse.sirius.components.forms.description.RadioDescription)1 RadioElementProps (org.eclipse.sirius.components.forms.elements.RadioElementProps)1 DiagnosticComponent (org.eclipse.sirius.components.forms.validation.DiagnosticComponent)1 DiagnosticComponentProps (org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps)1 Element (org.eclipse.sirius.components.representations.Element)1 IComponent (org.eclipse.sirius.components.representations.IComponent)1 IStatus (org.eclipse.sirius.components.representations.IStatus)1 VariableManager (org.eclipse.sirius.components.representations.VariableManager)1