X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.interop.update%2Fsrc%2Forg%2Fsimantics%2Finterop%2Fupdate%2Fmodel%2FUpdateTree.java;fp=org.simantics.interop.update%2Fsrc%2Forg%2Fsimantics%2Finterop%2Fupdate%2Fmodel%2FUpdateTree.java;h=bf7e0688546beb2e053529ee30e54b41350b738d;hb=88fcf43b9eb2e217b50bf67cee58edaef4637a59;hp=a558f84462cf5e8cfe6548f761afa0c85cdb00fe;hpb=b2bf3445afe9519017f07e41da3c6bc2bccedc6f;p=simantics%2Finterop.git diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateTree.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateTree.java index a558f84..bf7e068 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateTree.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateTree.java @@ -3,6 +3,8 @@ package org.simantics.interop.update.model; import java.util.HashMap; import java.util.Map; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Session; @@ -29,17 +31,30 @@ public class UpdateTree { this.updateOps = updateOps; this.updateOps.populate(g); populate(g); + this.rootNode.sort(); } public UpdateTree(Session session, GraphChanges changes, UpdateOperations updateOps) throws DatabaseException { + this(session, changes, updateOps, new NullProgressMonitor()); + } + + public UpdateTree(Session session, GraphChanges changes, UpdateOperations updateOps, IProgressMonitor monitor) throws DatabaseException { this.changes = changes; this.nodes = new HashMap(); this.rootNode = session.syncRequest(new NodeRequest(UpdateStatus.EXIST, changes.getResource1())); nodes.put(changes.getResource1(), rootNode); nodes.put(changes.getResource2(), rootNode); this.updateOps = updateOps; - this.updateOps.populate(session); - populate(session); + this.updateOps.populate(session, monitor); + populate(session, monitor); + if (monitor.isCanceled()) { + this.changes = null; + this.nodes.clear(); + this.updateOps = null; + this.rootNode = null; + } else { + this.rootNode.sort(); + } } private class NodeRequest extends ResourceRead { @@ -176,9 +191,11 @@ public class UpdateTree { } } - protected void populate(Session session) throws DatabaseException{ + protected void populate(Session session, IProgressMonitor monitor) throws DatabaseException{ int i = 0; while (i < updateOps.getOperations().size()) { + if (monitor.isCanceled()) + return; i = session.syncRequest(new PopulateRead(i)); } }