Search in sources :

Example 1 with MultiSelectElementProps

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
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) SelectOption(org.eclipse.sirius.components.forms.SelectOption) Function(java.util.function.Function) MultiSelectElementProps(org.eclipse.sirius.components.forms.elements.MultiSelectElementProps) MultiSelectDescription(org.eclipse.sirius.components.forms.description.MultiSelectDescription) 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) 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) MultiSelectDescription(org.eclipse.sirius.components.forms.description.MultiSelectDescription) MultiSelectElementProps(org.eclipse.sirius.components.forms.elements.MultiSelectElementProps) DiagnosticComponent(org.eclipse.sirius.components.forms.validation.DiagnosticComponent) SelectOption(org.eclipse.sirius.components.forms.SelectOption) ArrayList(java.util.ArrayList) List(java.util.List)

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 MultiSelectDescription (org.eclipse.sirius.components.forms.description.MultiSelectDescription)1 MultiSelectElementProps (org.eclipse.sirius.components.forms.elements.MultiSelectElementProps)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