Search in sources :

Example 11 with Form

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

the class EditTextfieldEventHandler method handle.

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, Form form, IFormInput formInput) {
    this.counter.increment();
    String message = this.messageService.invalidInput(formInput.getClass().getSimpleName(), EditTextfieldInput.class.getSimpleName());
    IPayload payload = new ErrorPayload(formInput.getId(), message);
    ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, formInput.getRepresentationId(), formInput);
    if (formInput instanceof EditTextfieldInput) {
        EditTextfieldInput input = (EditTextfieldInput) formInput;
        // @formatter:off
        IStatus status = this.formQueryService.findWidget(form, input.getTextfieldId()).map(widget -> {
            Function<String, IStatus> handlerFunction = null;
            if (widget instanceof Textfield) {
                handlerFunction = ((Textfield) widget).getNewValueHandler();
            } else if (widget instanceof Textarea) {
                handlerFunction = ((Textarea) widget).getNewValueHandler();
            }
            return handlerFunction;
        }).map(handler -> handler.apply(input.getNewValue())).orElse(// $NON-NLS-1$
        new Failure(""));
        if (status instanceof Success) {
            payload = new EditTextfieldSuccessPayload(formInput.getId());
            changeDescription = new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, formInput.getRepresentationId(), formInput);
        } else if (status instanceof Failure) {
            payload = new ErrorPayload(formInput.getId(), ((Failure) status).getMessage());
        }
    }
    changeDescriptionSink.tryEmitNext(changeDescription);
    payloadSink.tryEmitValue(payload);
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) Counter(io.micrometer.core.instrument.Counter) Form(org.eclipse.sirius.components.forms.Form) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) Failure(org.eclipse.sirius.components.representations.Failure) Success(org.eclipse.sirius.components.representations.Success) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) One(reactor.core.publisher.Sinks.One) Textarea(org.eclipse.sirius.components.forms.Textarea) Function(java.util.function.Function) EditTextfieldSuccessPayload(org.eclipse.sirius.components.collaborative.forms.dto.EditTextfieldSuccessPayload) Objects(java.util.Objects) IFormEventHandler(org.eclipse.sirius.components.collaborative.forms.api.IFormEventHandler) IFormQueryService(org.eclipse.sirius.components.collaborative.forms.api.IFormQueryService) ICollaborativeFormMessageService(org.eclipse.sirius.components.collaborative.forms.messages.ICollaborativeFormMessageService) IPayload(org.eclipse.sirius.components.core.api.IPayload) Textfield(org.eclipse.sirius.components.forms.Textfield) IStatus(org.eclipse.sirius.components.representations.IStatus) Monitoring(org.eclipse.sirius.components.collaborative.api.Monitoring) Service(org.springframework.stereotype.Service) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) EditTextfieldInput(org.eclipse.sirius.components.collaborative.forms.dto.EditTextfieldInput) Many(reactor.core.publisher.Sinks.Many) IFormInput(org.eclipse.sirius.components.collaborative.forms.api.IFormInput) IStatus(org.eclipse.sirius.components.representations.IStatus) Success(org.eclipse.sirius.components.representations.Success) IPayload(org.eclipse.sirius.components.core.api.IPayload) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) EditTextfieldInput(org.eclipse.sirius.components.collaborative.forms.dto.EditTextfieldInput) Textarea(org.eclipse.sirius.components.forms.Textarea) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) Textfield(org.eclipse.sirius.components.forms.Textfield) Failure(org.eclipse.sirius.components.representations.Failure) EditTextfieldSuccessPayload(org.eclipse.sirius.components.collaborative.forms.dto.EditTextfieldSuccessPayload)

Example 12 with Form

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

the class FormEventProcessor method refresh.

