From 30e5eaf79d3a481ddbb6eeba2979770ccbe87b7b Mon Sep 17 00:00:00 2001 From: Remi Schnekenburger Date: Fri, 4 Jan 2019 15:29:55 +0100 Subject: [PATCH] Issue #457: edition of messages with scrolled diagrams - fix the position of the request to get the new location in terms of absolute position and not relative to the screen top left position. Change-Id: Iaa1eef0224d5e7b62aa2bf2fed74c5ee12ddae2b Signed-off-by: Remi Schnekenburger --- ...stractSequenceGraphicalNodeEditPolicy.java | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/plugins/org.eclipse.papyrus.uml.diagram.sequence.runtime/src/org/eclipse/papyrus/uml/diagram/sequence/runtime/internal/edit/policies/AbstractSequenceGraphicalNodeEditPolicy.java b/plugins/org.eclipse.papyrus.uml.diagram.sequence.runtime/src/org/eclipse/papyrus/uml/diagram/sequence/runtime/internal/edit/policies/AbstractSequenceGraphicalNodeEditPolicy.java index 6ef4e11a..70539d79 100644 --- a/plugins/org.eclipse.papyrus.uml.diagram.sequence.runtime/src/org/eclipse/papyrus/uml/diagram/sequence/runtime/internal/edit/policies/AbstractSequenceGraphicalNodeEditPolicy.java +++ b/plugins/org.eclipse.papyrus.uml.diagram.sequence.runtime/src/org/eclipse/papyrus/uml/diagram/sequence/runtime/internal/edit/policies/AbstractSequenceGraphicalNodeEditPolicy.java @@ -38,6 +38,8 @@ import org.eclipse.draw2d.ConnectionLayer; import org.eclipse.draw2d.ConnectionRouter; +import org.eclipse.draw2d.Viewport; +import org.eclipse.draw2d.ViewportUtilities; import org.eclipse.draw2d.geometry.Point; import org.eclipse.emf.common.command.CommandWrapper; import org.eclipse.emf.ecore.EClass; @@ -474,13 +476,17 @@ protected Command getReconnectSourceCommand(ReconnectRequest request) { // This is known to exist because we're manipulating an existing message in the diagram MMessage message = getInteraction().getMessage(_message.get()).get(); - int y = request.getLocation().y(); + + Point location = request.getLocation(); + + fixScroll(location); + int y = location.y(); OptionalInt yPosition = OptionalInt.of(y); org.eclipse.emf.common.command.Command result = null; // Check for semantic re-ordering if we're not connecting to an execution - if (!getExecutionFinish(lifeline.get(), request.getLocation()).isPresent()) { + if (!getExecutionFinish(lifeline.get(), location).isPresent()) { // should ensure the execution start is nudged result = getNudgeObstacleCommand(request, message.getSend().get(), y); } @@ -562,7 +568,11 @@ protected Command getReconnectTargetCommand(ReconnectRequest request) { // This is known to exist because we're manipulating an existing message in the diagram MMessage message = getInteraction().getMessage(_message.get()).get(); - int y = request.getLocation().y(); + + Point location = request.getLocation(); + + fixScroll(location); + int y = location.y(); if (!isForce(request) && MessageUtil.isSynchronous(message.getElement().getMessageSort()) // Synchronous message that is not a self-message && message.getSender().isPresent() @@ -574,7 +584,7 @@ protected Command getReconnectTargetCommand(ReconnectRequest request) { org.eclipse.emf.common.command.Command result = null; // Check for semantic re-ordering if we're not connecting to an execution - if (!getExecutionStart(lifeline.get(), request.getLocation()).isPresent() + if (!getExecutionStart(lifeline.get(), location).isPresent() // Or if we're moving both ends and the other is not connecting to an execution && !(isForce(request) && message.getSender() .flatMap(sndr -> getExecutionFinish(sndr, getUpdatedSourceLocation(request))) @@ -624,6 +634,22 @@ protected Command getReconnectTargetCommand(ReconnectRequest request) { return wrap(result); } + private void fixScroll(Point location) { + Viewport enclosingViewport = ViewportUtilities.getRootViewport(getHostFigure()); + if (enclosingViewport != null) { + location.performTranslate(enclosingViewport.getHorizontalRangeModel().getValue(), + enclosingViewport.getVerticalRangeModel().getValue()); + } + } + + private void unfixScroll(Point location) { + Viewport enclosingViewport = ViewportUtilities.getRootViewport(getHostFigure()); + if (enclosingViewport != null) { + location.performTranslate(-enclosingViewport.getHorizontalRangeModel().getValue(), + -enclosingViewport.getVerticalRangeModel().getValue()); + } + } + protected boolean shouldCreateExecution() { return Activator.getDefault().getPreferences().isAutoCreateExecutionForSyncMessage(); }