Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Redor2017-09-07 09:08:07 +0000
committerLaurent Redor2017-09-07 16:01:56 +0000
commit41968cea31afb15f04a891d28e4c50a68481abd6 (patch)
treec806d5113de900bf720a900457bca6c0fc219993
parentd93fcfdb588651aa7f3803cbc7be08857ba301d6 (diff)
downloadorg.eclipse.sirius-41968cea31afb15f04a891d28e4c50a68481abd6.tar.gz
org.eclipse.sirius-41968cea31afb15f04a891d28e4c50a68481abd6.tar.xz
org.eclipse.sirius-41968cea31afb15f04a891d28e4c50a68481abd6.zip
[520632] Add tests for simultaneous elements creation
This allows to discover that the case is correctly managed for creation in diagram but not for creation in container. This commit also fixes this problem. Bug: 520632 Change-Id: I5d933011a6073ea1cbc27f3dc6c329554f7e3986 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/internal/refresh/AbstractCanonicalSynchronizer.java64
-rw-r--r--plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/NodeCreationPositionTest.java73
2 files changed, 100 insertions, 37 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/AbstractCanonicalSynchronizer.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/AbstractCanonicalSynchronizer.java
index 4ff5884773..d445da1d27 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/AbstractCanonicalSynchronizer.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/AbstractCanonicalSynchronizer.java
@@ -457,37 +457,24 @@ public abstract class AbstractCanonicalSynchronizer implements CanonicalSynchron
Bounds bounds = (Bounds) ((Node) createdView).getLayoutConstraint();
if (location == null && previousCreatedView instanceof Node && ((Node) previousCreatedView).getLayoutConstraint() instanceof Bounds) {
- // if a location has been registered in
- // SiriusLayoutDataManager but we were not able to
- // retrieve it before -> Set a center location for child
- // DNode of DNodeContainer
- // like
- // in AirXYLayoutEditPolicy#getConstraintFor(request)
+ // if a location has been registered in SiriusLayoutDataManager but we were not able to retrieve it
+ // before -> Set a center location for child DNode of DNodeContainer like in
+ // AirXYLayoutEditPolicy#getConstraintFor(request)
if (previousCreatedView.eAdapters().contains(SiriusLayoutDataManager.INSTANCE.getCenterAdapterMarker())) {
markCreatedViewsWithCenterLayout(createdView);
} else {
- // If no location is found in the layoutDataManager we can
- // use
- // the previous created View coordinates and translate it.
- // This
- // is the case for example in D'n'D or when several elements
- // are
- // created at same time.
+ // If no location is found in the layoutDataManager we can use the previous created View coordinates
+ // and translate it. This is the case for example in D'n'D or when several elements are created at
+ // same time.
Bounds previousBounds = (Bounds) ((Node) previousCreatedView).getLayoutConstraint();
- int padding = SiriusLayoutDataManager.PADDING;
- if (isSnapToGrid()) {
- padding = getGridSpacing();
- }
+ int padding = getPaddingForNextView();
location = new Point(previousBounds.getX(), previousBounds.getY()).getTranslated(padding, padding);
}
}
- // if a location has been registered in
- // SiriusLayoutDataManager but we were not able to
- // retrieve it before -> Set a center location for child
- // DNode of DNodeContainer
- // like
- // in AirXYLayoutEditPolicy#getConstraintFor(request)
+ // if a location has been registered in SiriusLayoutDataManager but we were not able to retrieve it before
+ // -> Set a center location for child DNode of DNodeContainer like in
+ // AirXYLayoutEditPolicy#getConstraintFor(request)
if (location == null && SiriusLayoutDataManager.INSTANCE.getData().some()) {
// mark with special layout
markCreatedViewsWithCenterLayout(createdView);
@@ -681,28 +668,23 @@ public abstract class AbstractCanonicalSynchronizer implements CanonicalSynchron
if (location == null) {
if (previousCreatedView instanceof Node && ((Node) previousCreatedView).getLayoutConstraint() instanceof Bounds) {
- // if a location has been registered in
- // SiriusLayoutDataManager but we were not able to
- // retrieve it before -> Set a center location for child
- // DNode of DNodeContainer
- // like
- // in AirXYLayoutEditPolicy#getConstraintFor(request)
+ // if a location has been registered in SiriusLayoutDataManager but we were not able to retrieve it
+ // before -> Set a center location for child DNode of DNodeContainer like in
+ // AirXYLayoutEditPolicy#getConstraintFor(request)
if (previousCreatedView.eAdapters().contains(SiriusLayoutDataManager.INSTANCE.getCenterAdapterMarker())) {
markCreatedViewsWithCenterLayout(createdView);
} else {
Bounds previousBounds = (Bounds) ((Node) previousCreatedView).getLayoutConstraint();
- location = new Point(previousBounds.getX(), previousBounds.getY()).getTranslated(SiriusLayoutDataManager.PADDING, SiriusLayoutDataManager.PADDING);
+ int padding = getPaddingForNextView();
+ location = new Point(previousBounds.getX(), previousBounds.getY()).getTranslated(padding, padding);
}
isAlreadylayouted = true;
} else {
- // if a location has been registered in
- // SiriusLayoutDataManager but we were not able to
- // retrieve it before -> Set a center location for child
- // DNode of DNodeContainer like
- // in AirXYLayoutEditPolicy#getConstraintFor(request),
- // except for children of regions container for which layout
- // is managed with RegionContainerUpdateLayoutOperation.
+ // if a location has been registered in SiriusLayoutDataManager but we were not able to retrieve it
+ // before -> Set a center location for child DNode of DNodeContainer like in
+ // AirXYLayoutEditPolicy#getConstraintFor(request), except for children of regions container for
+ // which layout is managed with RegionContainerUpdateLayoutOperation.
if (layoutData == null && SiriusLayoutDataManager.INSTANCE.getData().some() && !(new DNodeContainerExperimentalQuery((DNodeContainer) parent).isRegionContainer())) {
// mark with special layout
markCreatedViewsWithCenterLayout(createdView);
@@ -719,6 +701,14 @@ public abstract class AbstractCanonicalSynchronizer implements CanonicalSynchron
return isAlreadylayouted;
}
+ private int getPaddingForNextView() {
+ int padding = SiriusLayoutDataManager.PADDING;
+ if (isSnapToGrid()) {
+ padding = getGridSpacing();
+ }
+ return padding;
+ }
+
private void updateLocationConstraint(Node createdNode, Dimension size, Point location, AbstractDNode abstractDNode) {
Bounds bounds = (Bounds) createdNode.getLayoutConstraint();
if (location != null) {
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/NodeCreationPositionTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/NodeCreationPositionTest.java
index ed49ca6c2a..66d20b512a 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/NodeCreationPositionTest.java
+++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/NodeCreationPositionTest.java
@@ -312,6 +312,62 @@ public class NodeCreationPositionTest extends AbstractSiriusSwtBotGefTestCase {
}
/**
+ * Test for the multiple EClass creation with a standard tool and snapToGrid
+ * enabled to check that created elements are selected after creation (and
+ * with a space of grid spacing).
+ */
+ public void testNodeMultipleSelectionAfterMultipleCreationOnPackageByStandardToolAndSnapToGrid() {
+ openDiagram();
+ SWTBotGefEditPart p3Bot = editor.getEditPart("p3").parent();
+ Point creationLocation = editor.getBounds(p3Bot).getCenter();
+ testNodeMultipleSelectionAfterMultipleCreationByStandardToolAndSnapToGrid(creationLocation);
+ }
+
+ /**
+ * Test for the multiple EClass creation with a standard tool and snapToGrid
+ * enabled to check that created elements are selected after creation (and
+ * with a space of grid spacing).
+ */
+ public void testNodeMultipleSelectionAfterMultipleCreationOnDiagramByStandardToolAndSnapToGrid() {
+ openDiagram();
+ testNodeMultipleSelectionAfterMultipleCreationByStandardToolAndSnapToGrid(new Point(10, 10));
+ }
+
+ /**
+ * Test for the multiple EClass creation with a standard tool and snapToGrid
+ * enabled to check that created elements are selected after creation (and
+ * with a space of grid spacing).
+ */
+ private void testNodeMultipleSelectionAfterMultipleCreationByStandardToolAndSnapToGrid(Point creationLocation) {
+ int gridSpacing = 50;
+ editor.setSnapToGrid(true, gridSpacing, 2);
+ // Create three EClass
+ editor.activateTool("ThreeClass");
+ editor.click(creationLocation);
+
+ // Checks their selection
+ SWTBotGefEditPart createdNewEClass1Bot = editor.getEditPart("new EClass 1").parent();
+ assertEquals("the created view should be selected as primary view", EditPart.SELECTED, createdNewEClass1Bot.part().getSelected());
+ Point c1Location = editor.getAbsoluteLocation((GraphicalEditPart) createdNewEClass1Bot.part());
+ checkLocationAlignOnGrid(c1Location, "new EClass 1", gridSpacing);
+
+ SWTBotGefEditPart createdNewEClass2Bot = editor.getEditPart("new EClass 2").parent();
+ assertEquals("the created view should be selected as primary view", EditPart.SELECTED, createdNewEClass2Bot.part().getSelected());
+ Point c2Location = editor.getAbsoluteLocation((GraphicalEditPart) createdNewEClass2Bot.part());
+ checkLocationAlignOnGrid(c2Location, "new EClass 2", gridSpacing);
+ assertEquals("The x coordinate of second class should have a delta of " + gridSpacing + " pixels with the x coordinate of the first class.", c1Location.x + gridSpacing, c2Location.x);
+ assertEquals("The y coordinate of second class should have a delta of " + gridSpacing + " pixels with the y coordinate of the first class.", c1Location.y + gridSpacing, c2Location.y);
+
+ SWTBotGefEditPart createdNewEClass3Bot = editor.getEditPart("new EClass 3").parent();
+ assertEquals("the created view should be selected as primary view", EditPart.SELECTED_PRIMARY, createdNewEClass3Bot.part().getSelected());
+ Point c3Location = editor.getAbsoluteLocation((GraphicalEditPart) createdNewEClass3Bot.part());
+ checkLocationAlignOnGrid(c3Location, "new EClass 3", gridSpacing);
+ assertEquals("The x coordinate of third class should have a delta of " + gridSpacing + " pixels with the x coordinate of the second class.", c2Location.x + gridSpacing, c3Location.x);
+ assertEquals("The y coordinate of third class should have a delta of " + gridSpacing + " pixels with the y coordinate of the second class.", c2Location.y + gridSpacing, c3Location.y);
+ }
+
+
+ /**
* Test for the single EReference creation with a standard tool to check
* that created element are selected after creation.
*/
@@ -1240,4 +1296,21 @@ public class NodeCreationPositionTest extends AbstractSiriusSwtBotGefTestCase {
assertFalse("Edit part should not exist", found);
}
}
+
+ /**
+ * 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