From ba924daec9f5b209949e7a5fa162294e33219e43 Mon Sep 17 00:00:00 2001
From: Simon Barner <barner@fortiss.org>
Date: Fri, 26 Jan 2018 15:37:03 +0000
Subject: [PATCH] - Add fixMissingIDs(EObject object, EObject existingModel), a
 method that generates all missing IDs of the given sub-model. refs 3067

---
 .../org/fortiss/tooling/kernel/utils/.ratings |  2 +-
 .../tooling/kernel/utils/UniqueIDUtils.java   | 31 ++++++++++++++++---
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/.ratings b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/.ratings
index 1ff30f580..b8a101a5b 100644
--- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/.ratings
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/.ratings
@@ -12,4 +12,4 @@ MigrationUtils.java e54370b19148ff656d7563e8188baccd947c24d5 GREEN
 PrototypesUtils.java 538b5edbab06e95bc32e81309482e36a4bc64d1e GREEN
 ResourceUtils.java 8ab06ad3b72fdb2b1925e2ccbedcfea35e36cf24 GREEN
 TransformationUtils.java f159b17ac1ce2ce0d94c1a873d74e052ac2dc74b GREEN
-UniqueIDUtils.java 9586f7f13b69b89d2b443312373e7f15aac92bd8 GREEN
+UniqueIDUtils.java f8b053bf64835d8a441192f7681fda0655a98469 YELLOW
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/UniqueIDUtils.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/UniqueIDUtils.java
index a0ba898c4..e96bd49aa 100644
--- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/UniqueIDUtils.java
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/UniqueIDUtils.java
@@ -261,11 +261,32 @@ public class UniqueIDUtils {
 	public static void fixMissingIDs(final ITopLevelElement modelElement) {
 		final int maxID = getLargestID(modelElement.getRootModelElement());
 		if(maxID > 0) {
-			modelElement.runAsCommand(new Runnable() {
-				@Override
-				public void run() {
-					generateMissingIDs(modelElement.getRootModelElement(), maxID);
-				}
+			modelElement.runAsCommand(() -> {
+				generateMissingIDs(modelElement.getRootModelElement(), maxID);
+			});
+		}
+	}
+
+	/**
+	 * Generates all missing IDs of the given sub-model.
+	 * 
+	 * @param object
+	 *            The sub-model element for which missing IDs should be prepared
+	 * @param existingModel
+	 *            the existing model to be considered for used IDs if object
+	 *            already contains IDs > 0
+	 */
+	public static void fixMissingIDs(EObject object, EObject existingModel) {
+		EObject root = existingModel;
+		while(root.eContainer() != null) {
+			root = root.eContainer();
+		}
+		ITopLevelElement topLevelElement =
+				IPersistencyService.getInstance().getTopLevelElementFor(existingModel);
+		final int maxID = getLargestID(root);
+		if(maxID > 0) {
+			topLevelElement.runAsCommand(() -> {
+				generateMissingIDs(object, maxID);
 			});
 		}
 	}
-- 
GitLab