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=17eee72ee6a40861c6ebb716bbfa8199fe62c384;hb=7010cce1f5f206a9dc74bdffa0ec6267d1be1d04;hp=51cd1eb4c0c338655e0f8dbc4777e58786dedd43;hpb=e9c2e1be3035e043674052acc916e1d3446114fb;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 51cd1eb..17eee72 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 @@ -14,8 +14,10 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.Statement; +import org.simantics.db.VirtualGraph; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.request.Read; @@ -48,6 +50,7 @@ public abstract class ModelUpdate { private List userFilters = new ArrayList(); boolean init = false; + private int chunkSize = -1; public void setInput(Resource oldModel, Resource newModel) throws DatabaseException { setInput(oldModel, newModel, null, false); @@ -82,6 +85,7 @@ public abstract class ModelUpdate { showWarning(result2.second); comparator2.test(getSession(), monitor); changes2 = comparator2.getChanges(); + comparator2.dispose(); if (monitor.isCanceled()) { dispose(); return; @@ -98,6 +102,7 @@ public abstract class ModelUpdate { showWarning(result3.second); comparator3.test(getSession(), monitor); changes3 = comparator3.getChanges(); + comparator2.dispose(); changes3 = getSession().syncRequest(createFilterRead(changes3, filters)); } if (monitor.isCanceled()) { @@ -150,6 +155,7 @@ public abstract class ModelUpdate { monitor.setTaskName("Processing changes..."); monitor.subTask(""); changes = comparator.getChanges(); + comparator.dispose(); changes = getSession().syncRequest(createFilterRead(changes, filters)); Pair chg = createChangeObjects(changes, monitor); if (chg == null) { @@ -169,6 +175,30 @@ public abstract class ModelUpdate { 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; + } + public void addFilter(ChangeFilter filter) { if (init) throw new IllegalStateException("ModelUpdate has been initialized, adjusting filters is no longer possible."); @@ -207,6 +237,14 @@ public abstract class ModelUpdate { return userFilters; } + public int getChunkSize() { + return chunkSize; + } + + public void setChunkSize(int chunkSize) { + this.chunkSize = chunkSize; + } + public void refreshUserFilters() throws DatabaseException{ // use user filters to set visible flags of changes. // First, set all changes visible. @@ -285,13 +323,13 @@ public abstract class ModelUpdate { return null; monitor.subTask("Processing structural changes"); } - UpdateTree updateTree = getUpdateTree(changes); + UpdateTree updateTree = getUpdateTree(changes, monitor); if (monitor != null) { if (monitor.isCanceled()) return null; monitor.subTask("Processing property changes"); } - UpdateList updateList = getUpdateList(changes); + UpdateList updateList = getUpdateList(changes, monitor); if (monitor != null) { if (monitor.isCanceled()) return null; @@ -301,8 +339,8 @@ public abstract class ModelUpdate { return new Pair(updateTree, updateList); } - protected abstract UpdateTree getUpdateTree(GraphChanges changes) throws DatabaseException; - protected UpdateList getUpdateList(GraphChanges changes) throws DatabaseException { + protected abstract UpdateTree getUpdateTree(GraphChanges changes, IProgressMonitor monitor) throws DatabaseException; + protected UpdateList getUpdateList(GraphChanges changes, IProgressMonitor monitor) throws DatabaseException { return new UpdateList(changes, changes.getModifications()); } @@ -375,30 +413,91 @@ public abstract class ModelUpdate { return updateNode3; } - public void applyAll(WriteGraph graph) throws DatabaseException { - Layer0Utils.addCommentMetadata(graph, "Apply all model updates"); - graph.markUndoPoint(); - for (PropertyChange mod : updateList.getChanges()) { - mod.apply(graph); - } + List list = updateList.getChanges(); + apply(graph, list, "Apply all model updates"); updateTree.getUpdateOps().applyAll(graph); } public void applySelected(WriteGraph graph) throws DatabaseException { - Layer0Utils.addCommentMetadata(graph, "Apply selected model updates"); - graph.markUndoPoint(); + List list = new ArrayList(); + for (PropertyChange mod : updateList.getChanges()) { + if (mod.selected()) + list.add(mod); + } + apply(graph, list, "Apply selected model updates"); updateTree.getUpdateOps().applySelected(graph); + } + + public void applyAll(Session session, VirtualGraph vg) throws DatabaseException { + List list = updateList.getChanges(); + apply(session, list, "Apply all model updates", vg); + updateTree.getUpdateOps().applyAll(session, vg); + } + + public void applySelected(Session session, VirtualGraph vg) throws DatabaseException { + List list = new ArrayList(); for (PropertyChange mod : updateList.getChanges()) { if (mod.selected()) - mod.apply(graph); + list.add(mod); } + apply(session, list, "Apply selected model updates", vg); + + updateTree.getUpdateOps().applySelected(session, vg); + } + protected void apply(WriteGraph graph, List list, String message) throws DatabaseException { + Layer0Utils.addCommentMetadata(graph, message); + graph.markUndoPoint(); + for (PropertyChange mod : list) { + mod.apply(graph); + } + } + protected void apply(Session session, List list, String message, VirtualGraph vg) throws DatabaseException { + if (getChunkSize() > 0) { + for (int s = 0; s < list.size(); ) { + int e = s + getChunkSize(); + if (e > list.size()) + e = list.size(); + List subList = updateList.getChanges().subList(e, e); + if (s == 0) { + session.syncRequest(new WriteRequest(vg) { + public void perform(WriteGraph graph) throws DatabaseException { + Layer0Utils.addCommentMetadata(graph, message); + graph.markUndoPoint(); + } + }); + } + session.syncRequest(new WriteRequest(vg) { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + for (PropertyChange mod : subList) { + mod.apply(graph); + } + } + }); + s = e; + } + } else { + session.syncRequest(new WriteRequest(vg) { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0Utils.addCommentMetadata(graph, message); + graph.markUndoPoint(); + for (PropertyChange mod : list) { + mod.apply(graph); + } + } + }); + } + } protected Session getSession() {