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;fp=org.simantics.interop.update%2Fsrc%2Forg%2Fsimantics%2Finterop%2Fupdate%2Fmodel%2FModelUpdate.java;h=46bf79ecbcdeccd3679b684e924ca13e0214a5b1;hb=b0205b09bbd81755eb69452eae0142d5a93f95a4;hp=bf391d49e52e8a1fd367f1fbbfac29758b696314;hpb=6fd88055dcf1a4982cc607222e77907a786173a8;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 bf391d4..46bf79e 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 @@ -1,7 +1,6 @@ package org.simantics.interop.update.model; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Map.Entry; @@ -136,7 +135,7 @@ public abstract class ModelUpdate { protected abstract Pair getChanges(Resource r1, Resource r2) throws DatabaseException; protected abstract UpdateTree getUpdateTree(GraphChanges changes) throws DatabaseException; protected UpdateList getUpdateList(GraphChanges changes) throws DatabaseException { - return new UpdateList(changes.getModifications()); + return new UpdateList(changes, changes.getModifications()); } protected void addFilters(List filters) { @@ -198,10 +197,9 @@ public abstract class ModelUpdate { public void applyAll(WriteGraph graph) throws DatabaseException { Layer0Utils.addCommentMetadata(graph, "Apply all model updates"); graph.markUndoPoint(); - for (Pair mod : updateList.getChanges()) { - applyLiteralChange(graph, mod); + for (PropertyChange mod : updateList.getChanges()) { + mod.apply(graph); } - updateList.clear(); updateTree.getUpdateOps().applyAll(graph); } @@ -209,29 +207,15 @@ public abstract class ModelUpdate { public void applySelected(WriteGraph graph) throws DatabaseException { Layer0Utils.addCommentMetadata(graph, "Apply selected model updates"); graph.markUndoPoint(); - HashSet> changes = new HashSet<>(updateList.getSelected()); - for (Pair mod : changes) { - updateList.removeChange(mod); - applyLiteralChange(graph, mod); + for (PropertyChange mod : updateList.getChanges()) { + if (mod.selected()) + mod.apply(graph); } updateTree.getUpdateOps().applySelected(graph); } - protected void applyLiteralChange(WriteGraph graph, Pair mod) throws DatabaseException { - if (mod.second == null) { - graph.deny(mod.first); - return; - } - Resource s = changes.getComparable().getLeft(mod.second.getSubject()); - Resource pred = mod.second.getPredicate(); - if (graph.hasValue(mod.second.getObject())) { - Object value = graph.getValue(mod.second.getObject()); - graph.claimLiteral(s, pred, value); - } else { - graph.deny(s,pred); - } - } + protected Session getSession() { @@ -341,8 +325,8 @@ public abstract class ModelUpdate { } - for (Pair pair : updateList.getChanges()) { - updateList.addSelected(pair); + for (PropertyChange pair : updateList.getChanges()) { + pair.select(true); } // preserve user-made changes (by removing selections) @@ -358,17 +342,17 @@ public abstract class ModelUpdate { } } - for (Pair pair : updateList.getChanges()) { - if (pair.first != null) { + for (PropertyChange pair : updateList.getChanges()) { + if (pair.getFirst() != null) { boolean found = false; - for (Pair pair2 : updateList2.getChanges()) { - if (pair.first.equals(pair2.second)) { + for (PropertyChange pair2 : updateList2.getChanges()) { + if (pair.getFirst().equals(pair2.getSecond())) { found = true; break; } } if (found) { - updateList.removeSelected(pair); + pair.select(false); } } }