]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.interop.update/src/org/simantics/interop/update/model/ModelUpdate.java
PropertyChange class (instead of Pair)
[simantics/interop.git] / org.simantics.interop.update / src / org / simantics / interop / update / model / ModelUpdate.java
index bf391d49e52e8a1fd367f1fbbfac29758b696314..46bf79ecbcdeccd3679b684e924ca13e0214a5b1 100644 (file)
@@ -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<GraphComparator,String> 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<ChangeFilter> 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<Statement, Statement> 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<Pair<Statement, Statement>> changes = new HashSet<>(updateList.getSelected());
-               for (Pair<Statement, Statement> 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<Statement, Statement> 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<Statement, Statement> 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<Statement, Statement> pair : updateList.getChanges()) {
-                       if (pair.first != null) {
+               for (PropertyChange pair : updateList.getChanges()) {
+                       if (pair.getFirst() != null) {
                                boolean found = false;
-                               for (Pair<Statement, Statement> 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);
                                }
                        }
                }