use of org.eclipse.sirius.components.collaborative.dto.DeleteRepresentationInput 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 org.eclipse.sirius.components.collaborative.dto.DeleteRepresentationInput in project sirius-web by eclipse-sirius.
the class DeleteRepresentationEventHandler 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(), DeleteRepresentationInput.class.getSimpleName());
IPayload payload = new ErrorPayload(input.getId(), message);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input);
if (input instanceof DeleteRepresentationInput) {
DeleteRepresentationInput deleteRepresentationInput = (DeleteRepresentationInput) input;
var representationId = new IDParser().parse(deleteRepresentationInput.getRepresentationId());
if (representationId.isPresent() && this.representationService.existsById(representationId.get())) {
this.representationService.delete(representationId.get());
payload = new DeleteRepresentationSuccessPayload(input.getId(), deleteRepresentationInput.getRepresentationId());
changeDescription = new ChangeDescription(ChangeKind.REPRESENTATION_DELETION, editingContext.getId(), input);
}
}
payloadSink.tryEmitValue(payload);
changeDescriptionSink.tryEmitNext(changeDescription);
}
use of org.eclipse.sirius.components.collaborative.dto.DeleteRepresentationInput in project sirius-components by eclipse-sirius.
the class EditingContextEventProcessor method setupChangeDescriptionSinkConsumer.
@SuppressWarnings("checkstyle:IllegalCatch")
private Disposable setupChangeDescriptionSinkConsumer() {
Consumer<ChangeDescription> consumer = changeDescription -> {
if (ChangeKind.REPRESENTATION_TO_DELETE.equals(changeDescription.getKind())) {
Object representationId = changeDescription.getParameters().get(REPRESENTATION_ID);
if (representationId instanceof String) {
DeleteRepresentationInput deleteRepresentationInput = new DeleteRepresentationInput(UUID.randomUUID(), (String) representationId);
this.doHandle(Sinks.one(), deleteRepresentationInput);
}
} else if (ChangeKind.REPRESENTATION_TO_RENAME.equals(changeDescription.getKind())) {
Object representationId = changeDescription.getParameters().get(REPRESENTATION_ID);
Object representationLabel = changeDescription.getParameters().get(REPRESENTATION_LABEL);
if (representationId instanceof String && representationLabel instanceof String) {
RenameRepresentationInput renameRepresentationInput = new RenameRepresentationInput(UUID.randomUUID(), this.getEditingContextId(), (String) representationId, (String) representationLabel);
this.doHandle(Sinks.one(), renameRepresentationInput);
}
}
this.publishEvent(changeDescription);
this.disposeRepresentationIfNeeded();
RepresentationEventProcessorEntry representationEventProcessorEntry = this.representationEventProcessors.get(changeDescription.getSourceId());
if (representationEventProcessorEntry != null) {
try {
IRepresentationEventProcessor representationEventProcessor = representationEventProcessorEntry.getRepresentationEventProcessor();
representationEventProcessor.refresh(changeDescription);
IRepresentation representation = representationEventProcessor.getRepresentation();
this.applicationEventPublisher.publishEvent(new RepresentationRefreshedEvent(this.editingContext.getId(), representation));
} catch (Exception exception) {
this.logger.warn(exception.getMessage(), exception);
}
}
this.refreshOtherRepresentations(changeDescription);
if (this.shouldPersistTheEditingContext(changeDescription)) {
this.editingContextPersistenceService.persist(this.editingContext);
}
this.danglingRepresentationDeletionService.deleteDanglingRepresentations(this.editingContext.getId());
};
Consumer<Throwable> errorConsumer = throwable -> this.logger.warn(throwable.getMessage(), throwable);
return this.changeDescriptionSink.asFlux().subscribe(consumer, errorConsumer);
}
Aggregations