Search in sources :

Example 1 with IFormInput

use of org.eclipse.sirius.components.collaborative.forms.api.IFormInput in project sirius-components by eclipse-sirius.

the class DeleteListItemEventHandler 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(), DeleteListItemInput.class.getSimpleName());
    IPayload payload = new ErrorPayload(formInput.getId(), message);
    ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, formInput.getRepresentationId(), formInput);
    if (formInput instanceof DeleteListItemInput) {
        DeleteListItemInput input = (DeleteListItemInput) formInput;
        // @formatter:off
        var optionalListItem = this.formQueryService.findWidget(form, input.getListId()).filter(List.class::isInstance).map(List.class::cast).stream().map(List::getItems).flatMap(Collection::stream).filter(item -> item.getId().toString().equals(input.getListItemId())).findFirst();
        var status = optionalListItem.map(ListItem::getDeleteHandler).map(handler -> handler.get()).orElse(// $NON-NLS-1$
        new Failure(""));
        if (status instanceof Success) {
            Success success = (Success) status;
            changeDescription = new ChangeDescription(success.getChangeKind(), formInput.getRepresentationId(), formInput, success.getParameters());
            payload = new DeleteListItemSuccessPayload(formInput.getId());
        } else if (status instanceof Failure) {
            payload = new ErrorPayload(formInput.getId(), ((Failure) status).getMessage());
        }
    }
    changeDescriptionSink.tryEmitNext(changeDescription);
    payloadSink.tryEmitValue(payload);
}
Also used : DeleteListItemInput(org.eclipse.sirius.components.collaborative.forms.dto.DeleteListItemInput) 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) ListItem(org.eclipse.sirius.components.forms.ListItem) Collection(java.util.Collection) Success(org.eclipse.sirius.components.representations.Success) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) One(reactor.core.publisher.Sinks.One) List(org.eclipse.sirius.components.forms.List) Objects(java.util.Objects) IFormEventHandler(org.eclipse.sirius.components.collaborative.forms.api.IFormEventHandler) DeleteListItemSuccessPayload(org.eclipse.sirius.components.collaborative.forms.dto.DeleteListItemSuccessPayload) 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) 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) IFormInput(org.eclipse.sirius.components.collaborative.forms.api.IFormInput) Success(org.eclipse.sirius.components.representations.Success) DeleteListItemSuccessPayload(org.eclipse.sirius.components.collaborative.forms.dto.DeleteListItemSuccessPayload) IPayload(org.eclipse.sirius.components.core.api.IPayload) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) Collection(java.util.Collection) List(org.eclipse.sirius.components.forms.List) ListItem(org.eclipse.sirius.components.forms.ListItem) DeleteListItemInput(org.eclipse.sirius.components.collaborative.forms.dto.DeleteListItemInput) Failure(org.eclipse.sirius.components.representations.Failure)

Example 2 with IFormInput

use of org.eclipse.sirius.components.collaborative.forms.api.IFormInput in project sirius-components by eclipse-sirius.

the class EditCheckboxEventHandler 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(), EditCheckboxInput.class.getSimpleName());
    IPayload payload = new ErrorPayload(formInput.getId(), message);
    ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, formInput.getRepresentationId(), formInput);
    if (formInput instanceof EditCheckboxInput) {
        EditCheckboxInput input = (EditCheckboxInput) formInput;
        // @formatter:off
        var optionalCheckbox = this.formQueryService.findWidget(form, input.getCheckboxId()).filter(Checkbox.class::isInstance).map(Checkbox.class::cast);
        IStatus status = optionalCheckbox.map(Checkbox::getNewValueHandler).map(handler -> handler.apply(input.getNewValue())).orElse(// $NON-NLS-1$
        new Failure(""));
        if (status instanceof Success) {
            payload = new EditCheckboxSuccessPayload(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) EditCheckboxSuccessPayload(org.eclipse.sirius.components.collaborative.forms.dto.EditCheckboxSuccessPayload) 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) Checkbox(org.eclipse.sirius.components.forms.Checkbox) 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) EditCheckboxInput(org.eclipse.sirius.components.collaborative.forms.dto.EditCheckboxInput) Many(reactor.core.publisher.Sinks.Many) IFormInput(org.eclipse.sirius.components.collaborative.forms.api.IFormInput) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) IStatus(org.eclipse.sirius.components.representations.IStatus) EditCheckboxSuccessPayload(org.eclipse.sirius.components.collaborative.forms.dto.EditCheckboxSuccessPayload) Checkbox(org.eclipse.sirius.components.forms.Checkbox) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) EditCheckboxInput(org.eclipse.sirius.components.collaborative.forms.dto.EditCheckboxInput) Failure(org.eclipse.sirius.components.representations.Failure) Success(org.eclipse.sirius.components.representations.Success) IPayload(org.eclipse.sirius.components.core.api.IPayload)

Example 3 with IFormInput

use of org.eclipse.sirius.components.collaborative.forms.api.IFormInput in project sirius-components by eclipse-sirius.