@Override
public void refresh(ChangeDescription changeDescription) {
    if (this.shouldRefresh(changeDescription)) {
        Form form = this.refreshForm();
        this.currentForm.set(form);
        if (this.sink.currentSubscriberCount() > 0) {
            EmitResult emitResult = this.sink.tryEmitNext(new FormRefreshedEventPayload(changeDescription.getInput().getId(), form));
            if (emitResult.isFailure()) {
                // $NON-NLS-1$
                String pattern = "An error has occurred while emitting a FormRefreshedEventPayload: {}";
                this.logger.warn(pattern, emitResult);
            }
        }
    }
}
Also used : Form(org.eclipse.sirius.components.forms.Form) FormRefreshedEventPayload(org.eclipse.sirius.components.collaborative.forms.dto.FormRefreshedEventPayload) EmitResult(reactor.core.publisher.Sinks.EmitResult)

Example 13 with Form

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

the class CreateFormEventHandler method handle.

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IInput input) {
    this.counter.increment();
    String message = this.messageService.invalidInput(input.getClass().getSimpleName(), CreateRepresentationInput.class.getSimpleName());
    IPayload payload = new ErrorPayload(input.getId(), message);
    ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input);
    if (input instanceof CreateRepresentationInput) {
        CreateRepresentationInput createRepresentationInput = (CreateRepresentationInput) input;
        Optional<IRepresentationDescription> optionalRepresentationDescription = this.representationDescriptionSearchService.findById(editingContext, createRepresentationInput.getRepresentationDescriptionId());
        Optional<Object> optionalObject = this.objectService.getObject(editingContext, createRepresentationInput.getObjectId());
        if (optionalRepresentationDescription.isPresent() && optionalObject.isPresent()) {
            IRepresentationDescription representationDescription = optionalRepresentationDescription.get();
            String targetObjectId = this.objectService.getId(optionalObject.get());
            if (representationDescription instanceof FormDescription) {
                // @formatter:off
                Form form = Form.newForm(UUID.randomUUID().toString()).label(createRepresentationInput.getRepresentationName()).targetObjectId(targetObjectId).descriptionId(representationDescription.getId()).pages(// We don't store form pages, it will be re-render by the FormProcessor.
                List.of()).build();
                // @formatter:on
                this.representationPersistenceService.save(editingContext, form);
                payload = new CreateRepresentationSuccessPayload(input.getId(), form);
                changeDescription = new ChangeDescription(ChangeKind.REPRESENTATION_CREATION, editingContext.getId(), input);
            }
        }
    }
    payloadSink.tryEmitValue(payload);
    changeDescriptionSink.tryEmitNext(changeDescription);
}
Also used : CreateRepresentationInput(org.eclipse.sirius.components.collaborative.dto.CreateRepresentationInput) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) Form(org.eclipse.sirius.components.forms.Form) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) CreateRepresentationSuccessPayload(org.eclipse.sirius.components.collaborative.dto.CreateRepresentationSuccessPayload) FormDescription(org.eclipse.sirius.components.forms.description.FormDescription) IRepresentationDescription(org.eclipse.sirius.components.representations.IRepresentationDescription) IPayload(org.eclipse.sirius.components.core.api.IPayload)

Example 14 with Form

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

