]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Allow binding statement changes to update operations
authorMarko Luukkainen <marko.luukkainen@vtt.fi>
Fri, 3 Mar 2017 11:17:31 +0000 (13:17 +0200)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Fri, 3 Mar 2017 11:17:31 +0000 (13:17 +0200)
refs #7045

Change-Id: I36cff7c0451cc19934f176ab6db4d30b41636cd4

org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java
org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateOp.java
org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateOperations.java

index a3b60332ce9e1552bbe68f9e14bdb182f65a86d1..8ecaaa77f36157d55d836c16ee25a63be5e693aa 100644 (file)
@@ -49,20 +49,17 @@ import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.DoesNotContainValueException;
 import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
-import org.simantics.db.exception.NoSingleResultException;
 import org.simantics.db.exception.ServiceException;
+import org.simantics.db.layer0.util.Layer0Utils;
 import org.simantics.db.request.Read;
 import org.simantics.interop.test.GraphChanges;
 import org.simantics.interop.test.GraphComparator;
-import org.simantics.interop.test.NameComparator;
 import org.simantics.interop.update.Activator;
 import org.simantics.interop.update.model.UpdateNode;
 import org.simantics.interop.update.model.UpdateNode.Status;
 import org.simantics.interop.update.model.UpdateTree;
 import org.simantics.interop.utils.TableUtils;
-import org.simantics.layer0.Layer0;
 import org.simantics.ui.workbench.ResourceEditorPart2;
-import org.simantics.utils.datastructures.BijectionMap;
 import org.simantics.utils.datastructures.Callback;
 import org.simantics.utils.datastructures.Pair;
 import org.simantics.utils.ui.ExceptionUtils;
@@ -401,6 +398,8 @@ public abstract class ModelUpdateEditor extends ResourceEditorPart2 {
                getSession().asyncRequest(new WriteRequest(){
                        @Override
                        public void perform(WriteGraph graph) throws DatabaseException {
+                               Layer0Utils.addCommentMetadata(graph, "Apply all model updates");
+                               graph.markUndoPoint();
                                for (Pair<Statement, Statement> mod : changes.getModifications()) {
                                        applyLiteralChange(graph, mod);
                                }
@@ -452,6 +451,8 @@ public abstract class ModelUpdateEditor extends ResourceEditorPart2 {
                getSession().asyncRequest(new WriteRequest(){
                        @Override
                        public void perform(WriteGraph graph) throws DatabaseException {
+                               Layer0Utils.addCommentMetadata(graph, "Apply selected model updates");
+                               graph.markUndoPoint();
                                for (Pair<Statement, Statement> mod : selected) {
                                        changes.getModifications().remove(mod);
                                        applyLiteralChange(graph, mod);
index 907741c23300b71a60b2504f26676363c05b61df..46bfcd298624c5384d679e4aeaae11520f3f3ed5 100644 (file)
@@ -63,9 +63,33 @@ public abstract class UpdateOp {
        public abstract boolean isAdd();
        public abstract boolean isDelete();
        
+       /**
+        * Is parent operation applied before this.
+        * @return
+        */
        public abstract boolean requiresParentOps();
+       /**
+        * Is child operation applied before this.
+        * @return
+        */
        public abstract boolean requiresSubOps(); 
        
+       /**
+        * Is parent operation selected when this is selected
+        * @return
+        */
+       public boolean selectParentOps() {
+               return requiresParentOps();
+       }
+       
+       /**
+        * Is child operation selected when this is selected
+        * @return
+        */
+       public boolean selectSubOps() {
+               return requiresSubOps();
+       }
+       
        public boolean select(boolean select) {
                boolean b = _select(select);
                if (b)
@@ -77,14 +101,14 @@ public abstract class UpdateOp {
                if (select == selected)
                        return true;
                if (select) {
-                       if (requiresParentOps()) {
+                       if (selectParentOps()) {
                                for (UpdateOp op : parentOps)
                                        op._select(true);
                        }
                        
                        selected = true;
                        manualSelection = false;
-                       if (requiresSubOps()) {
+                       if (selectSubOps()) {
                                for (UpdateOp op : subOps)
                                        op._select(true);
                        }
@@ -93,13 +117,13 @@ public abstract class UpdateOp {
                        selected = false;
                        manualSelection = false;
                        for (UpdateOp op : subOps) {
-                               if (op.requiresParentOps())
+                               if (op.selectParentOps())
                                        op._select(false);
                                else if (!op.manualSelection)
                                        op._select(false);
                        }
                        for (UpdateOp op : parentOps)
-                               if (op.requiresSubOps())
+                               if (op.selectSubOps())
                                        op._select(false);
                        return true;
                }
@@ -120,6 +144,12 @@ public abstract class UpdateOp {
                
        }
        
+       /**
+        * Applies the changes into the database.
+        * 
+        * @param g
+        * @throws DatabaseException
+        */
        protected abstract void _apply(WriteGraph g) throws DatabaseException;
        
        /**
index 9c929c59cc4f267d14d1cc5f867d05fce23c00d6..e24e0cba8a92653485eec00c67085041e53c0cb6 100644 (file)
@@ -21,7 +21,8 @@ import org.simantics.interop.test.GraphChanges;
 public abstract  class UpdateOperations {
        
        private List<UpdateOp> operations = new ArrayList<UpdateOp>();
-       private Map<Resource, UpdateOp> opMap = new HashMap<Resource, UpdateOp>();
+       private Map<Resource, UpdateOp> resourceMap = new HashMap<Resource, UpdateOp>();
+       private Map<Statement, UpdateOp> statementMap = new HashMap<Statement, UpdateOp>();
        private GraphChanges changes;
        
        public UpdateOperations(GraphChanges changes) {
@@ -29,7 +30,11 @@ public abstract  class UpdateOperations {
        }
        
        public UpdateOp getUpdateOp(Resource r) {
-               return opMap.get(r);
+               return resourceMap.get(r);
+       }
+       
+       public UpdateOp getUpdateOp(Statement s) {
+               return statementMap.get(s);
        }
        
        public void applyAll(WriteGraph g) throws DatabaseException {
@@ -61,8 +66,10 @@ public abstract  class UpdateOperations {
        private void _apply(WriteGraph g, Stack<UpdateOp> stack, UpdateOp op) throws DatabaseException {
                if (op.applied())
                        return;
-               if (stack.contains(op))
+               if (stack.contains(op)) {
+                       op.apply(g);
                        return;
+               }
                stack.push(op);
                if (op.requiresParentOps()) {
                        for (UpdateOp pop : op.getParentOps())
@@ -85,21 +92,30 @@ public abstract  class UpdateOperations {
        }
        
        protected void addOp(Resource r, UpdateOp op) {
-               opMap.put(r, op);
+               resourceMap.put(r, op);
+               operations.add(op);
+       }
+       
+       protected void addOp(Statement s, UpdateOp op) {
+               statementMap.put(s, op);
                operations.add(op);
        }
        
        protected void replaceOp(Resource r, UpdateOp op) {
-               UpdateOp oldOp = opMap.remove(r);
+               UpdateOp oldOp = resourceMap.remove(r);
                if (oldOp != null) {
                        operations.remove(oldOp);
                }
-               opMap.put(r, op);
+               resourceMap.put(r, op);
                operations.add(op);
        }
        
        protected UpdateOp getOP(Resource r) {
-               return opMap.get(r);
+               return resourceMap.get(r);
+       }
+       
+       protected UpdateOp getOP(Statement r) {
+               return statementMap.get(r);
        }
 
        public abstract void populate(ReadGraph g) throws DatabaseException;