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=46bf79ecbcdeccd3679b684e924ca13e0214a5b1;hb=refs%2Fheads%2Frelease%2F1.32.1;hp=553396b48750f5d72f26e077c1dfc5d87779b827;hpb=51ca3975e1d4137e189e5e0beedc4efd137af142;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 553396b..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; @@ -20,15 +19,19 @@ import org.simantics.utils.datastructures.Pair; public abstract class ModelUpdate { - private GraphChanges changes; + private Resource oldModel; // old model that is going to be updated (User modified model) + private Resource newModel; // new model that contains the updates (New design model) + private Resource originalModel; // original model (optional) that is used for detecting and retaining user made changes (Old design model) + + private GraphChanges changes; // changes between old /new private UpdateTree updateTree; private UpdateList updateList; - private GraphChanges changes2; + private GraphChanges changes2; // changes between original / old private UpdateTree updateTree2; private UpdateList updateList2; - private GraphChanges changes3; + private GraphChanges changes3; // changes between original / new private UpdateTree updateTree3; private UpdateList updateList3; @@ -40,7 +43,18 @@ public abstract class ModelUpdate { setInput(oldModel, newModel, null, false); } + /** + * Initialises the ModelUpdate with given input + * @param oldModel the model that is going to be updated (User modified model) + * @param newModel the model containing updates (New design model) + * @param originalModel the model that is used for detecting and retaining user made changes (Old design model). Parameter can be null. + * @param newDistinct when originalModel is given, additions to the old and the new model (when compared to the original model) are forced to be distinct. + * @throws DatabaseException + */ public void setInput(Resource oldModel, Resource newModel, Resource originalModel, boolean newDistinct) throws DatabaseException{ + this.oldModel = oldModel; + this.newModel = newModel; + this.originalModel = originalModel; addFilters(filters); if (originalModel != null) { // tree way comparison @@ -110,7 +124,7 @@ public abstract class ModelUpdate { if (originalModel != null) { - createDefaultSelections(); + defaultSelections(); } init = true; @@ -121,13 +135,25 @@ 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) { } + public Resource getOldModel() { + return oldModel; + } + + public Resource getNewModel() { + return newModel; + } + + public Resource getOriginalModel() { + return originalModel; + } + public boolean isInit() { return init; } @@ -171,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); } @@ -182,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() { @@ -304,15 +315,18 @@ public abstract class ModelUpdate { } } - protected void createDefaultSelections() { + public void defaultSelections() { + if (changes3 == null) { + return; + } // select all changes for (Entry op : updateTree.getUpdateOps().getResourceMap().entrySet()) { op.getValue().select(true); } - for (Pair pair : updateList.getChanges()) { - updateList.addSelected(pair); + for (PropertyChange pair : updateList.getChanges()) { + pair.select(true); } // preserve user-made changes (by removing selections) @@ -328,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); } } }