the class EditMultiSelectEventHandler method handle.

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, Form form, IFormInput formInput) {
    this.counter.increment();
    String message = this.messageService.invalidInput(formInput.getClass().getSimpleName(), EditMultiSelectInput.class.getSimpleName());
    IPayload payload = new ErrorPayload(formInput.getId(), message);
    ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, formInput.getRepresentationId(), formInput);
    if (formInput instanceof EditMultiSelectInput) {
        EditMultiSelectInput input = (EditMultiSelectInput) formInput;
        // @formatter:off
        Optional<MultiSelect> optionalMultiSelect = this.formQueryService.findWidget(form, input.getSelectId()).filter(MultiSelect.class::isInstance).map(MultiSelect.class::cast);
        IStatus status = optionalMultiSelect.map(MultiSelect::getNewValuesHandler).map(handler -> handler.apply(input.getNewValues())).orElse(// $NON-NLS-1$
        new Failure(""));
        if (status instanceof Success) {
            payload = new EditMultiSelectSuccessPayload(formInput.getId());
            changeDescription = new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, formInput.getRepresentationId(), formInput);
        } else if (status instanceof Failure) {
            payload = new ErrorPayload(formInput.getId(), ((Failure) status).getMessage());
        }
    }
    changeDescriptionSink.tryEmitNext(changeDescription);
    payloadSink.tryEmitValue(payload);
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) Counter(io.micrometer.core.instrument.Counter) Form(org.eclipse.sirius.components.forms.Form) 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) Failure(org.eclipse.sirius.components.representations.Failure) Success(org.eclipse.sirius.components.representations.Success) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) One(reactor.core.publisher.Sinks.One) MultiSelect(org.eclipse.sirius.components.forms.MultiSelect) Objects(java.util.Objects) IFormEventHandler(org.eclipse.sirius.components.collaborative.forms.api.IFormEventHandler) IFormQueryService(org.eclipse.sirius.components.collaborative.forms.api.IFormQueryService) ICollaborativeFormMessageService(org.eclipse.sirius.components.collaborative.forms.messages.ICollaborativeFormMessageService) IPayload(org.eclipse.sirius.components.core.api.IPayload) IStatus(org.eclipse.sirius.components.representations.IStatus) Monitoring(org.eclipse.sirius.components.collaborative.api.Monitoring) Service(org.springframework.stereotype.Service) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Many(reactor.core.publisher.Sinks.Many) Optional(java.util.Optional) IFormInput(org.eclipse.sirius.components.collaborative.forms.api.IFormInput) MultiSelect(org.eclipse.sirius.components.forms.MultiSelect) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) IStatus(org.eclipse.sirius.components.representations.IStatus) EditMultiSelectInput(org.eclipse.sirius.components.collaborative.forms.dto.EditMultiSelectInput) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) EditMultiSelectSuccessPayload(org.eclipse.sirius.components.collaborative.forms.dto.EditMultiSelectSuccessPayload) Failure(org.eclipse.sirius.components.representations.Failure) Success(org.eclipse.sirius.components.representations.Success) IPayload(org.eclipse.sirius.components.core.api.IPayload)

Example 15 with Form

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

the class FormRendererTests method checkResult.

