Search in sources :

Example 1 with SelectOption

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

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

the class EditSelectEventHandlerTests method testSelectEdition.

@Test
public void testSelectEdition() {
    // $NON-NLS-1$
    String id = "Select id";
    // $NON-NLS-1$
    var input = new EditSelectInput(UUID.randomUUID(), UUID.randomUUID().toString(), FORM_ID, id, "false");
    AtomicBoolean hasBeenExecuted = new AtomicBoolean();
    Function<String, IStatus> newValueHandler = newValue -> {
        hasBeenExecuted.set(true);
        return new Success();
    };
    // @formatter:off
    SelectOption trueOption = // $NON-NLS-1$
    SelectOption.newSelectOption("true").label(// $NON-NLS-1$
    "True").build();
    SelectOption falseOption = // $NON-NLS-1$
    SelectOption.newSelectOption("false").label(// $NON-NLS-1$
    "False").build();
    Select select = Select.newSelect(id).label(// $NON-NLS-1$
    "label").value(// $NON-NLS-1$
    "true").newValueHandler(newValueHandler).options(List.of(trueOption, falseOption)).diagnostics(List.of()).build();
    Group group = // $NON-NLS-1$
    Group.newGroup("groupId").label(// $NON-NLS-1$
    "group label").widgets(List.of(select)).build();
    Page page = // $NON-NLS-1$
    Page.newPage("pageId").label(// $NON-NLS-1$
    "page label").groups(List.of(group)).build();
    Form form = Form.newForm(FORM_ID).targetObjectId(// $NON-NLS-1$
    "targetObjectId").descriptionId(UUID.randomUUID()).label(// $NON-NLS-1$
    "form label").pages(List.of(page)).build();
    // @formatter:on
    IFormQueryService formQueryService = new IFormQueryService.NoOp() {

        @Override
        public Optional<AbstractWidget> findWidget(Form form, String widgetId) {
            return Optional.of(select);
        }
    };
    EditSelectEventHandler handler = new EditSelectEventHandler(formQueryService, new ICollaborativeFormMessageService.NoOp(), new SimpleMeterRegistry());
    assertThat(handler.canHandle(input)).isTrue();
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    One<IPayload> payloadSink = Sinks.one();
    handler.handle(payloadSink, changeDescriptionSink, form, input);
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(EditSelectSuccessPayload.class);
    assertThat(hasBeenExecuted.get()).isTrue();
}
Also used : Sinks(reactor.core.publisher.Sinks) Form(org.eclipse.sirius.components.forms.Form) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SelectOption(org.eclipse.sirius.components.forms.SelectOption) One(reactor.core.publisher.Sinks.One) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Function(java.util.function.Function) AbstractWidget(org.eclipse.sirius.components.forms.AbstractWidget) IFormQueryService(org.eclipse.sirius.components.collaborative.forms.api.IFormQueryService) IStatus(org.eclipse.sirius.components.representations.IStatus) Page(org.eclipse.sirius.components.forms.Page) EditSelectInput(org.eclipse.sirius.components.collaborative.forms.dto.EditSelectInput) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) EditSelectSuccessPayload(org.eclipse.sirius.components.collaborative.forms.dto.EditSelectSuccessPayload) Success(org.eclipse.sirius.components.representations.Success) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) Select(org.eclipse.sirius.components.forms.Select) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) List(java.util.List) ICollaborativeFormMessageService(org.eclipse.sirius.components.collaborative.forms.messages.ICollaborativeFormMessageService) IPayload(org.eclipse.sirius.components.core.api.IPayload) Group(org.eclipse.sirius.components.forms.Group) Many(reactor.core.publisher.Sinks.Many) Optional(java.util.Optional) Group(org.eclipse.sirius.components.forms.Group) IStatus(org.eclipse.sirius.components.representations.IStatus) ICollaborativeFormMessageService(org.eclipse.sirius.components.collaborative.forms.messages.ICollaborativeFormMessageService) Form(org.eclipse.sirius.components.forms.Form) IFormQueryService(org.eclipse.sirius.components.collaborative.forms.api.IFormQueryService) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Page(org.eclipse.sirius.components.forms.Page) Success(org.eclipse.sirius.components.representations.Success) EditSelectInput(org.eclipse.sirius.components.collaborative.forms.dto.EditSelectInput) IPayload(org.eclipse.sirius.components.core.api.IPayload) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SelectOption(org.eclipse.sirius.components.forms.SelectOption) Select(org.eclipse.sirius.components.forms.Select) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) AbstractWidget(org.eclipse.sirius.components.forms.AbstractWidget) Test(org.junit.jupiter.api.Test)

Example 3 with SelectOption

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

the class EditMultiSelectEventHandlerTests method testMultiSelectEdition.

