Search in sources :

Example 1 with AbstractWidget

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

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

the class EditTextfieldEventHandlerTests method testTextfieldEdition.

@Test
public void testTextfieldEdition() {
    // $NON-NLS-1$
    String id = "Textfield id";
    // $NON-NLS-1$
    var input = new EditTextfieldInput(UUID.randomUUID(), UUID.randomUUID().toString(), FORM_ID, id, "New value");
    AtomicBoolean hasBeenExecuted = new AtomicBoolean();
    Function<String, IStatus> newValueHandler = newValue -> {
        hasBeenExecuted.set(true);
        return new Success();
    };
    // @formatter:off
    Textfield textfield = Textfield.newTextfield(id).label(// $NON-NLS-1$
    "label").value(// $NON-NLS-1$
    "Previous value").newValueHandler(newValueHandler).diagnostics(List.of()).build();
    Group group = // $NON-NLS-1$
    Group.newGroup("groupId").label(// $NON-NLS-1$
    "group label").widgets(List.of(textfield)).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(textfield);
        }
    };
    EditTextfieldEventHandler handler = new EditTextfieldEventHandler(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(EditTextfieldSuccessPayload.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) 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) Textfield(org.eclipse.sirius.components.forms.Textfield) IStatus(org.eclipse.sirius.components.representations.IStatus) EditTextfieldInput(org.eclipse.sirius.components.collaborative.forms.dto.EditTextfieldInput) Page(org.eclipse.sirius.components.forms.Page) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) Success(org.eclipse.sirius.components.representations.Success) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) UUID(java.util.UUID) EditTextfieldSuccessPayload(org.eclipse.sirius.components.collaborative.forms.dto.EditTextfieldSuccessPayload) 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) IPayload(org.eclipse.sirius.components.core.api.IPayload) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EditTextfieldInput(org.eclipse.sirius.components.collaborative.forms.dto.EditTextfieldInput) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) Textfield(org.eclipse.sirius.components.forms.Textfield) AbstractWidget(org.eclipse.sirius.components.forms.AbstractWidget) Test(org.junit.jupiter.api.Test)

Example 3 with AbstractWidget

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

the class DeleteListItemEventHandlerTests method testListItemDeletion.

@Test
public void testListItemDeletion() {
    // $NON-NLS-1$
    String listId = "List id";
    // $NON-NLS-1$
    String listItemId = "element id to delete";
    // $NON-NLS-1$
    String changeKind = "delete something";
    // $NON-NLS-1$
    String changeDescriptionParameterKey = "change_description_parameter_key";
    Map<String, Object> parameters = new HashMap<>();
    parameters.put(changeDescriptionParameterKey, listItemId);
    var input = new DeleteListItemInput(UUID.randomUUID(), FORM_ID.toString(), UUID.randomUUID().toString(), listId, listItemId);
    AtomicBoolean hasBeenExecuted = new AtomicBoolean();
    Supplier<IStatus> deleteHandler = () -> {
        hasBeenExecuted.set(true);
        return new Success(changeKind, parameters);
    };
    // @formatter:off
    ListItem listItem = ListItem.newListItem(listItemId).deletable(true).deleteHandler(deleteHandler).imageURL(// $NON-NLS-1$
    "").kind(// $NON-NLS-1$
    "Diagram").label(// $NON-NLS-1$
    "empty representation").build();
    List list = List.newList(listId).diagnostics(Collections.emptyList()).items(Collections.singletonList(listItem)).label(// $NON-NLS-1$
    "").build();
    Group group = // $NON-NLS-1$
    Group.newGroup("groupId").label(// $NON-NLS-1$
    "group label").widgets(Collections.singletonList(list)).build();
    Page page = // $NON-NLS-1$
    Page.newPage("pageId").label(// $NON-NLS-1$
    "page label").groups(Collections.singletonList(group)).build();
    Form form = Form.newForm(FORM_ID.toString()).targetObjectId(// $NON-NLS-1$
    "targetObjectId").descriptionId(UUID.randomUUID()).label(// $NON-NLS-1$
    "form label").pages(Collections.singletonList(page)).build();
    // @formatter:on
    IFormQueryService formQueryService = new IFormQueryService.NoOp() {

        @Override
        public Optional<AbstractWidget> findWidget(Form form, String widgetId) {
            return Optional.of(list);
        }
    };
    DeleteListItemEventHandler handler = new DeleteListItemEventHandler(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);
    Map<String, Object> changeDescriptionParameters = changeDescription.getParameters();
    assertThat(changeDescriptionParameters.get(changeDescriptionParameterKey)).isEqualTo(listItemId);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(DeleteListItemSuccessPayload.class);
    assertThat(hasBeenExecuted.get()).isTrue();
}
Also used : Group(org.eclipse.sirius.components.forms.Group) IStatus(org.eclipse.sirius.components.representations.IStatus) ICollaborativeFormMessageService(org.eclipse.sirius.components.collaborative.forms.messages.ICollaborativeFormMessageService) HashMap(java.util.HashMap) Form(org.eclipse.sirius.components.forms.Form) IFormQueryService(org.eclipse.sirius.components.collaborative.forms.api.IFormQueryService) Page(org.eclipse.sirius.components.forms.Page) Success(org.eclipse.sirius.components.representations.Success) IPayload(org.eclipse.sirius.components.core.api.IPayload) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) List(org.eclipse.sirius.components.forms.List) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AbstractWidget(org.eclipse.sirius.components.forms.AbstractWidget) ListItem(org.eclipse.sirius.components.forms.ListItem) DeleteListItemInput(org.eclipse.sirius.components.collaborative.forms.dto.DeleteListItemInput) Test(org.junit.jupiter.api.Test)

Example 4 with AbstractWidget

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

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

the class FormRendererTests method checkIdsInGroups.

/**
 * Checks that inside a group all widget id are different.
 *
 * @param groups
 *            The list of groups
 */
private void checkIdsInGroups(List<Group> groups) {
    for (Group group : groups) {
        List<AbstractWidget> widgets = group.getWidgets();
        for (int i = 0; i < widgets.size(); i++) {
            AbstractWidget abstractWidget = widgets.get(i);
            // $NON-NLS-1$
            assertThat(abstractWidget.getId()).endsWith("#" + i);
        }
    }
}
Also used : Group(org.eclipse.sirius.components.forms.Group) AbstractWidget(org.eclipse.sirius.components.forms.AbstractWidget)

Aggregations

AbstractWidget (org.eclipse.sirius.components.forms.AbstractWidget)9 Group (org.eclipse.sirius.components.forms.Group)7 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)6 IFormQueryService (org.eclipse.sirius.components.collaborative.forms.api.IFormQueryService)6 ICollaborativeFormMessageService (org.eclipse.sirius.components.collaborative.forms.messages.ICollaborativeFormMessageService)6 IPayload (org.eclipse.sirius.components.core.api.IPayload)6 Form (org.eclipse.sirius.components.forms.Form)6 Page (org.eclipse.sirius.components.forms.Page)6 IStatus (org.eclipse.sirius.components.representations.IStatus)6 Success (org.eclipse.sirius.components.representations.Success)6 Test (org.junit.jupiter.api.Test)6 List (java.util.List)5 Optional (java.util.Optional)5 UUID (java.util.UUID)5 Function (java.util.function.Function)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)5 Sinks (reactor.core.publisher.Sinks)5