Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Redor2020-10-29 08:01:06 +0000
committerLaurent Redor2020-11-06 08:42:19 +0000
commitfcc641e1e91063931e71327a2a2495413a863d32 (patch)
treee08ccfefdb7a6b8fa79915ef8e64e385eb2c44f9
parent6605f1b8521015624215049275c1499481c395fe (diff)
downloadorg.eclipse.sirius-fcc641e1e91063931e71327a2a2495413a863d32.tar.gz
org.eclipse.sirius-fcc641e1e91063931e71327a2a2495413a863d32.tar.xz
org.eclipse.sirius-fcc641e1e91063931e71327a2a2495413a863d32.zip
[568037] ELK - Change the absolute bounds computation
Previously, there are arrange problems when the diagram or the container contained scroll bar. The algorithm now relies on GraphicalHelper that is already used in Sirius. Bug: 568037 Change-Id: I455bdef6f507108d348ccf300bb20e5d0d18bf5c Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.elk/src/org/eclipse/sirius/diagram/elk/ElkDiagramLayoutConnector.java32
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/layout/SimpleELKLayoutTest.java4
2 files changed, 18 insertions, 18 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.elk/src/org/eclipse/sirius/diagram/elk/ElkDiagramLayoutConnector.java b/plugins/org.eclipse.sirius.diagram.elk/src/org/eclipse/sirius/diagram/elk/ElkDiagramLayoutConnector.java
index ccbc8bb341..0e97665ebb 100644
--- a/plugins/org.eclipse.sirius.diagram.elk/src/org/eclipse/sirius/diagram/elk/ElkDiagramLayoutConnector.java
+++ b/plugins/org.eclipse.sirius.diagram.elk/src/org/eclipse/sirius/diagram/elk/ElkDiagramLayoutConnector.java
@@ -133,6 +133,7 @@ import org.eclipse.sirius.diagram.ui.internal.edit.parts.SiriusTextEditPart;
import org.eclipse.sirius.diagram.ui.internal.operation.ResetOriginChangeModelOperation;
import org.eclipse.sirius.diagram.ui.internal.refresh.GMFHelper;
import org.eclipse.sirius.diagram.ui.tools.api.graphical.edit.styles.IBorderItemOffsets;
+import org.eclipse.sirius.ext.gmf.runtime.editparts.GraphicalHelper;
import org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures.AlphaDropShadowBorder;
import org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures.SiriusWrapLabel;
import org.eclipse.sirius.viewpoint.LabelAlignment;
@@ -521,11 +522,11 @@ public class ElkDiagramLayoutConnector implements IDiagramLayoutConnector {
// only one element (ie one parent). So we want to keep it at a fixed location. For that we use the bounds
// of the node to determine the size of the graph. We also set its identifier according to its only child.
// We can not use directly the node as the graph root (in case of it has bordered node) .
- Rectangle childAbsoluteBounds = getAbsoluteBounds(layoutRootPart.getFigure());
+ Rectangle childAbsoluteBounds = GraphicalHelper.getAbsoluteBoundsIn100Percent(layoutRootPart, true);
IGraphicalEditPart parentEditPart = getTopGraphicParentEditPartIfPresent(layoutRootPart);
if (parentEditPart != null && !(parentEditPart instanceof DiagramEditPart)) {
// Compute the parent location origin
- parentLocation = getAbsoluteBounds(parentEditPart.getFigure()).getTopLeft();
+ parentLocation = GraphicalHelper.getAbsoluteBoundsIn100Percent(parentEditPart).getTopLeft();
}
topNode.setLocation(0, 0);
topNode.setDimensions(childAbsoluteBounds.preciseX() + childAbsoluteBounds.preciseWidth(), childAbsoluteBounds.preciseY() + childAbsoluteBounds.preciseHeight());
@@ -541,7 +542,6 @@ public class ElkDiagramLayoutConnector implements IDiagramLayoutConnector {
// larger than the existing one. But it is not allowed to be reduced.
parentNode.setProperty(CoreOptions.NODE_SIZE_MINIMUM, new KVector(parentNode.getHeight(), parentNode.getWidth()));
} else {
- Rectangle rootBounds = layoutRootPart.getFigure().getBounds();
if (layoutRootPart == diagramEditPart) {
String labelText = diagramEditPart.getDiagramView().getName();
if (labelText.length() > 0) {
@@ -549,9 +549,9 @@ public class ElkDiagramLayoutConnector implements IDiagramLayoutConnector {
label.setText(labelText);
}
} else {
- topNode.setLocation(rootBounds.x, rootBounds.y);
+ topNode.setLocation(childAbsoluteBounds.x, childAbsoluteBounds.y);
}
- topNode.setDimensions(rootBounds.width, rootBounds.height);
+ topNode.setDimensions(childAbsoluteBounds.width, childAbsoluteBounds.height);
mapping.getGraphMap().put(topNode, layoutRootPart);
// Fix the size of the container. This option is ignored/unknown by ELK, we use it to store this
// information. It is used later, in transfertLayout, to ignore the layout of this container as we want
@@ -598,20 +598,20 @@ public class ElkDiagramLayoutConnector implements IDiagramLayoutConnector {
}
if (layoutRootPart instanceof ShapeNodeEditPart) {
+ Dimension topLeftInsets = GMFHelper.getContainerTopLeftInsetsAfterLabel((Node) layoutRootPart.getNotationView(), true);
if (selection.size() == 1 && selection.get(0).equals(layoutRootPart)) {
- mapping.setProperty(COORDINATE_OFFSET, new KVector(minx - parentLocation.x(), miny - parentLocation.y()));
- } else {
if (isArrangeAtOpening) {
- // Use the parent node bounds if the arrange selection concerns sub part of a container during
- // an arrange at opening
- mapping.setProperty(COORDINATE_OFFSET, new KVector(parentNode.getX() - parentLocation.x(), parentNode.getY() - parentLocation.y()));
+ mapping.setProperty(COORDINATE_OFFSET, new KVector(minx - parentLocation.x() + topLeftInsets.width, miny - parentLocation.y() + topLeftInsets.height));
} else {
- // Use the standard coordinates if the arrange selection concerns sub part of a container (with
- // the insets added)
- Dimension topLeftInsets = GMFHelper.getContainerTopLeftInsetsAfterLabel((Node) layoutRootPart.getNotationView(), true);
- // Add the insets
- mapping.setProperty(COORDINATE_OFFSET, new KVector(minx - parentLocation.x() - topLeftInsets.width, miny - parentLocation.y() - topLeftInsets.height));
+ mapping.setProperty(COORDINATE_OFFSET, new KVector(minx - parentLocation.x(), miny - parentLocation.y()));
}
+ } else if (!isArrangeAtOpening) {
+ mapping.setProperty(COORDINATE_OFFSET, new KVector(minx, miny));
+ } else {
+ // Use the parent node bounds if the arrange selection concerns sub part of a container during
+ // an arrange at opening
+ mapping.setProperty(COORDINATE_OFFSET,
+ new KVector(parentNode.getX() - parentLocation.x() - topLeftInsets.width, parentNode.getY() - parentLocation.y() - topLeftInsets.height));
}
} else {
if (isArrangeAll || isArrangeAtOpening) {
@@ -994,7 +994,7 @@ public class ElkDiagramLayoutConnector implements IDiagramLayoutConnector {
applyOptionsRelatedToElementTarget(newNode, elkTargetToOptionsOverrideMap);
// set location and size
- Rectangle childAbsoluteBounds = getAbsoluteBounds(nodeFigure);
+ Rectangle childAbsoluteBounds = GraphicalHelper.getAbsoluteBoundsIn100Percent(nodeEditPart, true);
KVector containerAbsoluteLocation = new KVector();
ElkUtil.toAbsolute(containerAbsoluteLocation, parentElkNode);
newNode.setX(childAbsoluteBounds.x - containerAbsoluteLocation.x);
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/layout/SimpleELKLayoutTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/layout/SimpleELKLayoutTest.java
index d53f68194b..3ef0498342 100644
--- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/layout/SimpleELKLayoutTest.java
+++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/layout/SimpleELKLayoutTest.java
@@ -1309,7 +1309,7 @@ public class SimpleELKLayoutTest extends SiriusDiagramTestCase {
assertEquals(expectedContainerTopLeftCorner, getTopLeftCorner(getEditPart("Class3_5"), getEditPart("Class3_6")));
// TODO : The top left corner should be the same for container in other container (it is currently not the case)
// (further improvement)
- expectedContainerTopLeftCorner = new Point(0, 0);
+ expectedContainerTopLeftCorner = new Point(5, 6);
assertEquals(expectedContainerTopLeftCorner, getTopLeftCorner(getEditPart("Class2_2_3")));
// Assert that there is no scroll bar on container (for p1 and p3 the new elements layout is larger than
@@ -1366,7 +1366,7 @@ public class SimpleELKLayoutTest extends SiriusDiagramTestCase {
assertEquals(expectedContainerTopLeftCorner, getTopLeftCorner(getEditPart("Class3_5"), getEditPart("Class3_6")));
// TODO : The top left corner should be the same for container in other container (it is currently not the case)
// (further improvement)
- expectedContainerTopLeftCorner = new Point(0, 0);
+ expectedContainerTopLeftCorner = new Point(5, 6);
assertEquals(expectedContainerTopLeftCorner, getTopLeftCorner(getEditPart("Class2_2_3")));
// Assert that there is no scroll bar on container (for p1 and p3 the new elements layout is larger than

Back to the top