]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Allow UpdateOps to describe parent resource 73/3773/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 13 Jan 2020 09:20:24 +0000 (11:20 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 13 Jan 2020 09:20:24 +0000 (11:20 +0200)
gitlab #21

Change-Id: Idef9b151b3719268e97c63a6376f0945a0a9a8d1

org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java
org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateOp.java

index b786586c9a3daef1c2b562707e1b07779d107a54..54d6b2ce670bc3f28d4e3fa75e73dc1adaf34522 100644 (file)
@@ -52,6 +52,11 @@ public class UpdateNode {
        }
        
        public Resource getParentResource(ReadGraph g) throws DatabaseException {
+               if (op != null) {
+                       Resource parent = op.getParentResource(g);
+                       if (parent != null)
+                               return parent;
+               }
                Layer0 l0 = Layer0.getInstance(g);
                return g.getPossibleObject(r, l0.PartOf);
        }
index 3b633c28cdfd5a017995ff7e2c1a364b9cc4d22f..2bd3718f6a39cc96d5741611e8cb85f3b5f59771 100644 (file)
@@ -4,11 +4,13 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.Statement;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.interop.test.GraphChanges;
+import org.simantics.layer0.Layer0;
 
 /**
  * Base class for update operations (adding and deleting objects)  
@@ -60,11 +62,15 @@ public abstract class UpdateOp {
        
        public void addParentOp(UpdateOp op) {
                assert (!op.equals(this));
+               if (parentOps.contains(op))
+                       return;
                parentOps.add(op);
        }
        
        public void addSubOp(UpdateOp op) {
                assert (!op.equals(this));
+               if (subOps.contains(op))
+                       return;
                subOps.add(op);
        }
        
@@ -212,6 +218,12 @@ public abstract class UpdateOp {
         */
        public abstract Resource getCreatedResource();
        
+       public Resource getParentResource(ReadGraph g) throws DatabaseException {
+               Layer0 l0 = Layer0.getInstance(g);
+               return g.getPossibleObject(getResource(), l0.PartOf);
+       }
+
+       
        @Override
     public String toString() {
         String s = this.getClass().getSimpleName();