Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Redor2017-09-07 09:58:10 +0000
committerLaurent Redor2017-09-08 09:47:51 +0000
commited2ea73448b7063225e100400d422a58349ecf70 (patch)
treeb1dbd867b75c75bf1dd379ef8171fdd394d86f7d
parent41968cea31afb15f04a891d28e4c50a68481abd6 (diff)
downloadorg.eclipse.sirius-ed2ea73448b7063225e100400d422a58349ecf70.tar.gz
org.eclipse.sirius-ed2ea73448b7063225e100400d422a58349ecf70.tar.xz
org.eclipse.sirius-ed2ea73448b7063225e100400d422a58349ecf70.zip
[520632] Handle other cases where Sirius default PADDING is used
This commit is not really in scope of the issue but when SiriusLayoutDataManager.PADDING is used, if snapToGrid is enabled we must always consider the grid spacing instead of the default PADDING. Even if code concerned in AirXYLayoutEditPolicy is not used, it has been changed too. The changed code for SiriusLayoutDataManagerImpl is tested with new test in GroupElementsInOneOtherTests. Bug: 520632 Change-Id: I73dcfe8eab5529d81c58063a753306e47e22f0d9 Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/view/SiriusLayoutDataManagerImpl.java31
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/AirXYLayoutEditPolicy.java7
-rw-r--r--plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/editparts/GraphicalHelper.java11
-rw-r--r--plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/GroupElementsInOneOtherTests.java83
4 files changed, 116 insertions, 16 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/view/SiriusLayoutDataManagerImpl.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/view/SiriusLayoutDataManagerImpl.java
index 2a177cd670..46376f4e2a 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/view/SiriusLayoutDataManagerImpl.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/view/SiriusLayoutDataManagerImpl.java
@@ -28,16 +28,20 @@ import org.eclipse.core.commands.operations.OperationHistoryFactory;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.draw2d.FigureCanvas;
+import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.EditPart;
+import org.eclipse.gef.SnapToHelper;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gef.requests.CreateRequest;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.common.core.util.ObjectAdapter;
import org.eclipse.gmf.runtime.diagram.ui.actions.ActionIds;
@@ -67,6 +71,7 @@ import org.eclipse.sirius.diagram.ui.graphical.figures.SiriusLayoutHelper;
import org.eclipse.sirius.diagram.ui.provider.Messages;
import org.eclipse.sirius.ext.base.Option;
import org.eclipse.sirius.ext.base.Options;
+import org.eclipse.sirius.ext.gmf.runtime.editparts.GraphicalHelper;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
@@ -561,12 +566,30 @@ public final class SiriusLayoutDataManagerImpl implements SiriusLayoutDataManage
rect.setSize(LayoutHelper.UNDEFINED.getSize());
Point centerLocation;
if (previousCenterLocation == null) {
- Point result = getLayoutHelper().getReferencePosition(host.getContentPane(), ((FigureCanvas) host.getViewer().getControl()).getViewport(), host);
- rect.setLocation(result);
+ // Get center (reference point)
+ Point referencePoint = getLayoutHelper().getReferencePosition(host.getContentPane(), ((FigureCanvas) host.getViewer().getControl()).getViewport(), host);
+ rect.setLocation(referencePoint);
+ // Get the first free location
Point point = getLayoutHelper().validatePosition(host.getContentPane(), rect);
- centerLocation = point.getCopy();
+ // Snap the first free location
+ PrecisionPoint result = new PrecisionPoint(point);
+ // We must apply the zoom to be compatible with what SnapToHelper expects
+ GraphicalHelper.logical2screen(result, host);
+ SnapToHelper helper = host.getAdapter(SnapToHelper.class);
+ if (helper != null) {
+ PrecisionPoint preciseLocation = new PrecisionPoint(result);
+ helper.snapPoint(new CreateRequest(), PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, preciseLocation, result);
+ }
+ // Inverse zoom to retrieve expected coordinates here
+ GraphicalHelper.screen2logical(result, host);
+ rect.setLocation(result);
+ centerLocation = result.getCopy();
} else {
- centerLocation = new Point(previousCenterLocation).getTranslated(SiriusLayoutDataManager.PADDING, SiriusLayoutDataManager.PADDING);
+ int padding = SiriusLayoutDataManager.PADDING;
+ if (GraphicalHelper.isSnapToGridEnabled(host)) {
+ padding = GraphicalHelper.getGridSpacing(host);
+ }
+ centerLocation = new Point(previousCenterLocation).getTranslated(padding, padding);
}
IGraphicalEditPart part = (IGraphicalEditPart) host.getViewer().getEditPartRegistry().get(iAdaptable.getAdapter(View.class));
cc.add(new ICommandProxy(new SetBoundsCommand(host.getEditingDomain(), DiagramUIMessages.SetLocationCommand_Label_Resize, part, centerLocation)));
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/AirXYLayoutEditPolicy.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/AirXYLayoutEditPolicy.java
index 7a0128c311..4fdacf8fe7 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/AirXYLayoutEditPolicy.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/AirXYLayoutEditPolicy.java
@@ -54,6 +54,7 @@ import org.eclipse.sirius.diagram.ui.internal.operation.ShiftEdgeIdentityAnchorO
import org.eclipse.sirius.diagram.ui.internal.view.factories.ViewSizeHint;
import org.eclipse.sirius.diagram.ui.tools.api.layout.LayoutUtils;
import org.eclipse.sirius.diagram.ui.tools.internal.edit.command.CommandFactory;
+import org.eclipse.sirius.ext.gmf.runtime.editparts.GraphicalHelper;
/**
* The {@link AirXYLayoutEditPolicy}. import
@@ -170,7 +171,11 @@ public class AirXYLayoutEditPolicy extends XYLayoutEditPolicy {
if (location != null) {
Point centerLocation = location.getCopy();
if (locationReference != null && !hasLayoutData) {
- locationReference.translate(SiriusLayoutDataManager.PADDING, SiriusLayoutDataManager.PADDING);
+ int padding = SiriusLayoutDataManager.PADDING;
+ if (GraphicalHelper.isSnapToGridEnabled(host)) {
+ padding = GraphicalHelper.getGridSpacing(host);
+ }
+ locationReference.translate(padding, padding);
centerLocation = locationReference.getCopy();
}
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 5147cca292..892b330a0b 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
@@ -635,4 +635,15 @@ public final class GraphicalHelper {
public static boolean isSnapToGridEnabled(EditPart editPart) {
return (Boolean) editPart.getViewer().getProperty(SnapToGrid.PROPERTY_GRID_ENABLED);
}
+
+ /**
+ * Return the grid spacing in pixels for the diagram containing this edit part.
+ *
+ * @param editPart
+ * The edit part to use.
+ * @return the grid spacing in pixels.
+ */
+ public static int getGridSpacing(EditPart editPart) {
+ return ((Dimension) editPart.getViewer().getProperty(SnapToGrid.PROPERTY_GRID_SPACING)).width;
+ }
}
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/GroupElementsInOneOtherTests.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/GroupElementsInOneOtherTests.java
index 8b3f7a5c0f..a815c6b368 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/GroupElementsInOneOtherTests.java
+++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/GroupElementsInOneOtherTests.java
@@ -22,6 +22,7 @@ import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.sirius.diagram.DDiagram;
+import org.eclipse.sirius.diagram.ui.business.api.view.SiriusLayoutDataManager;
import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramContainerEditPart;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNodeEditPart;
import org.eclipse.sirius.ext.gmf.runtime.editparts.GraphicalHelper;
@@ -161,19 +162,63 @@ public class GroupElementsInOneOtherTests extends AbstractSiriusSwtBotGefTestCas
* figure.
*/
public void testMultiCreationOutsideCurrentSelection() {
- // Select Class1 & Class3
- editor.select(class1ChildOfDiagramBot, class3ChildOfDiagramBot);
- // Launch the action that create 2 packages outside the current selected
- // element
- editor.clickContextMenu(CREATION_TOOL_NAME);
+ testMultiCreationOutsideCurrentSelection(false);
+ }
- // Check that the two new packages top-left corner does not overlap each
- // other.
- Point package5AbsoluteLocation = editor.getAbsoluteLocation("Package5", AbstractDiagramContainerEditPart.class);
- Point package6AbsoluteLocation = editor.getAbsoluteLocation("Package6", AbstractDiagramContainerEditPart.class);
+ /**
+ * Test that creating two elements outside the current selection (with
+ * snapToGrid enabled), does not overlapped this new packages (VP-2609).<BR>
+ * Currently there is no overlapping for the top-left corner. A specific
+ * issue VP-2399 must be fix to check that there is no overlap of all the
+ * figure.
+ */
+ public void testMultiCreationOutsideCurrentSelectionWithSnapToGridEnabled() {
+ testMultiCreationOutsideCurrentSelection(true);
+ }
+
+ /**
+ * Test that creating two elements outside the current selection (with
+ * snapToGrid enabled), does not overlapped this new packages (VP-2609).<BR>
+ * Currently there is no overlapping for the top-left corner. A specific
+ * issue VP-2399 must be fix to check that there is no overlap of all the
+ * figure.
+ */
+ private void testMultiCreationOutsideCurrentSelection(boolean isSnapToGridEnabled) {
+ if (isSnapToGridEnabled) {
+ editor.setSnapToGrid(true, 50, 2);
+ }
+ try {
+ // Select Class1 & Class3
+ editor.select(class1ChildOfDiagramBot, class3ChildOfDiagramBot);
+ // Launch the action that create 2 packages outside the current
+ // selected
+ // element
+ editor.clickContextMenu(CREATION_TOOL_NAME);
+
+ // Check that the two new packages top-left corner does not overlap
+ // each
+ // other.
+ Point package5AbsoluteLocation = editor.getAbsoluteLocation("Package5", AbstractDiagramContainerEditPart.class);
+ Point package6AbsoluteLocation = editor.getAbsoluteLocation("Package6", AbstractDiagramContainerEditPart.class);
+
+ assertFalse("The location (top-left corner) of the first created figure should not overlaped the location (top-left corner) of the second created figure.",
+ package5AbsoluteLocation.equals(package6AbsoluteLocation));
+ int padding = SiriusLayoutDataManager.PADDING;
+ if (isSnapToGridEnabled) {
+ padding = 50;
- assertFalse("The location (top-left corner) of the first created figure should not overlaped the location (top-left corner) of the second created figure.",
- package5AbsoluteLocation.equals(package6AbsoluteLocation));
+ }
+ assertEquals("The x coordinate of Package6 should have a delta of " + padding + " pixels with the x coordinate of the Package5.", package5AbsoluteLocation.x + padding,
+ package6AbsoluteLocation.x);
+ assertEquals("The y coordinate of Package6 should have a delta of " + padding + " pixels with the y coordinate of the Package5.", package5AbsoluteLocation.y + padding,
+ package6AbsoluteLocation.y);
+ if (isSnapToGridEnabled) {
+ checkLocationAlignOnGrid(package5AbsoluteLocation, "Package5", padding);
+ checkLocationAlignOnGrid(package6AbsoluteLocation, "Package6", padding);
+ }
+ } finally {
+ editor.setSnapToGrid(false);
+ }
}
/**
@@ -234,4 +279,20 @@ public class GroupElementsInOneOtherTests extends AbstractSiriusSwtBotGefTestCas
super.tearDown();
}
+ /**
+ * Check that a diagram element is aligned on the grid.
+ *
+ * @param location
+ * location of the diagram element element to check
+ * @param elementNameToDisplay
+ * The name of the element displayed in case of error
+ * @param gridSpacing
+ * The current grid spacing
+ */
+ private void checkLocationAlignOnGrid(Point location, String elementNameToDisplay, int gridSpacing) {
+ boolean locationIsOK = (location.x % gridSpacing) == 0 || (location.y % gridSpacing) == 0;
+ if (!locationIsOK) {
+ fail("For " + elementNameToDisplay + ", the x or y coordinate of the top left corner should be on the grid (grid spacing = " + gridSpacing + "), but was: " + location + ".");
+ }
+ }
}

Back to the top