private void checkResult(FormDescription description) {
    // test SiriusViewExtensionDescriptionConverter
    assertThat(description).isNotNull();
    assertThat(description.getGroupDescriptions()).hasSize(1);
    assertThat(description.getPageDescriptions()).hasSize(1);
    assertThat(description.getPageDescriptions().get(0).getGroupDescriptions()).hasSize(1);
    assertThat(description.getPageDescriptions()).hasSize(1);
    assertThat(description.getPageDescriptions().get(0).getGroupDescriptions().get(0)).isEqualTo(description.getGroupDescriptions().get(0));
    assertThat(description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream())).hasSize(6);
    assertThat(description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream()).filter(CheckboxDescription.class::isInstance)).hasSize(1);
    assertThat(description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream()).filter(RadioDescription.class::isInstance)).hasSize(1);
    assertThat(description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream()).filter(SelectDescription.class::isInstance)).hasSize(1);
    assertThat(description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream()).filter(TextfieldDescription.class::isInstance)).hasSize(1);
    assertThat(description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream()).filter(TextfieldDescription.class::isInstance)).hasSize(1);
    Optional<ForDescription> forOptional = description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream()).filter(ForDescription.class::isInstance).map(ForDescription.class::cast).findFirst();
    assertThat(forOptional).isNotEmpty();
    assertThat(forOptional.get().getIfDescriptions()).hasSize(1);
    assertThat(forOptional.get().getIfDescriptions().stream().findFirst().get().getWidgetDescription()).isNotNull();
    // Test FormRenderer
    VariableManager variableManager = new VariableManager();
    variableManager.put(VariableManager.SELF, List.of(EcorePackage.eINSTANCE));
    FormRenderer formRenderer = new FormRenderer();
    FormComponentProps props = new FormComponentProps(variableManager, description);
    Element element = new Element(FormComponent.class, props);
    Form form = formRenderer.render(element);
    assertThat(form.getPages()).hasSize(1);
    assertThat(form.getPages().stream().flatMap(p -> p.getGroups().stream())).hasSize(1);
    assertThat(form.getPages().stream().flatMap(p -> p.getGroups().stream()).flatMap(g -> g.getWidgets().stream())).hasSize(5);
    List<Group> groups = form.getPages().stream().flatMap(p -> p.getGroups().stream()).collect(Collectors.toList());
    this.checkIdsInGroups(groups);
}
Also used : Form(org.eclipse.sirius.components.forms.Form) EcorePackage(org.eclipse.emf.ecore.EcorePackage) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) Category(org.eclipse.sirius.properties.Category) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FormRenderer(org.eclipse.sirius.components.forms.renderer.FormRenderer) AbstractWidget(org.eclipse.sirius.components.forms.AbstractWidget) ViewExtensionDescription(org.eclipse.sirius.properties.ViewExtensionDescription) FormDescription(org.eclipse.sirius.components.forms.description.FormDescription) FormComponent(org.eclipse.sirius.components.forms.components.FormComponent) TextfieldDescription(org.eclipse.sirius.components.forms.description.TextfieldDescription) ModelOperationHandlerSwitch(org.eclipse.sirius.components.emf.compatibility.modeloperations.ModelOperationHandlerSwitch) ISemanticCandidatesProviderFactory(org.eclipse.sirius.components.compatibility.api.ISemanticCandidatesProviderFactory) ForDescription(org.eclipse.sirius.components.forms.description.ForDescription) CheckboxDescription(org.eclipse.sirius.components.forms.description.CheckboxDescription) PropertiesFactory(org.eclipse.sirius.properties.PropertiesFactory) SemanticCandidatesProvider(org.eclipse.sirius.components.emf.compatibility.SemanticCandidatesProvider) ViewExtensionDescriptionConverter(org.eclipse.sirius.components.compatibility.forms.ViewExtensionDescriptionConverter) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) SelectDescription(org.eclipse.sirius.components.forms.description.SelectDescription) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) Element(org.eclipse.sirius.components.representations.Element) IRepresentationMetadataSearchService(org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService) Test(org.junit.jupiter.api.Test) List(java.util.List) Group(org.eclipse.sirius.components.forms.Group) FormComponentProps(org.eclipse.sirius.components.forms.components.FormComponentProps) Optional(java.util.Optional) RadioDescription(org.eclipse.sirius.components.forms.description.RadioDescription) VariableManager(org.eclipse.sirius.components.representations.VariableManager) IdentifiedElementLabelProvider(org.eclipse.sirius.components.compatibility.services.representations.IdentifiedElementLabelProvider) AQLInterpreterFactory(org.eclipse.sirius.components.emf.compatibility.AQLInterpreterFactory) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) CheckboxDescription(org.eclipse.sirius.components.forms.description.CheckboxDescription) VariableManager(org.eclipse.sirius.components.representations.VariableManager) Group(org.eclipse.sirius.components.forms.Group) RadioDescription(org.eclipse.sirius.components.forms.description.RadioDescription) Form(org.eclipse.sirius.components.forms.Form) Element(org.eclipse.sirius.components.representations.Element) FormRenderer(org.eclipse.sirius.components.forms.renderer.FormRenderer) SelectDescription(org.eclipse.sirius.components.forms.description.SelectDescription) TextfieldDescription(org.eclipse.sirius.components.forms.description.TextfieldDescription) FormComponentProps(org.eclipse.sirius.components.forms.components.FormComponentProps) ForDescription(org.eclipse.sirius.components.forms.description.ForDescription)

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