Search in sources :

Example 1 with UpdateNodeBoundsSuccessPayload

use of org.eclipse.sirius.components.collaborative.diagrams.dto.UpdateNodeBoundsSuccessPayload in project sirius-components by eclipse-sirius.

the class UpdateNodeBoundsEventHandler method handleUpdateNodeBounds.

private void handleUpdateNodeBounds(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IDiagramContext diagramContext, UpdateNodeBoundsInput diagramInput) {
    // @formatter:off
    Position newPosition = Position.newPosition().x(diagramInput.getNewPositionX()).y(diagramInput.getNewPositionY()).build();
    Size newSize = Size.newSize().width(diagramInput.getNewWidth()).height(diagramInput.getNewHeight()).build();
    // @formatter:on
    Optional<Node> optionalNode = this.diagramQueryService.findNodeById(diagramContext.getDiagram(), diagramInput.getDiagramElementId());
    if (optionalNode.isPresent()) {
        Position oldPosition = optionalNode.get().getPosition();
        // @formatter:off
        Position delta = Position.newPosition().x(oldPosition.getX() - newPosition.getX()).y(oldPosition.getY() - newPosition.getY()).build();
        // @formatter:on
        diagramContext.setDiagramEvent(new ResizeEvent(diagramInput.getDiagramElementId(), delta, newSize));
        payloadSink.tryEmitValue(new UpdateNodeBoundsSuccessPayload(diagramInput.getId(), diagramContext.getDiagram()));
        changeDescriptionSink.tryEmitNext(new ChangeDescription(DiagramChangeKind.DIAGRAM_LAYOUT_CHANGE, diagramInput.getRepresentationId(), diagramInput));
    } else {
        String message = this.messageService.nodeNotFound(String.valueOf(diagramInput.getDiagramElementId()));
        payloadSink.tryEmitValue(new ErrorPayload(diagramInput.getId(), message));
        changeDescriptionSink.tryEmitNext(new ChangeDescription(ChangeKind.NOTHING, diagramInput.getRepresentationId(), diagramInput));
    }
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) Position(org.eclipse.sirius.components.diagrams.Position) Size(org.eclipse.sirius.components.diagrams.Size) Node(org.eclipse.sirius.components.diagrams.Node) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) UpdateNodeBoundsSuccessPayload(org.eclipse.sirius.components.collaborative.diagrams.dto.UpdateNodeBoundsSuccessPayload) ResizeEvent(org.eclipse.sirius.components.diagrams.events.ResizeEvent)

Aggregations

ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)1 UpdateNodeBoundsSuccessPayload (org.eclipse.sirius.components.collaborative.diagrams.dto.UpdateNodeBoundsSuccessPayload)1 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)1 Node (org.eclipse.sirius.components.diagrams.Node)1 Position (org.eclipse.sirius.components.diagrams.Position)1 Size (org.eclipse.sirius.components.diagrams.Size)1 ResizeEvent (org.eclipse.sirius.components.diagrams.events.ResizeEvent)1