Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Barbin2014-09-18 07:59:16 +0000
committerFlorian Barbin2014-09-19 14:09:11 +0000
commit15ce2d42b50bc970ecd920dc23c4ba1cb5668763 (patch)
treededa3516f13f1a16c6c0aacb3ec1a353d71204b4
parent4a31000467d2ff567d077c56157093f185599bd0 (diff)
downloadorg.eclipse.sirius-15ce2d42b50bc970ecd920dc23c4ba1cb5668763.tar.gz
org.eclipse.sirius-15ce2d42b50bc970ecd920dc23c4ba1cb5668763.tar.xz
org.eclipse.sirius-15ce2d42b50bc970ecd920dc23c4ba1cb5668763.zip
[437528] Use Figure absolute bounds instead of GMF when possible.
* In the case where the edge EditPart is available, we now use the source and target draw2D absolute bounds instead of GMF. Because of the difference between the GMF absolute bounds computation and the draw2D absolute bounds, the edge centering behavior was wrong in the case of container within a container. * Create a new method to get the top level FreeformViewport to compute the diagram scroll size and not the first container one. * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=437528#c9 for more details. Bug: 437528 Change-Id: I34ce80800c069d0dbddb5d8dfe0882694ae4fcd0 Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/operation/CenterEdgeEndModelChangeOperation.java44
-rw-r--r--plugins/org.eclipse.sirius.ext.draw2d/src/org/eclipse/sirius/ext/draw2d/figure/FigureUtilities.java22
-rw-r--r--plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/editparts/GraphicalHelper.java2
3 files changed, 63 insertions, 5 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/operation/CenterEdgeEndModelChangeOperation.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/operation/CenterEdgeEndModelChangeOperation.java
index e163e6f0fc..9472b6a2c7 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/operation/CenterEdgeEndModelChangeOperation.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/operation/CenterEdgeEndModelChangeOperation.java
@@ -25,6 +25,7 @@ import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.PrecisionPoint;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.LayerConstants;
import org.eclipse.gef.editparts.LayerManager;
@@ -125,7 +126,6 @@ public class CenterEdgeEndModelChangeOperation extends AbstractModelChangeOperat
* the {@link CenteringStyle} value.
*/
private void centerEdgeEnds(CenteringStyle center) {
-
Bendpoints bendpoints = edge.getBendpoints();
if (bendpoints instanceof RelativeBendpoints) {
@@ -134,10 +134,12 @@ public class CenterEdgeEndModelChangeOperation extends AbstractModelChangeOperat
if (edgeSourceView instanceof Node && edgeTargetView instanceof Node) {
+ setConnectionIfNull();
+
// We get the edge source and target nodes absolute bounds to
// compute absolute anchors coordinates
- Option<Rectangle> sourceBounds = GMFHelper.getAbsoluteBounds(edgeSourceView);
- Option<Rectangle> targetBounds = GMFHelper.getAbsoluteBounds(edgeTargetView);
+ Option<Rectangle> sourceBounds = getAbsoluteSourceBounds(edgeSourceView);
+ Option<Rectangle> targetBounds = getAbsoluteTargetBounds(edgeTargetView);
if (sourceBounds.some() && targetBounds.some()) {
@@ -168,6 +170,41 @@ public class CenterEdgeEndModelChangeOperation extends AbstractModelChangeOperat
}
/**
+ * Because of the difference between the GMF absolute bounds computation and
+ * the draw2D absolute bounds, we will compute these bounds from draw2D if
+ * we have access to the figure, or from GMF if we work in "pure" GMF
+ * context.
+ *
+ * @param gmfView
+ * the GMFView to compute the absolute bounds.
+ * @param isSource
+ * true if it represents the edge source, false otherwise.
+ * @return the absolute bounds.
+ */
+ private Option<Rectangle> getAbsoluteBounds(View gmfView, boolean isSource) {
+ if (connectionEditPart != null) {
+ EditPart editPart = null;
+ if (isSource) {
+ editPart = connectionEditPart.getSource();
+ } else {
+ editPart = connectionEditPart.getTarget();
+ }
+ if (editPart instanceof GraphicalEditPart) {
+ return Options.newSome(GraphicalHelper.getAbsoluteBoundsIn100Percent((GraphicalEditPart) editPart));
+ }
+ }
+ return GMFHelper.getAbsoluteBounds(gmfView);
+ }
+
+ private Option<Rectangle> getAbsoluteSourceBounds(View edgeSourceView) {
+ return getAbsoluteBounds(edgeSourceView, true);
+ }
+
+ private Option<Rectangle> getAbsoluteTargetBounds(View edgeTargetView) {
+ return getAbsoluteBounds(edgeTargetView, false);
+ }
+
+ /**
* Deal with the straight edge case.
*
* @param center
@@ -487,7 +524,6 @@ public class CenterEdgeEndModelChangeOperation extends AbstractModelChangeOperat
}
private Option<PointList> getAbsolutePointListFromConnection() {
- setConnectionIfNull();
Option<PointList> pointList = Options.newNone();
if (connection != null) {
pointList = Options.newSome(connection.getPoints().getCopy());
diff --git a/plugins/org.eclipse.sirius.ext.draw2d/src/org/eclipse/sirius/ext/draw2d/figure/FigureUtilities.java b/plugins/org.eclipse.sirius.ext.draw2d/src/org/eclipse/sirius/ext/draw2d/figure/FigureUtilities.java
index d521e43c89..a370a989d6 100644
--- a/plugins/org.eclipse.sirius.ext.draw2d/src/org/eclipse/sirius/ext/draw2d/figure/FigureUtilities.java
+++ b/plugins/org.eclipse.sirius.ext.draw2d/src/org/eclipse/sirius/ext/draw2d/figure/FigureUtilities.java
@@ -148,4 +148,26 @@ public final class FigureUtilities {
}
return (FreeformViewport) current;
}
+
+ /**
+ * Returns the root {@link FreeformViewport} that owns this figure, if any.
+ * We call root {@link FreeformViewport} the last one we found when going to
+ * the top of the figure hierarchy.
+ *
+ * @param figure
+ * the figure.
+ * @return the {@link FreeformViewport} that owns this figure, or
+ * <code>null</code> if there is none.
+ */
+ public static FreeformViewport getRootFreeformViewport(IFigure figure) {
+ IFigure current = figure;
+ FreeformViewport rootFreeformViewport = null;
+ while (current != null) {
+ if (current instanceof FreeformViewport) {
+ rootFreeformViewport = (FreeformViewport) current;
+ }
+ current = current.getParent();
+ }
+ return rootFreeformViewport;
+ }
}
diff --git a/plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/editparts/GraphicalHelper.java b/plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/editparts/GraphicalHelper.java
index a8c9dcae47..0f59e64227 100644
--- a/plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/editparts/GraphicalHelper.java
+++ b/plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/editparts/GraphicalHelper.java
@@ -168,7 +168,7 @@ public final class GraphicalHelper {
*/
public static Point getScrollSize(GraphicalEditPart part) {
Preconditions.checkNotNull(part);
- FreeformViewport viewport = FigureUtilities.getFreeformViewport(part.getFigure());
+ FreeformViewport viewport = FigureUtilities.getRootFreeformViewport(part.getFigure());
if (viewport != null) {
return viewport.getViewLocation();
} else {

Back to the top