Search in sources :

Example 1 with SelectElementProps

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
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) SelectDescription(org.eclipse.sirius.components.forms.description.SelectDescription) SelectOption(org.eclipse.sirius.components.forms.SelectOption) 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) IStatus(org.eclipse.sirius.components.representations.IStatus) SelectElementProps(org.eclipse.sirius.components.forms.elements.SelectElementProps) DiagnosticComponentProps(org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps) VariableManager(org.eclipse.sirius.components.representations.VariableManager) DiagnosticComponent(org.eclipse.sirius.components.forms.validation.DiagnosticComponent) IStatus(org.eclipse.sirius.components.representations.IStatus) Element(org.eclipse.sirius.components.representations.Element) DiagnosticComponentProps(org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps) ArrayList(java.util.ArrayList) SelectElementProps(org.eclipse.sirius.components.forms.elements.SelectElementProps) DiagnosticComponent(org.eclipse.sirius.components.forms.validation.DiagnosticComponent) SelectOption(org.eclipse.sirius.components.forms.SelectOption) SelectDescription(org.eclipse.sirius.components.forms.description.SelectDescription)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 SelectOption (org.eclipse.sirius.components.forms.SelectOption)1 SelectDescription (org.eclipse.sirius.components.forms.description.SelectDescription)1 SelectElementProps (org.eclipse.sirius.components.forms.elements.SelectElementProps)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