@Test
public void testMultiSelectEdition() {
    // $NON-NLS-1$
    String id = "MultiSelect id";
    // $NON-NLS-1$ //$NON-NLS-2$
    var input = new EditMultiSelectInput(UUID.randomUUID(), UUID.randomUUID().toString(), FORM_ID, id, List.of("true", "false"));
    AtomicBoolean hasBeenExecuted = new AtomicBoolean();
    Function<List<String>, IStatus> newValuesHandler = newValues -> {
        hasBeenExecuted.set(true);
        return new Success();
    };
    // @formatter:off
    SelectOption trueOption = // $NON-NLS-1$
    SelectOption.newSelectOption("true").label(// $NON-NLS-1$
    "True").build();
    SelectOption falseOption = // $NON-NLS-1$
    SelectOption.newSelectOption("false").label(// $NON-NLS-1$
    "False").build();
    MultiSelect multiSelect = MultiSelect.newMultiSelect(id).label(// $NON-NLS-1$
    "label").values(List.of()).newValuesHandler(newValuesHandler).options(List.of(trueOption, falseOption)).diagnostics(List.of()).build();
    Group group = // $NON-NLS-1$
    Group.newGroup("groupId").label(// $NON-NLS-1$
    "group label").widgets(List.of(multiSelect)).build();
    Page page = // $NON-NLS-1$
    Page.newPage("pageId").label(// $NON-NLS-1$
    "page label").groups(List.of(group)).build();
    Form form = Form.newForm(FORM_ID).targetObjectId(// $NON-NLS-1$
    "targetObjectId").descriptionId(UUID.randomUUID()).label(// $NON-NLS-1$
    "form label").pages(List.of(page)).build();
    // @formatter:on
    IFormQueryService formQueryService = new IFormQueryService.NoOp() {

        @Override
        public Optional<AbstractWidget> findWidget(Form form, String widgetId) {
            return Optional.of(multiSelect);
        }
    };
    EditMultiSelectEventHandler handler = new EditMultiSelectEventHandler(formQueryService, new ICollaborativeFormMessageService.NoOp(), new SimpleMeterRegistry());
    assertThat(handler.canHandle(input)).isTrue();
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    One<IPayload> payloadSink = Sinks.one();
    handler.handle(payloadSink, changeDescriptionSink, form, input);
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(EditMultiSelectSuccessPayload.class);
    assertThat(hasBeenExecuted.get()).isTrue();
}
Also used : Sinks(reactor.core.publisher.Sinks) Form(org.eclipse.sirius.components.forms.Form) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SelectOption(org.eclipse.sirius.components.forms.SelectOption) One(reactor.core.publisher.Sinks.One) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Function(java.util.function.Function) AbstractWidget(org.eclipse.sirius.components.forms.AbstractWidget) IFormQueryService(org.eclipse.sirius.components.collaborative.forms.api.IFormQueryService) IStatus(org.eclipse.sirius.components.representations.IStatus) Page(org.eclipse.sirius.components.forms.Page) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) EditMultiSelectInput(org.eclipse.sirius.components.collaborative.forms.dto.EditMultiSelectInput) EditMultiSelectSuccessPayload(org.eclipse.sirius.components.collaborative.forms.dto.EditMultiSelectSuccessPayload) Success(org.eclipse.sirius.components.representations.Success) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) MultiSelect(org.eclipse.sirius.components.forms.MultiSelect) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) List(java.util.List) ICollaborativeFormMessageService(org.eclipse.sirius.components.collaborative.forms.messages.ICollaborativeFormMessageService) IPayload(org.eclipse.sirius.components.core.api.IPayload) Group(org.eclipse.sirius.components.forms.Group) Many(reactor.core.publisher.Sinks.Many) Optional(java.util.Optional) Group(org.eclipse.sirius.components.forms.Group) IStatus(org.eclipse.sirius.components.representations.IStatus) ICollaborativeFormMessageService(org.eclipse.sirius.components.collaborative.forms.messages.ICollaborativeFormMessageService) Form(org.eclipse.sirius.components.forms.Form) IFormQueryService(org.eclipse.sirius.components.collaborative.forms.api.IFormQueryService) EditMultiSelectInput(org.eclipse.sirius.components.collaborative.forms.dto.EditMultiSelectInput) Page(org.eclipse.sirius.components.forms.Page) Success(org.eclipse.sirius.components.representations.Success) IPayload(org.eclipse.sirius.components.core.api.IPayload) SelectOption(org.eclipse.sirius.components.forms.SelectOption) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) List(java.util.List) MultiSelect(org.eclipse.sirius.components.forms.MultiSelect) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AbstractWidget(org.eclipse.sirius.components.forms.AbstractWidget) Test(org.junit.jupiter.api.Test)

Example 4 with SelectOption

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

the class WidgetAssert method assertSelect.

private void assertSelect(Select actualSelect, Select select, IdPolicy idPolicy) {
    assertThat(actualSelect.getLabel()).isEqualTo(select.getLabel());
    assertThat(actualSelect.getOptions().size()).isEqualTo(select.getOptions().size());
    int size = actualSelect.getOptions().size();
    for (int i = 0; i < size; i++) {
        SelectOption actualSelectOption = actualSelect.getOptions().get(i);
        SelectOption selectOption = select.getOptions().get(i);
        assertThatObject(actualSelectOption).isNotNull();
        if (idPolicy == IdPolicy.WITH_ID) {
            assertThat(actualSelectOption.getId()).isEqualTo(selectOption.getId());
        }
        assertThat(actualSelectOption.getLabel()).isEqualTo(selectOption.getLabel());
    }
}
Also used : SelectOption(org.eclipse.sirius.components.forms.SelectOption)

Example 5 with SelectOption

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

SelectOption (org.eclipse.sirius.components.forms.SelectOption)5 List (java.util.List)4 Function (java.util.function.Function)4 IStatus (org.eclipse.sirius.components.representations.IStatus)4 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)2 ArrayList (java.util.ArrayList)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)2 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)2 IFormQueryService (org.eclipse.sirius.components.collaborative.forms.api.IFormQueryService)2 ICollaborativeFormMessageService (org.eclipse.sirius.components.collaborative.forms.messages.ICollaborativeFormMessageService)2 IPayload (org.eclipse.sirius.components.core.api.IPayload)2 AbstractWidget (org.eclipse.sirius.components.forms.AbstractWidget)2 Form (org.eclipse.sirius.components.forms.Form)2 Group (org.eclipse.sirius.components.forms.Group)2 Page (org.eclipse.sirius.components.forms.Page)2