Search in sources :

Example 1 with DiagnosticComponentProps

use of org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps 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 DiagnosticComponentProps

use of org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps in project sirius-components by eclipse-sirius.

the class LinkComponent method render.

@Override
public Element render() {
    VariableManager variableManager = this.props.getVariableManager();
    LinkDescription linkDescription = this.props.getLinkDescription();
    String id = linkDescription.getIdProvider().apply(variableManager);
    String label = linkDescription.getLabelProvider().apply(variableManager);
    String url = linkDescription.getUrlProvider().apply(variableManager);
    List<Element> children = List.of(new Element(DiagnosticComponent.class, new DiagnosticComponentProps(linkDescription, variableManager)));
    // @formatter:off
    LinkElementProps linkElementProps = LinkElementProps.newLinkElementProps(id).label(label).url(url).children(children).build();
    return new Element(LinkElementProps.TYPE, linkElementProps);
// @formatter:on
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) DiagnosticComponent(org.eclipse.sirius.components.forms.validation.DiagnosticComponent) LinkDescription(org.eclipse.sirius.components.forms.description.LinkDescription) Element(org.eclipse.sirius.components.representations.Element) LinkElementProps(org.eclipse.sirius.components.forms.elements.LinkElementProps) DiagnosticComponentProps(org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps)

Example 3 with DiagnosticComponentProps

use of org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps in project sirius-components by eclipse-sirius.

the class TextfieldComponent method render.

@Override
public Element render() {
    VariableManager variableManager = this.props.getVariableManager();
    TextfieldDescription textfieldDescription = this.props.getTextfieldDescription();
    String id = textfieldDescription.getIdProvider().apply(variableManager);
    String label = textfieldDescription.getLabelProvider().apply(variableManager);
    String value = textfieldDescription.getValueProvider().apply(variableManager);
    BiFunction<VariableManager, String, IStatus> genericHandler = textfieldDescription.getNewValueHandler();
    Function<String, IStatus> specializedHandler = newValue -> {
        return genericHandler.apply(variableManager, newValue);
    };
    List<Element> children = List.of(new Element(DiagnosticComponent.class, new DiagnosticComponentProps(textfieldDescription, variableManager)));
    // @formatter:off
    TextfieldElementProps textfieldElementProps = TextfieldElementProps.newTextfieldElementProps(id).label(label).value(value).newValueHandler(specializedHandler).children(children).build();
    return new Element(TextfieldElementProps.TYPE, textfieldElementProps);
// @formatter:on
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) Objects(java.util.Objects) List(java.util.List) IStatus(org.eclipse.sirius.components.representations.IStatus) DiagnosticComponentProps(org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps) TextfieldDescription(org.eclipse.sirius.components.forms.description.TextfieldDescription) BiFunction(java.util.function.BiFunction) VariableManager(org.eclipse.sirius.components.representations.VariableManager) TextfieldElementProps(org.eclipse.sirius.components.forms.elements.TextfieldElementProps) Function(java.util.function.Function) Element(org.eclipse.sirius.components.representations.Element) IComponent(org.eclipse.sirius.components.representations.IComponent) DiagnosticComponent(org.eclipse.sirius.components.forms.validation.DiagnosticComponent) DiagnosticComponent(org.eclipse.sirius.components.forms.validation.DiagnosticComponent) IStatus(org.eclipse.sirius.components.representations.IStatus) TextfieldElementProps(org.eclipse.sirius.components.forms.elements.TextfieldElementProps) Element(org.eclipse.sirius.components.representations.Element) DiagnosticComponentProps(org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps) TextfieldDescription(org.eclipse.sirius.components.forms.description.TextfieldDescription)

Example 4 with DiagnosticComponentProps

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

Example 5 with DiagnosticComponentProps

use of org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps 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

DiagnosticComponent (org.eclipse.sirius.components.forms.validation.DiagnosticComponent)8 DiagnosticComponentProps (org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps)8 Element (org.eclipse.sirius.components.representations.Element)8 VariableManager (org.eclipse.sirius.components.representations.VariableManager)8 IStatus (org.eclipse.sirius.components.representations.IStatus)7 List (java.util.List)6 Objects (java.util.Objects)6 Function (java.util.function.Function)6 IComponent (org.eclipse.sirius.components.representations.IComponent)6 ArrayList (java.util.ArrayList)4 BiFunction (java.util.function.BiFunction)3 SelectOption (org.eclipse.sirius.components.forms.SelectOption)2 ListItem (org.eclipse.sirius.components.forms.ListItem)1 RadioOption (org.eclipse.sirius.components.forms.RadioOption)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 MultiSelectDescription (org.eclipse.sirius.components.forms.description.MultiSelectDescription)1 RadioDescription (org.eclipse.sirius.components.forms.description.RadioDescription)1 SelectDescription (org.eclipse.sirius.components.forms.description.SelectDescription)1