X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.interop.update%2Fsrc%2Forg%2Fsimantics%2Finterop%2Fupdate%2Fmodel%2FModelUpdate.java;h=6e5175707080e7f5587c7b9ea7d52b5ab4b43261;hb=1b3fe1c5f30f4c373cd55df131d3774fe33150ab;hp=ff56d43ea6f6bd3ac1430dc3ee959b5eb4428ef4;hpb=a4470f2cf50c3f6d4c586930ccd8eaa55ded25a5;p=simantics%2Finterop.git diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/ModelUpdate.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/ModelUpdate.java index ff56d43..6e51757 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/model/ModelUpdate.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/ModelUpdate.java @@ -7,6 +7,8 @@ import java.util.Deque; import java.util.List; import java.util.Map.Entry; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; import org.simantics.Simantics; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -60,9 +62,16 @@ public abstract class ModelUpdate { * @throws DatabaseException */ public void setInput(Resource oldModel, Resource newModel, Resource originalModel, boolean newDistinct) throws DatabaseException{ + this.setInput(oldModel, newModel, originalModel, newDistinct, null); + } + public void setInput(Resource oldModel, Resource newModel, Resource originalModel, boolean newDistinct, IProgressMonitor monitor) throws DatabaseException{ + this.oldModel = oldModel; this.newModel = newModel; this.originalModel = originalModel; + + if (monitor == null) + monitor = new NullProgressMonitor(); // addFilters(filters); if (originalModel != null) { // tree way comparison @@ -71,10 +80,14 @@ public abstract class ModelUpdate { GraphComparator comparator2 = result2.first; if (result2.second != null) showWarning(result2.second); - comparator2.test(getSession()); + comparator2.test(getSession(), monitor); changes2 = comparator2.getChanges(); + if (monitor.isCanceled()) { + dispose(); + return; + } changes2 = getSession().syncRequest(createFilterRead(changes2, filters)); - Pair chg2 = createChangeObjects(changes2); + Pair chg2 = createChangeObjects(changes2, null); updateTree2 = chg2.first; updateList2 = chg2.second; @@ -83,10 +96,14 @@ public abstract class ModelUpdate { GraphComparator comparator3 = result3.first; if (result3.second != null) showWarning(result3.second); - comparator3.test(getSession()); + comparator3.test(getSession(), monitor); changes3 = comparator3.getChanges(); changes3 = getSession().syncRequest(createFilterRead(changes3, filters)); } + if (monitor.isCanceled()) { + dispose(); + return; + } Pair result = getChanges(oldModel,newModel); GraphComparator comparator = result.first; @@ -125,10 +142,20 @@ public abstract class ModelUpdate { } } } - comparator.test(getSession()); + if (monitor.isCanceled()) { + dispose(); + return; + } + comparator.test(getSession(), monitor); + monitor.setTaskName("Processing changes..."); + monitor.subTask(""); changes = comparator.getChanges(); changes = getSession().syncRequest(createFilterRead(changes, filters)); - Pair chg = createChangeObjects(changes); + Pair chg = createChangeObjects(changes, monitor); + if (chg == null) { + dispose(); + return; + } updateTree = chg.first; updateList = chg.second; if (userFilters.size() != 0) { @@ -139,7 +166,30 @@ public abstract class ModelUpdate { if (originalModel != null) { defaultSelections(); } + init = true; + } + + public void setInput(Resource oldModel, Resource newModel, GraphChanges changes, IProgressMonitor monitor) throws DatabaseException{ + if (!oldModel.equals(changes.getResource1()) || + !newModel.equals(changes.getResource2())) { + throw new DatabaseException("GraphChanges does not match input models"); + } + this.changes = getSession().syncRequest(createFilterRead(changes, filters)); + Pair chg = createChangeObjects(changes, monitor); + if (chg == null) { + dispose(); + return; + } + updateTree = chg.first; + updateList = chg.second; + if (userFilters.size() != 0) { + refreshUserFilters(); + } + + if (originalModel != null) { + defaultSelections(); + } init = true; } @@ -253,9 +303,24 @@ public abstract class ModelUpdate { protected abstract Pair getChanges(Resource r1, Resource r2) throws DatabaseException; - protected Pair createChangeObjects(GraphChanges changes) throws DatabaseException{ - UpdateTree updateTree = getUpdateTree(changes); + protected Pair createChangeObjects(GraphChanges changes, IProgressMonitor monitor) throws DatabaseException{ + if (monitor != null) { + if (monitor.isCanceled()) + return null; + monitor.subTask("Processing structural changes"); + } + UpdateTree updateTree = getUpdateTree(changes); + if (monitor != null) { + if (monitor.isCanceled()) + return null; + monitor.subTask("Processing property changes"); + } UpdateList updateList = getUpdateList(changes); + if (monitor != null) { + if (monitor.isCanceled()) + return null; + monitor.subTask("Postprocessing changes"); + } postProcess(updateTree, updateList); return new Pair(updateTree, updateList); } @@ -312,7 +377,7 @@ public abstract class ModelUpdate { public UpdateTree getUpdateTree3() throws DatabaseException{ if (updateTree3 == null && changes3 != null) { - Pair chg3 = createChangeObjects(changes3); + Pair chg3 = createChangeObjects(changes3, null); updateTree3 = chg3.first; updateList3 = chg3.second; } @@ -320,9 +385,9 @@ public abstract class ModelUpdate { } public UpdateList getUpdateList3() throws DatabaseException { if (updateList3 == null && changes3 != null) { - Pair chg3 = createChangeObjects(changes3); - updateTree3 = chg3.first; - updateList3 = chg3.second; + Pair chg3 = createChangeObjects(changes3, null); + updateTree3 = chg3.first; + updateList3 = chg3.second; } return updateList3; } @@ -491,6 +556,8 @@ public abstract class ModelUpdate { @Override public boolean accept(ReadGraph g, Modification change) throws DatabaseException { //filter floating point values that have less than 1% difference. + if (change.getLeftStm() == null || change.getRightStm() == null) + return true; if (!g.hasValue(change.getLeftStm().getObject()) || !g.hasValue(change.getRightStm().getObject())) return true; Object v1 = g.getValue(change.getLeftStm().getObject()); @@ -584,4 +651,20 @@ public abstract class ModelUpdate { public void removeListener(WarningListener listener) { warningListeners.remove(listener); } + + public void dispose() { + changes = null; + changes2 = null; + changes3 = null; + filters = null; + userFilters = null; + updateList = null; + updateList2 = null; + updateList3 = null; + updateTree = null; + updateTree2 = null; + updateTree3 = null; + updateNode3 = null; + init = false; + } }