Search in sources :

Example 1 with Form

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

the class FormEventProcessor method refreshForm.

private Form refreshForm() {
    VariableManager variableManager = new VariableManager();
    variableManager.put(VariableManager.SELF, this.formCreationParameters.getObjects());
    variableManager.put(GetOrCreateRandomIdProvider.PREVIOUS_REPRESENTATION_ID, this.formCreationParameters.getId());
    variableManager.put(IEditingContext.EDITING_CONTEXT, this.formCreationParameters.getEditingContext());
    FormComponentProps formComponentProps = new FormComponentProps(variableManager, this.formCreationParameters.getFormDescription());
    Element element = new Element(FormComponent.class, formComponentProps);
    Form form = new FormRenderer().render(element);
    // $NON-NLS-1$
    this.logger.trace("Form refreshed: {}", form.getId());
    return form;
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) Form(org.eclipse.sirius.components.forms.Form) Element(org.eclipse.sirius.components.representations.Element) FormRenderer(org.eclipse.sirius.components.forms.renderer.FormRenderer) FormComponentProps(org.eclipse.sirius.components.forms.components.FormComponentProps)

Example 2 with Form

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

the class FormEventProcessorFactory method createRepresentationEventProcessor.

@Override
public <T extends IRepresentationEventProcessor> Optional<T> createRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration, IEditingContext editingContext) {
    if (IFormEventProcessor.class.isAssignableFrom(representationEventProcessorClass) && configuration instanceof FormConfiguration) {
        FormConfiguration formConfiguration = (FormConfiguration) configuration;
        Optional<Form> optionalForm = this.representationSearchService.findById(editingContext, formConfiguration.getId(), Form.class);
        if (optionalForm.isPresent()) {
            Form form = optionalForm.get();
            // @formatter:off
            Optional<FormDescription> optionalFormDescription = this.representationDescriptionSearchService.findById(editingContext, form.getDescriptionId()).filter(FormDescription.class::isInstance).map(FormDescription.class::cast);
            // @formatter:on
            Optional<Object> optionalObject = this.objectService.getObject(editingContext, form.getTargetObjectId());
            if (optionalFormDescription.isPresent() && optionalObject.isPresent()) {
                FormDescription formDescription = optionalFormDescription.get();
                Object object = optionalObject.get();
                // @formatter:off
                FormCreationParameters formCreationParameters = FormCreationParameters.newFormCreationParameters(formConfiguration.getId()).editingContext(editingContext).formDescription(formDescription).objects(List.of(object)).build();
                // @formatter:on
                IRepresentationEventProcessor formEventProcessor = new FormEventProcessor(formCreationParameters, this.formEventHandlers, this.subscriptionManagerFactory.create(), this.widgetSubscriptionManagerFactory.create(), this.representationRefreshPolicyRegistry);
                // @formatter:off
                return Optional.of(formEventProcessor).filter(representationEventProcessorClass::isInstance).map(representationEventProcessorClass::cast);
            // @formatter:on
            }
        }
    }
    return Optional.empty();
}
Also used : IFormEventProcessor(org.eclipse.sirius.components.collaborative.forms.api.IFormEventProcessor) Form(org.eclipse.sirius.components.forms.Form) IFormEventProcessor(org.eclipse.sirius.components.collaborative.forms.api.IFormEventProcessor) FormCreationParameters(org.eclipse.sirius.components.collaborative.forms.api.FormCreationParameters) FormConfiguration(org.eclipse.sirius.components.collaborative.forms.api.FormConfiguration) FormDescription(org.eclipse.sirius.components.forms.description.FormDescription) IRepresentationEventProcessor(org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor)

Example 3 with Form

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

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

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

Aggregations

Form (org.eclipse.sirius.components.forms.Form)17 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)13 IPayload (org.eclipse.sirius.components.core.api.IPayload)13 IFormQueryService (org.eclipse.sirius.components.collaborative.forms.api.IFormQueryService)12 ICollaborativeFormMessageService (org.eclipse.sirius.components.collaborative.forms.messages.ICollaborativeFormMessageService)12 Success (org.eclipse.sirius.components.representations.Success)12 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)11 IStatus (org.eclipse.sirius.components.representations.IStatus)11 Many (reactor.core.publisher.Sinks.Many)11 One (reactor.core.publisher.Sinks.One)11 Optional (java.util.Optional)8 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)7 AbstractWidget (org.eclipse.sirius.components.forms.AbstractWidget)7 Group (org.eclipse.sirius.components.forms.Group)7 Test (org.junit.jupiter.api.Test)7 Counter (io.micrometer.core.instrument.Counter)6 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)6 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)6 List (java.util.List)6 Objects (java.util.Objects)6