From db7c92f8d76aafde5d0a670cc81caa2b18002bc3 Mon Sep 17 00:00:00 2001
From: Florian Hoelzl <hoelzl@fortiss.org>
Date: Mon, 21 May 2012 10:58:00 +0000
Subject: [PATCH] bugfix: layout utils reuse old objects if possible refs 820

---
 .../tooling/base/utils/DimensionUtils.java    | 23 +++++++++---------
 .../tooling/base/utils/PointUtils.java        | 24 +++++++++----------
 2 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/DimensionUtils.java b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/DimensionUtils.java
index 68fe31631..b60b3efd9 100644
--- a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/DimensionUtils.java
+++ b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/DimensionUtils.java
@@ -29,7 +29,7 @@ import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
  * @author hoelzl
  * @author $Author$
  * @version $Rev$
- * @ConQAT.Rating GREEN Hash: 5C92A83202006734362EED9438B3A2D8
+ * @ConQAT.Rating YELLOW Hash: 5BDF0EA81728D59FBC5E27E00904D085
  */
 public final class DimensionUtils {
 
@@ -42,11 +42,10 @@ public final class DimensionUtils {
 	 *            the layout key
 	 * @return the dimension of the element
 	 */
-	public static Dimension getDimension(ILayoutedModelElement layouted,
-			String key) {
-		for (ILayoutData ld : layouted.getLayoutDataList()) {
-			if (ld.getKey().equals(key) && ld instanceof Dimension) {
-				return (Dimension) ld;
+	public static Dimension getDimension(ILayoutedModelElement layouted, String key) {
+		for(ILayoutData ld : layouted.getLayoutDataList()) {
+			if(ld.getKey().equals(key) && ld instanceof Dimension) {
+				return (Dimension)ld;
 			}
 		}
 		return null;
@@ -64,13 +63,13 @@ public final class DimensionUtils {
 	 * @param h
 	 *            the height
 	 */
-	public static void setDimension(ILayoutedModelElement layouted, String key,
-			int w, int h) {
+	public static void setDimension(ILayoutedModelElement layouted, String key, int w, int h) {
 		Dimension old = getDimension(layouted, key);
-		if (old != null) {
-			layouted.getLayoutDataList().remove(old);
+		if(old != null) {
+			old.setWidth(w);
+			old.setHeight(h);
+		} else {
+			layouted.getLayoutDataList().add(createDimension(w, h, key));
 		}
-		Dimension d = createDimension(w, h, key);
-		layouted.getLayoutDataList().add(d);
 	}
 }
diff --git a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/PointUtils.java b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/PointUtils.java
index 780cb42cb..70d0dbf3b 100644
--- a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/PointUtils.java
+++ b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/PointUtils.java
@@ -32,7 +32,7 @@ import org.fortiss.tooling.base.model.layout.Point;
  * @author hoelzl
  * @author $Author$
  * @version $Rev$
- * @ConQAT.Rating GREEN Hash: C4401B596767E967B83634EA26A60EC4
+ * @ConQAT.Rating YELLOW Hash: 497062A726321ADDE1E6991D61DE481F
  */
 public final class PointUtils {
 
@@ -48,10 +48,10 @@ public final class PointUtils {
 	public static Point getPosition(ILayoutedModelElement layouted, String key) {
 		Point point = getPoint(layouted, key);
 
-		if (point == null) {
+		if(point == null) {
 			int index = 0;
 			EObject container = layouted.eContainer();
-			if (container != null) {
+			if(container != null) {
 				index = 1 + container.eContents().indexOf(layouted);
 			}
 			Point p = createPoint(index * 20, index * 20, key);
@@ -62,9 +62,9 @@ public final class PointUtils {
 
 	/** Returns a {@link Point} layout data object with the given key or null. */
 	private static Point getPoint(ILayoutedModelElement layouted, String key) {
-		for (ILayoutData ld : layouted.getLayoutDataList()) {
-			if (ld.getKey().equals(key) && ld instanceof Point) {
-				return (Point) ld;
+		for(ILayoutData ld : layouted.getLayoutDataList()) {
+			if(ld.getKey().equals(key) && ld instanceof Point) {
+				return (Point)ld;
 			}
 		}
 		return null;
@@ -82,13 +82,13 @@ public final class PointUtils {
 	 * @param y
 	 *            the y coordinate value
 	 */
-	public static void setPoint(ILayoutedModelElement layouted, String key,
-			int x, int y) {
+	public static void setPoint(ILayoutedModelElement layouted, String key, int x, int y) {
 		Point old = getPoint(layouted, key);
-		if (old != null) {
-			layouted.getLayoutDataList().remove(old);
+		if(old != null) {
+			old.setX(x);
+			old.setY(y);
+		} else {
+			layouted.getLayoutDataList().add(createPoint(x, y, key));
 		}
-		Point p = createPoint(x, y, key);
-		layouted.getLayoutDataList().add(p);
 	}
 }
-- 
GitLab