the class EditRadioEventHandler 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(), EditRadioInput.class.getSimpleName());
    IPayload payload = new ErrorPayload(formInput.getId(), message);
    ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, formInput.getRepresentationId(), formInput);
    if (formInput instanceof EditRadioInput) {
        EditRadioInput input = (EditRadioInput) formInput;
        // @formatter:off
        var optionalRadio = this.formQueryService.findWidget(form, input.getRadioId()).filter(Radio.class::isInstance).map(Radio.class::cast);
        IStatus status = optionalRadio.map(Radio::getNewValueHandler).map(handler -> handler.apply(input.getNewValue())).orElse(// $NON-NLS-1$
        new Failure(""));
        if (status instanceof Success) {
            payload = new EditRadioSuccessPayload(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 : EditRadioInput(org.eclipse.sirius.components.collaborative.forms.dto.EditRadioInput) 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) Objects(java.util.Objects) IFormEventHandler(org.eclipse.sirius.components.collaborative.forms.api.IFormEventHandler) IFormQueryService(org.eclipse.sirius.components.collaborative.forms.api.IFormQueryService) EditRadioSuccessPayload(org.eclipse.sirius.components.collaborative.forms.dto.EditRadioSuccessPayload) 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) Radio(org.eclipse.sirius.components.forms.Radio) Many(reactor.core.publisher.Sinks.Many) IFormInput(org.eclipse.sirius.components.collaborative.forms.api.IFormInput) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) IStatus(org.eclipse.sirius.components.representations.IStatus) EditRadioSuccessPayload(org.eclipse.sirius.components.collaborative.forms.dto.EditRadioSuccessPayload) EditRadioInput(org.eclipse.sirius.components.collaborative.forms.dto.EditRadioInput) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) Radio(org.eclipse.sirius.components.forms.Radio) Failure(org.eclipse.sirius.components.representations.Failure) Success(org.eclipse.sirius.components.representations.Success) IPayload(org.eclipse.sirius.components.core.api.IPayload)

Example 4 with IFormInput

use of org.eclipse.sirius.components.collaborative.forms.api.IFormInput in project sirius-components by eclipse-sirius.

the class EditSelectEventHandler 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(), EditSelectInput.class.getSimpleName());
    IPayload payload = new ErrorPayload(formInput.getId(), message);
    ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, formInput.getRepresentationId(), formInput);
    if (formInput instanceof EditSelectInput) {
        EditSelectInput input = (EditSelectInput) formInput;
        // @formatter:off
        Optional<Select> optionalSelect = this.formQueryService.findWidget(form, input.getSelectId()).filter(Select.class::isInstance).map(Select.class::cast);
        IStatus status = optionalSelect.map(Select::getNewValueHandler).map(handler -> handler.apply(input.getNewValue())).orElse(// $NON-NLS-1$
        new Failure(""));
        if (status instanceof Success) {
            payload = new EditSelectSuccessPayload(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) EditSelectSuccessPayload(org.eclipse.sirius.components.collaborative.forms.dto.EditSelectSuccessPayload) Failure(org.eclipse.sirius.components.representations.Failure) Success(org.eclipse.sirius.components.representations.Success) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) Select(org.eclipse.sirius.components.forms.Select) One(reactor.core.publisher.Sinks.One) 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) EditSelectInput(org.eclipse.sirius.components.collaborative.forms.dto.EditSelectInput) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) IStatus(org.eclipse.sirius.components.representations.IStatus) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) Select(org.eclipse.sirius.components.forms.Select) EditSelectSuccessPayload(org.eclipse.sirius.components.collaborative.forms.dto.EditSelectSuccessPayload) Failure(org.eclipse.sirius.components.representations.Failure) Success(org.eclipse.sirius.components.representations.Success) EditSelectInput(org.eclipse.sirius.components.collaborative.forms.dto.EditSelectInput) IPayload(org.eclipse.sirius.components.core.api.IPayload)

Example 5 with IFormInput

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

Aggregations

Objects (java.util.Objects)7 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)7 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)7 IFormEventHandler (org.eclipse.sirius.components.collaborative.forms.api.IFormEventHandler)7 IFormInput (org.eclipse.sirius.components.collaborative.forms.api.IFormInput)7 IPayload (org.eclipse.sirius.components.core.api.IPayload)7 Form (org.eclipse.sirius.components.forms.Form)7 Many (reactor.core.publisher.Sinks.Many)7 One (reactor.core.publisher.Sinks.One)7 Counter (io.micrometer.core.instrument.Counter)6 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)6 Monitoring (org.eclipse.sirius.components.collaborative.api.Monitoring)6 IFormQueryService (org.eclipse.sirius.components.collaborative.forms.api.IFormQueryService)6 ICollaborativeFormMessageService (org.eclipse.sirius.components.collaborative.forms.messages.ICollaborativeFormMessageService)6 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)6 Failure (org.eclipse.sirius.components.representations.Failure)6 Success (org.eclipse.sirius.components.representations.Success)5 Service (org.springframework.stereotype.Service)5 IStatus (org.eclipse.sirius.components.representations.IStatus)4 Optional (java.util.Optional)3