Search in sources :

Example 1 with EditCheckboxSuccessPayload

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

Aggregations

Counter (io.micrometer.core.instrument.Counter)1 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 Objects (java.util.Objects)1 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)1 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)1 Monitoring (org.eclipse.sirius.components.collaborative.api.Monitoring)1 IFormEventHandler (org.eclipse.sirius.components.collaborative.forms.api.IFormEventHandler)1 IFormInput (org.eclipse.sirius.components.collaborative.forms.api.IFormInput)1 IFormQueryService (org.eclipse.sirius.components.collaborative.forms.api.IFormQueryService)1 EditCheckboxInput (org.eclipse.sirius.components.collaborative.forms.dto.EditCheckboxInput)1 EditCheckboxSuccessPayload (org.eclipse.sirius.components.collaborative.forms.dto.EditCheckboxSuccessPayload)1 ICollaborativeFormMessageService (org.eclipse.sirius.components.collaborative.forms.messages.ICollaborativeFormMessageService)1 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)1 IPayload (org.eclipse.sirius.components.core.api.IPayload)1 Checkbox (org.eclipse.sirius.components.forms.Checkbox)1 Form (org.eclipse.sirius.components.forms.Form)1 Failure (org.eclipse.sirius.components.representations.Failure)1 IStatus (org.eclipse.sirius.components.representations.IStatus)1 Success (org.eclipse.sirius.components.representations.Success)1 Service (org.springframework.stereotype.Service)1