use of reactor.core.publisher.Sinks.One in project sirius-components by eclipse-sirius.
the class EditingContextEventProcessor method handleInput.
private void handleInput(One<IPayload> payloadSink, IInput input) {
if (input instanceof DeleteRepresentationInput) {
DeleteRepresentationInput deleteRepresentationInput = (DeleteRepresentationInput) input;
this.disposeRepresentation(deleteRepresentationInput.getRepresentationId());
}
// @formatter:off
Optional<IEditingContextEventHandler> optionalEditingContextEventHandler = this.editingContextEventHandlers.stream().filter(handler -> handler.canHandle(this.editingContext, input)).findFirst();
if (optionalEditingContextEventHandler.isPresent()) {
IEditingContextEventHandler editingContextEventHandler = optionalEditingContextEventHandler.get();
editingContextEventHandler.handle(payloadSink, this.changeDescriptionSink, this.editingContext, input);
} else {
// $NON-NLS-1$
this.logger.warn("No handler found for event: {}", input);
}
}
use of reactor.core.publisher.Sinks.One in project sirius-components by eclipse-sirius.
the class GetToolSectionsEventHandler method handle.
@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IDiagramContext diagramContext, IDiagramInput diagramInput) {
this.counter.increment();
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), diagramInput);
IPayload payload = null;
if (diagramInput instanceof GetToolSectionsInput) {
GetToolSectionsInput toolSectionsInput = (GetToolSectionsInput) diagramInput;
String diagramElementId = toolSectionsInput.getDiagramElementId();
Diagram diagram = diagramContext.getDiagram();
// @formatter:off
var optionalDiagramDescription = this.representationDescriptionSearchService.findById(editingContext, diagram.getDescriptionId()).filter(DiagramDescription.class::isInstance).map(DiagramDescription.class::cast);
// @formatter:on
if (optionalDiagramDescription.isPresent()) {
DiagramDescription diagramDescription = optionalDiagramDescription.get();
var optionalToolSectionsProvider = this.toolSectionsProviders.stream().filter(toolSectionProvider -> toolSectionProvider.canHandle(diagramDescription)).findFirst();
var optionalTargetElement = this.findTargetElement(diagram, diagramElementId, editingContext);
var optionalDiagramElement = this.findDiagramElement(diagram, diagramElementId);
var optionalDiagramElementDescription = this.findDiagramElementDescription(diagram, diagramElementId, diagramDescription, optionalDiagramElement.orElse(null));
if (optionalToolSectionsProvider.isPresent() && optionalTargetElement.isPresent() && optionalDiagramElementDescription.isPresent()) {
IToolSectionsProvider toolSectionsProvider = optionalToolSectionsProvider.get();
List<ToolSection> toolSections = toolSectionsProvider.handle(optionalTargetElement.get(), optionalDiagramElement.orElse(null), optionalDiagramElementDescription.get(), diagramDescription);
payload = new GetToolSectionSuccessPayload(diagramInput.getId(), toolSections);
}
} else {
String message = this.messageService.invalidInput(diagramInput.getClass().getSimpleName(), GetToolSectionsInput.class.getSimpleName());
payload = new ErrorPayload(diagramInput.getId(), message);
}
payloadSink.tryEmitValue(payload);
changeDescriptionSink.tryEmitNext(changeDescription);
}
}
use of reactor.core.publisher.Sinks.One in project sirius-components by eclipse-sirius.
the class DiagramEventProcessor method handle.
@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IRepresentationInput representationInput) {
IRepresentationInput effectiveInput = representationInput;
if (representationInput instanceof RenameRepresentationInput) {
RenameRepresentationInput renameRepresentationInput = (RenameRepresentationInput) representationInput;
effectiveInput = new RenameDiagramInput(renameRepresentationInput.getId(), renameRepresentationInput.getEditingContextId(), renameRepresentationInput.getRepresentationId(), renameRepresentationInput.getNewLabel());
}
if (effectiveInput instanceof IDiagramInput) {
IDiagramInput diagramInput = (IDiagramInput) effectiveInput;
Optional<IDiagramEventHandler> optionalDiagramEventHandler = this.diagramEventHandlers.stream().filter(handler -> handler.canHandle(diagramInput)).findFirst();
if (optionalDiagramEventHandler.isPresent()) {
IDiagramEventHandler diagramEventHandler = optionalDiagramEventHandler.get();
diagramEventHandler.handle(payloadSink, changeDescriptionSink, this.editingContext, this.diagramContext, diagramInput);
} else {
// $NON-NLS-1$
this.logger.warn("No handler found for event: {}", diagramInput);
}
}
}
use of reactor.core.publisher.Sinks.One 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();
}
use of reactor.core.publisher.Sinks.One 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();
}
Aggregations