diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/ModelUtils.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/ModelUtils.java index 893fc9d1e865347339819e029884891c6545676c..ec024f72471817fea57baaee4e201b0dee6a14f0 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/ModelUtils.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/ModelUtils.java @@ -17,7 +17,10 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.utils; +import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.ecore.EObject; +import org.fortiss.tooling.kernel.extension.data.ITopLevelElement; +import org.fortiss.tooling.kernel.model.IIdLabeled; import org.fortiss.tooling.kernel.service.ICommandStackService; import org.fortiss.tooling.kernel.service.IPersistencyService; @@ -27,7 +30,7 @@ import org.fortiss.tooling.kernel.service.IPersistencyService; * @author doebber * @author $Author: hoelzl $ * @version $Rev: 18709 $ - * @ConQAT.Rating GREEN Hash: 196FA181C009BB49CC3E878D79547091 + * @ConQAT.Rating YELLOW Hash: 4E7A872801564F1C1CEDB77AA20BC8ED */ public class ModelUtils { @@ -58,6 +61,24 @@ public class ModelUtils { * if the context is not contained in a persisted model. */ public static void prepareUniqueID(EObject element, EObject context) { - IPersistencyService.INSTANCE.getTopLevelElementFor(context).prepareIDs(element); + ITopLevelElement top = IPersistencyService.INSTANCE.getTopLevelElementFor(context); + + if(top == null) { + EObject root = context; + while(root.eContainer() != null) + root = root.eContainer(); + + int id = Integer.MIN_VALUE; + for(TreeIterator<EObject> iter = root.eAllContents(); iter.hasNext();) { + EObject o = iter.next(); + if(o instanceof IIdLabeled) { + id = Math.max(id, ((IIdLabeled)o).getId()); + } + } + + ((IIdLabeled)element).setId(id + 1); + } else { + top.prepareIDs(element); + } } }