use of org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput 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 org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput 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);
}
use of org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput in project sirius-components by eclipse-sirius.
the class EditingContextEventProcessor method publishEvent.
private void publishEvent(ChangeDescription changeDescription) {
if (this.sink.currentSubscriberCount() > 0) {
IInput input = changeDescription.getInput();
UUID correlationId = input.getId();
if (input instanceof RenameRepresentationInput && ChangeKind.REPRESENTATION_RENAMING.equals(changeDescription.getKind())) {
String representationId = ((RenameRepresentationInput) input).getRepresentationId();
String newLabel = ((RenameRepresentationInput) input).getNewLabel();
this.tryEmitRepresentationRenamedEvent(correlationId, representationId, newLabel);
} else if (ChangeKind.REPRESENTATION_TO_RENAME.equals(changeDescription.getKind()) && !changeDescription.getParameters().isEmpty()) {
Map<String, Object> parameters = changeDescription.getParameters();
// @formatter:off
var optionalRepresentationId = Optional.ofNullable(parameters.get(REPRESENTATION_ID)).filter(String.class::isInstance).map(String.class::cast);
var optionalRepresentationLabel = Optional.ofNullable(parameters.get(REPRESENTATION_LABEL)).filter(String.class::isInstance).map(String.class::cast);
// @formatter:on
if (optionalRepresentationId.isPresent() && optionalRepresentationLabel.isPresent()) {
this.tryEmitRepresentationRenamedEvent(correlationId, optionalRepresentationId.get(), optionalRepresentationLabel.get());
}
}
}
}
Aggregations