Bug 458465 - PeServiceImpl.getLocationInfo Returns Shape that Has Been
Sent to Back
* Loop over child shapes in inverse order
Change-Id: If59822d3dc72a3f76b55fd3bc7f122c323e8108f
diff --git a/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/internal/services/impl/PeServiceImpl.java b/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/internal/services/impl/PeServiceImpl.java
index 88fe156..4a1f2e7 100644
--- a/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/internal/services/impl/PeServiceImpl.java
+++ b/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/internal/services/impl/PeServiceImpl.java
@@ -969,7 +969,8 @@
if (shape instanceof ContainerShape) {
ContainerShape containerShape = (ContainerShape) shape;
List<Shape> children = containerShape.getChildren();
- for (Shape childShape : children) {
+ for (int i = children.size() - 1; i >= 0; i--) {
+ Shape childShape = children.get(i);
GraphicsAlgorithm childGa = childShape.getGraphicsAlgorithm();
if (childGa != null) {
int newX = x - childGa.getX();
diff --git a/tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/cases/PeServiceTest.java b/tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/cases/PeServiceTest.java
index c9c9d30..fc04e5b 100644
--- a/tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/cases/PeServiceTest.java
+++ b/tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/cases/PeServiceTest.java
@@ -367,6 +367,33 @@
assertEquals(new DimensionImpl(100, 100), dim3);
}
+ // Test for Bug 458465
+ @Test
+ public void testWhenShapeWasSentToBack_andGetLocationInfo_thenShapeInFrontIsReturned() {
+ ICreateService createService = Graphiti.getCreateService();
+ ILayoutService layoutService = Graphiti.getLayoutService();
+
+ ContainerShape cs = createService.createContainerShape(d, true);
+ Rectangle r = createService.createRectangle(cs);
+ layoutService.setLocationAndSize(r, 100, 100, 100, 100);
+
+ Shape s1 = createService.createShape(cs, true);
+ Rectangle r1 = createService.createRectangle(s1);
+ layoutService.setLocationAndSize(r1, 10, 10, 80, 80);
+
+ Shape s2 = createService.createShape(cs, true);
+ Rectangle r2 = createService.createRectangle(s2);
+ layoutService.setLocationAndSize(r2, 20, 20, 60, 60);
+
+ ILocationInfo locationInfo = layoutService.getLocationInfo(d, 150, 150);
+ assertEquals(s2, locationInfo.getShape());
+ assertEquals(r2, locationInfo.getGraphicsAlgorithm());
+
+ locationInfo = layoutService.getLocationInfo(d, 115, 115);
+ assertEquals(s1, locationInfo.getShape());
+ assertEquals(r1, locationInfo.getGraphicsAlgorithm());
+ }
+
@Test
public void checkProperties() {
ICreateService createService = Graphiti.getCreateService();