X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.structural.synchronization.client%2Fsrc%2Forg%2Fsimantics%2Fstructural%2Fsynchronization%2Fbase%2FUpdateComponentUids.java;fp=bundles%2Forg.simantics.structural.synchronization.client%2Fsrc%2Forg%2Fsimantics%2Fstructural%2Fsynchronization%2Fbase%2FUpdateComponentUids.java;h=0000000000000000000000000000000000000000;hb=e4007b17057ff4acc2e900c5c811743b74f71f41;hp=df63ada0525911d50cd84c636989f1fe8e30d34c;hpb=3fe6778c21d6437e90d08987de6dae7bca89bc6d;p=simantics%2Fplatform.git 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 deleted file mode 100644 index df63ada05..000000000 --- a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.simantics.structural.synchronization.base; - -import org.eclipse.core.runtime.IProgressMonitor; -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 - */ -public class UpdateComponentUids> { - - public static interface ComponentUpdateProgressMonitor { - void componentsDone(int components, int componentCount); - } - - private THashMap oldToNewUids; - private IProgressMonitor monitor; - private ComponentUpdateProgressMonitor componentMonitor; - private ReadGraph graph; - private int componentCount; - private int counter; - - private UpdateComponentUids(IProgressMonitor monitor, ReadGraph graph, int componentCount) { - this.monitor = monitor; - 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 { - String newUid = variable.getRVI(graph).toString(); - oldToNewUids.put(component.uid, newUid); - component.uid = newUid; - - // Handle progress monitoring and cancellation - counter++; - if (monitor != null) { - if (componentMonitor != null) - componentMonitor.componentsDone(counter, componentCount); - if (monitor.isCanceled()) - throw new CancelTransactionException(); - } - - for(Variable childVariable : variable.getChildren(graph)) { - String childName = childVariable.getName(graph); - T childComponent = component.getChild(childName); - if(childComponent != null) - update(childComponent, childVariable); - } - } - - public static > THashMap update(ReadGraph graph, T component, Variable variable) throws DatabaseException { - return update(null, graph, 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) { - return new Counter().count(component); - } - - private static class Counter> { - int counter; - int count(T component) { - ++counter; - for (T child : component.getChildren()) - count(child); - return counter; - } - } - -}