Search in sources :

Example 1 with MultiSelectDescription

use of org.eclipse.sirius.components.forms.description.MultiSelectDescription 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)

Example 2 with MultiSelectDescription

use of org.eclipse.sirius.components.forms.description.MultiSelectDescription in project sirius-components by eclipse-sirius.

the class WidgetComponent method render.

@Override
public Element render() {
    VariableManager variableManager = this.props.getVariableManager();
    AbstractWidgetDescription widgetDescription = this.props.getWidgetDescription();
    Element element = null;
    if (widgetDescription instanceof TextfieldDescription) {
        TextfieldComponentProps textfieldProps = new TextfieldComponentProps(variableManager, (TextfieldDescription) widgetDescription);
        element = new Element(TextfieldComponent.class, textfieldProps);
    } else if (widgetDescription instanceof TextareaDescription) {
        TextareaComponentProps textareaProps = new TextareaComponentProps(variableManager, (TextareaDescription) widgetDescription);
        element = new Element(TextareaComponent.class, textareaProps);
    } else if (widgetDescription instanceof CheckboxDescription) {
        CheckboxComponentProps checkboxProps = new CheckboxComponentProps(variableManager, (CheckboxDescription) widgetDescription);
        element = new Element(CheckboxComponent.class, checkboxProps);
    } else if (widgetDescription instanceof SelectDescription) {
        SelectComponentProps selectProps = new SelectComponentProps(variableManager, (SelectDescription) widgetDescription);
        element = new Element(SelectComponent.class, selectProps);
    } else if (widgetDescription instanceof MultiSelectDescription) {
        MultiSelectComponentProps multiSelectProps = new MultiSelectComponentProps(variableManager, (MultiSelectDescription) widgetDescription);
        element = new Element(MultiSelectComponent.class, multiSelectProps);
    } else if (widgetDescription instanceof RadioDescription) {
        RadioComponentProps radioProps = new RadioComponentProps(variableManager, (RadioDescription) widgetDescription);
        element = new Element(RadioComponent.class, radioProps);
    } else if (widgetDescription instanceof ListDescription) {
        ListComponentProps listProps = new ListComponentProps(variableManager, (ListDescription) widgetDescription);
        element = new Element(ListComponent.class, listProps);
    } else if (widgetDescription instanceof LinkDescription) {
        LinkComponentProps linkProps = new LinkComponentProps(variableManager, (LinkDescription) widgetDescription);
        element = new Element(LinkComponent.class, linkProps);
    } else {
        // $NON-NLS-1$
        String pattern = "Unsupported widget description: {}";
        this.logger.warn(pattern, widgetDescription.getClass().getSimpleName());
    }
    return element;
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) CheckboxDescription(org.eclipse.sirius.components.forms.description.CheckboxDescription) RadioDescription(org.eclipse.sirius.components.forms.description.RadioDescription) LinkDescription(org.eclipse.sirius.components.forms.description.LinkDescription) Element(org.eclipse.sirius.components.representations.Element) MultiSelectDescription(org.eclipse.sirius.components.forms.description.MultiSelectDescription) ListDescription(org.eclipse.sirius.components.forms.description.ListDescription) AbstractWidgetDescription(org.eclipse.sirius.components.forms.description.AbstractWidgetDescription) TextareaDescription(org.eclipse.sirius.components.forms.description.TextareaDescription) TextfieldDescription(org.eclipse.sirius.components.forms.description.TextfieldDescription) SelectDescription(org.eclipse.sirius.components.forms.description.SelectDescription) MultiSelectDescription(org.eclipse.sirius.components.forms.description.MultiSelectDescription)

Aggregations

MultiSelectDescription (org.eclipse.sirius.components.forms.description.MultiSelectDescription)2 Element (org.eclipse.sirius.components.representations.Element)2 VariableManager (org.eclipse.sirius.components.representations.VariableManager)2 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 AbstractWidgetDescription (org.eclipse.sirius.components.forms.description.AbstractWidgetDescription)1 CheckboxDescription (org.eclipse.sirius.components.forms.description.CheckboxDescription)1 LinkDescription (org.eclipse.sirius.components.forms.description.LinkDescription)1 ListDescription (org.eclipse.sirius.components.forms.description.ListDescription)1 RadioDescription (org.eclipse.sirius.components.forms.description.RadioDescription)1 SelectDescription (org.eclipse.sirius.components.forms.description.SelectDescription)1 TextareaDescription (org.eclipse.sirius.components.forms.description.TextareaDescription)1 TextfieldDescription (org.eclipse.sirius.components.forms.description.TextfieldDescription)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 IComponent (org.eclipse.sirius.components.representations.IComponent)1