Search in sources :

Example 1 with RenameRepresentationSuccessPayload

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);
}
Also used : RenameDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.dto.RenameDiagramInput) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) RenameRepresentationSuccessPayload(org.eclipse.sirius.components.collaborative.dto.RenameRepresentationSuccessPayload) IPayload(org.eclipse.sirius.components.core.api.IPayload) Diagram(org.eclipse.sirius.components.diagrams.Diagram)

Aggregations

ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)1 RenameDiagramInput (org.eclipse.sirius.components.collaborative.diagrams.dto.RenameDiagramInput)1 RenameRepresentationSuccessPayload (org.eclipse.sirius.components.collaborative.dto.RenameRepresentationSuccessPayload)1 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)1 IPayload (org.eclipse.sirius.components.core.api.IPayload)1 Diagram (org.eclipse.sirius.components.diagrams.Diagram)1