diff options
| author | Laurent Redor | 2020-10-26 18:02:00 +0000 |
|---|---|---|
| committer | Laurent Redor | 2020-11-05 19:15:46 +0000 |
| commit | 789a4f679e177a1b2ca8023fcb3a7c069882fc77 (patch) | |
| tree | a736f44b001c4e30249891a507b943f752caf85f | |
| parent | e96e20e29cfde10b353b635bc34bc1d4e6ce8f0f (diff) | |
| download | org.eclipse.sirius-789a4f679e177a1b2ca8023fcb3a7c069882fc77.tar.gz org.eclipse.sirius-789a4f679e177a1b2ca8023fcb3a7c069882fc77.tar.xz org.eclipse.sirius-789a4f679e177a1b2ca8023fcb3a7c069882fc77.zip | |
[568037] Arrange selection of container in container with ELK
When launching an arrange selection on only one container, located in
another container (not in the diagram), the locations of elements inside
the container were wrong after the layout.
Bug: 568037
Change-Id: I8dd0e776289313140ad4a1b2470e25048743d260
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.java | 39 |
1 files changed, 31 insertions, 8 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 502211c5d7..55ae6174b4 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 @@ -497,6 +497,15 @@ public class ElkDiagramLayoutConnector implements IDiagramLayoutConnector { ElkNode topNode = ElkGraphUtil.createGraph(); applyOptionsRelatedToElementTarget(topNode, elkTargetToOptionsOevrrideMap); + // The parentLocation is used when launching an arrange selection of one container contained in another + // container + Point parentLocation = new Point(0, 0); + IGraphicalEditPart parentEditPart = getTopGraphicParentEditPartIfPresent(layoutRootPart); + if (parentEditPart != null && !(parentEditPart instanceof DiagramEditPart)) { + // Compute the parent location origin + parentLocation = getAbsoluteBounds(parentEditPart.getFigure()).getTopLeft(); + } + if (layoutRootPart instanceof ShapeNodeEditPart && selection.isEmpty()) { // If the root part is a ShapeNodeEditPart and the selection is empty, this implies an arrange selection on // only one element (ie one parent). So we want to keep it at a fixed location. For that we use the bounds @@ -506,9 +515,8 @@ public class ElkDiagramLayoutConnector implements IDiagramLayoutConnector { topNode.setIdentifier(((DDiagramElement) ((View) layoutRootPart.getModel()).getElement()).getName() + "_graph"); } - IFigure nodeFigure = layoutRootPart.getFigure(); - Rectangle childAbsoluteBounds = getAbsoluteBounds(nodeFigure); - + Rectangle childAbsoluteBounds = getAbsoluteBounds(layoutRootPart.getFigure()); + topNode.setLocation(0, 0); topNode.setDimensions(childAbsoluteBounds.preciseX() + childAbsoluteBounds.preciseWidth(), childAbsoluteBounds.preciseY() + childAbsoluteBounds.preciseHeight()); @@ -557,12 +565,27 @@ public class ElkDiagramLayoutConnector implements IDiagramLayoutConnector { } } - // Use ResetOriginChangeModelOperation.MARGIN instead of minx or miny when arranging all elements of the - // diagram - if (isArrangeAll) { - mapping.setProperty(COORDINATE_OFFSET, new KVector(ResetOriginChangeModelOperation.MARGIN, ResetOriginChangeModelOperation.MARGIN)); + if (layoutRootPart instanceof ShapeNodeEditPart) { + if (selection.size() == 1 && selection.get(0).equals(layoutRootPart)) { + mapping.setProperty(COORDINATE_OFFSET, new KVector(minx - parentLocation.x(), miny - parentLocation.y())); + } else if (parentLocation.x() == 0 && parentLocation.y() == 0) { + // the parent of the container is the diagram use "classical coordinate offset + mapping.setProperty(COORDINATE_OFFSET, new KVector(minx, miny)); + } else { + // Use the parent node bounds 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)); + } } else { - mapping.setProperty(COORDINATE_OFFSET, new KVector(minx, miny)); + if (isArrangeAll) { + // Use ResetOriginChangeModelOperation.MARGIN instead of minx or miny when arranging all elements of + // the current diagram + mapping.setProperty(COORDINATE_OFFSET, new KVector(ResetOriginChangeModelOperation.MARGIN, ResetOriginChangeModelOperation.MARGIN)); + } else { + mapping.setProperty(COORDINATE_OFFSET, new KVector(minx - parentLocation.x(), miny - parentLocation.y())); + } } } else { // traverse all children of the layout root part |
