X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.structural.synchronization.client%2Fsrc%2Forg%2Fsimantics%2Fstructural%2Fsynchronization%2Fbase%2FUpdateComponentUids.java;h=df63ada0525911d50cd84c636989f1fe8e30d34c;hp=d3233115254aecb5863bd31d2874241849e618a5;hb=6b4432af6fe79c859dd1ddb31fd185d64c729863;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07 diff --git a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java index d32331152..df63ada05 100644 --- a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java +++ b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java @@ -5,13 +5,16 @@ import org.simantics.db.ReadGraph; import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.variable.Variable; +import org.simantics.structural.synchronization.utils.ComponentBase; + +import gnu.trove.map.hash.THashMap; /** * Utility for updating UIDs in the given component to correspond * the RVIs of the given variable. This operation is needed when * the mapping is part of a model that is imported to a new database * and resource ids have been changed. - * + * * @author Hannu Niemistö * @author Tuukka Lehtonen */ @@ -21,10 +24,11 @@ public class UpdateComponentUids> { void componentsDone(int components, int componentCount); } + private THashMap oldToNewUids; private IProgressMonitor monitor; private ComponentUpdateProgressMonitor componentMonitor; private ReadGraph graph; - private int componentCount; + private int componentCount; private int counter; private UpdateComponentUids(IProgressMonitor monitor, ReadGraph graph, int componentCount) { @@ -32,10 +36,13 @@ public class UpdateComponentUids> { this.componentMonitor = monitor instanceof ComponentUpdateProgressMonitor ? (ComponentUpdateProgressMonitor) monitor : null; this.graph = graph; this.componentCount = componentCount; + this.oldToNewUids = new THashMap<>(componentCount); } private void update(T component, Variable variable) throws DatabaseException { - component.uid = variable.getRVI(graph).toString(); + String newUid = variable.getRVI(graph).toString(); + oldToNewUids.put(component.uid, newUid); + component.uid = newUid; // Handle progress monitoring and cancellation counter++; @@ -54,12 +61,14 @@ public class UpdateComponentUids> { } } - public static > void update(ReadGraph graph, T component, Variable variable) throws DatabaseException { - update(null, graph, component, variable); + public static > THashMap update(ReadGraph graph, T component, Variable variable) throws DatabaseException { + return update(null, graph, component, variable); } - public static > void update(IProgressMonitor monitor, ReadGraph graph, T component, Variable variable) throws DatabaseException { - new UpdateComponentUids(monitor, graph, countComponents(component)).update(component, variable); + public static > THashMap update(IProgressMonitor monitor, ReadGraph graph, T component, Variable variable) throws DatabaseException { + UpdateComponentUids updateComponentUids = new UpdateComponentUids(monitor, graph, countComponents(component)); + updateComponentUids.update(component, variable); + return updateComponentUids.oldToNewUids; } public static > int countComponents(T component) {