use of org.eclipse.sirius.components.collaborative.dto.RenameRepresentationSuccessPayload in project sirius-components by eclipse-sirius.
the class RenameDiagramEventHandler method handle.
@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IDiagramContext diagramContext, IDiagramInput diagramInput) {
this.counter.increment();
String message = this.messageService.invalidInput(diagramInput.getClass().getSimpleName(), RenameDiagramInput.class.getSimpleName());
IPayload payload = new ErrorPayload(diagramInput.getId(), message);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, diagramInput.getRepresentationId(), diagramInput);
if (diagramInput instanceof RenameDiagramInput) {
RenameDiagramInput renameRepresentationInput = (RenameDiagramInput) diagramInput;
String representationId = renameRepresentationInput.getRepresentationId();
String newLabel = renameRepresentationInput.getNewLabel();
Optional<Diagram> optionalDiagram = this.representationSearchService.findById(editingContext, representationId, Diagram.class);
if (optionalDiagram.isPresent()) {
Diagram diagram = optionalDiagram.get();
Diagram renamedDiagram = Diagram.newDiagram(diagram).label(newLabel).build();
this.representationPersistenceService.save(editingContext, renamedDiagram);
diagramContext.update(renamedDiagram);
payload = new RenameRepresentationSuccessPayload(diagramInput.getId(), renamedDiagram);
changeDescription = new ChangeDescription(ChangeKind.REPRESENTATION_RENAMING, renameRepresentationInput.getRepresentationId(), diagramInput);
}
}
payloadSink.tryEmitValue(payload);
changeDescriptionSink.tryEmitNext(changeDescription);
}
Aggregations