]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
UpdateOp specific selection propagation 23/3623/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 22 Nov 2019 11:35:38 +0000 (13:35 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 26 Nov 2019 16:16:27 +0000 (16:16 +0000)
This implementation replaces previous, direction (parent/sub) specific
propagation.

This is API change, implementations must be updated.

gitlab #16

Change-Id: I1da59958636495ee2e9c90cc6b86ce0cfb99c186
(cherry picked from commit e75decb773efdb18e98b6951986c62adf52707f0)

org.simantics.interop.update/src/org/simantics/interop/update/model/AddDeleteUpdateOp.java
org.simantics.interop.update/src/org/simantics/interop/update/model/NopOp.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 901dc19ecbd027b25eead4cf6cc73efab4a82d18..854ad543a9f19f7d42f3e5eabdec96acdd9bacca 100644 (file)
@@ -35,13 +35,24 @@ public abstract class AddDeleteUpdateOp extends UpdateOp {
        }
        
        @Override
-       public boolean requiresParentOps() {
-               return add;
+       public boolean requiresOp(UpdateOp op) {
+           if (add) {
+               if (getParentOps().contains(op))
+                   return true;
+           } else {
+               if (getSubOps().contains(op))
+                return true;
+           }
+           return false;
        }
-
+       
        @Override
-       public boolean requiresSubOps() {
-               return !add;
+       public boolean selectOp(UpdateOp op, boolean select) {
+           if (select) {
+               return requiresOp(op);
+           } else {
+               return op.requiresOp(this);
+           }
        }
 
        protected static void copyProperties(WriteGraph g, Resource source, Resource destination) throws DatabaseException {
index f2316d53a8bdd702825d8be4566845333c560427..eec963421528e7b6fcc9889e8a2ccc72e930bd86 100644 (file)
@@ -51,13 +51,13 @@ public class NopOp extends UpdateOp{
        }
        
        @Override
-       public boolean requiresParentOps() {
-               return false;
+       public boolean requiresOp(UpdateOp op) {
+           return false;
        }
        
        @Override
-       public boolean requiresSubOps() {
-               return false;
+       public boolean selectOp(UpdateOp op, boolean select) {
+           return false;
        }
 
 }
index 6fba56723f2c5cf2cca45117643664eb30448991..50954ec1ffca968cc3e06a6dfbd1b09a59e4765e 100644 (file)
@@ -69,33 +69,25 @@ public abstract class UpdateOp {
        public boolean isChange() {
                return isAdd() || 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
+        * Should given operation to be applied before this operation.
+        * @param op
         * @return
         */
-       public boolean selectParentOps() {
-               return requiresParentOps();
+       public boolean requiresOp(UpdateOp op) {
+           return false;
        }
        
        /**
-        * Is child operation selected when this is selected
+        * Should selection state to be propagated to given op.
+        * @param op parent or sub op of this.
+        * @param select selection flag.
         * @return
         */
-       public boolean selectSubOps() {
-               return requiresSubOps();
-       }
+       public boolean selectOp(UpdateOp op, boolean select) {
+           return requiresOp(op);
+    }
        
        public boolean select(boolean select) {
            if (!enabled)
@@ -107,44 +99,44 @@ public abstract class UpdateOp {
                        manualSelection = true;
                return b;
        }
-       
+
        private boolean _select(boolean select) {
                if (select == selected)
                        return true;
                if (applied)
                        return false;
-               if (!isChange())
-                   return false;
                if (select) {
-                       if (selectParentOps()) {
-                               for (UpdateOp op : parentOps)
-                                       op._select(true);
-                       }
-                       
-                       selected = true;
-                       manualSelection = false;
-                       if (selectSubOps()) {
-                               for (UpdateOp op : subOps)
-                                       op._select(true);
-                       }
-                       
+                   selected = true;
+            manualSelection = false;
+                   for (UpdateOp op : parentOps) {
+                       if (selectOp(op,true))
+                   op._select(true);
+            }
+                       for (UpdateOp op : subOps) {
+                           if (selectOp(op,true))
+                   op._select(true);
+            }
+                       return true;
                } else {
                        selected = false;
                        manualSelection = false;
                        for (UpdateOp op : subOps) {
-                               if (op.selectParentOps())
-                                       op._select(false);
-                               else if (!op.manualSelection)
-                                       op._select(false);
-                       }
+                           if (selectOp(op, false))
+                    op._select(false);
+                else if (!op.manualSelection)
+                    op._select(false);
+            }
                        for (UpdateOp op : parentOps)
-                               if (op.selectSubOps())
-                                       op._select(false);
+                          if (selectOp(op, false))
+                  op._select(false);
                        return true;
                }
-               return false;
        }
+       
        public boolean selected() {
+           if (!isChange())
+               // Non change operations are not really selected, but the selected flag may be used for selection propagation
+               return false;
                return selected;
        }
        
@@ -202,5 +194,19 @@ public abstract class UpdateOp {
         * @return
         */
        public abstract Resource getCreatedResource();
+       
+       @Override
+    public String toString() {
+        String s = this.getClass().getSimpleName();
+        if (selected)
+            s += " selected";
+        if (enabled)
+            s += " enabled";
+        if (visible)
+            s += " visible";
+        if (applied)
+            s += " applied";
+        return s;
+    }
 
 }
index 0814ecf7fe524b0077c4cec85774af7d9c418144..0c1882c3fbcc38b6c7eadaeb5b88fa0f65ff146b 100644 (file)
@@ -79,16 +79,16 @@ public abstract  class UpdateOperations {
                        return;
                }
                stack.push(op);
-               if (op.requiresParentOps()) {
-                       for (UpdateOp pop : op.getParentOps())
-                               if (!pop.applied())
-                                       _apply(g, stack, pop);
-               
-               if (op.requiresSubOps()) {
-                       for (UpdateOp sop : op.getSubOps())
-                               if (!sop.applied())
-                                       _apply(g, stack, sop);
-               }
+               for (UpdateOp pop : op.getParentOps())
+                   if (op.requiresOp(pop)) {
+                if (!pop.applied())
+                    _apply(g, stack, pop);
+        } 
+               for (UpdateOp sop : op.getSubOps())
+                   if (op.requiresOp(sop)) {
+                if (!sop.applied())
+                    _apply(g, stack, sop);
+        }
                stack.pop();
                op.apply(g);
        }