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=f3fbdda5b13877a3705b55901e1057aab3bb726a;hb=refs%2Fchanges%2F43%2F4643%2F1;hp=7cd2afd06784e49dacdd1b7a2d31b721af66357f;hpb=c276677539e2b4111a072a2e6f6c4e8aa3e65b30;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 7cd2afd..f3fbdda 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 @@ -74,8 +74,9 @@ public abstract class ModelUpdate { comparator2.test(getSession()); changes2 = comparator2.getChanges(); changes2 = getSession().syncRequest(createFilterRead(changes2, filters)); - updateTree2 = getUpdateTree(changes2); - updateList2 = getUpdateList(changes2); + Pair chg2 = createChangeObjects(changes2); + updateTree2 = chg2.first; + updateList2 = chg2.second; // compare the original and the new model Pair result3 = getChanges(originalModel,newModel); @@ -127,8 +128,9 @@ public abstract class ModelUpdate { comparator.test(getSession()); changes = comparator.getChanges(); changes = getSession().syncRequest(createFilterRead(changes, filters)); - updateTree = getUpdateTree(changes); - updateList = getUpdateList(changes); + Pair chg = createChangeObjects(changes); + updateTree = chg.first; + updateList = chg.second; if (userFilters.size() != 0) { refreshUserFilters(); } @@ -250,11 +252,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); + UpdateList updateList = getUpdateList(changes); + postProcess(updateTree, updateList); + return new Pair(updateTree, updateList); + } + protected abstract UpdateTree getUpdateTree(GraphChanges changes) throws DatabaseException; protected UpdateList getUpdateList(GraphChanges changes) throws DatabaseException { return new UpdateList(changes, changes.getModifications()); } + + protected void postProcess(UpdateTree updateTree, UpdateList updateList) throws DatabaseException{ + + } + public Resource getOldModel() { return oldModel; } @@ -296,13 +311,19 @@ public abstract class ModelUpdate { } public UpdateTree getUpdateTree3() throws DatabaseException{ - if (updateTree3 == null && changes3 != null) - updateTree3 = getUpdateTree(changes3); + if (updateTree3 == null && changes3 != null) { + Pair chg3 = createChangeObjects(changes3); + updateTree3 = chg3.first; + updateList3 = chg3.second; + } return updateTree3; } public UpdateList getUpdateList3() throws DatabaseException { - if (updateList3 == null && changes3 != null) - updateList3 = getUpdateList(changes3); + if (updateList3 == null && changes3 != null) { + Pair chg3 = createChangeObjects(changes3); + updateTree3 = chg3.first; + updateList3 = chg3.second; + } return updateList3; } @@ -327,12 +348,13 @@ public abstract class ModelUpdate { public void applySelected(WriteGraph graph) throws DatabaseException { Layer0Utils.addCommentMetadata(graph, "Apply selected model updates"); graph.markUndoPoint(); + + updateTree.getUpdateOps().applySelected(graph); + for (PropertyChange mod : updateList.getChanges()) { if (mod.selected()) mod.apply(graph); } - - updateTree.getUpdateOps().applySelected(graph); } @@ -469,6 +491,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()); @@ -562,4 +586,19 @@ 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; + } }