]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java
Allow UpdateOps to describe parent resource
[simantics/interop.git] / org.simantics.interop.update / src / org / simantics / interop / update / model / UpdateNode.java
index 486b3a1ec204b882db7dbd0e86c4d4addeb9b66c..54d6b2ce670bc3f28d4e3fa75e73dc1adaf34522 100644 (file)
@@ -12,10 +12,12 @@ import org.simantics.layer0.Layer0;
 
 public class UpdateNode {
 
+    private UpdateNode parent;
        private UpdateStatus status;
        private UpdateOp op;
        private Resource r;
        private String label;
+       private boolean visible = true;
        
        
        private Collection<UpdateNode> children = new ArrayList<UpdateNode>();
@@ -50,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);
        }
@@ -68,6 +75,7 @@ public class UpdateNode {
        
        public void addChild(UpdateNode node) {
                children.add(node);
+               node.parent = this;
                if (op != null && node.op != null) {
                        if (!op.getSubOps().contains(node.op)) {
                                op.addSubOp(node.op);
@@ -101,5 +109,30 @@ public class UpdateNode {
        public UpdateOp getOp() {
                return op;
        }
+       
+       public boolean isVisible() {
+               return visible;
+       }
+       
+       public void setVisible(boolean visible) {
+               this.visible = visible;
+               if (op != null)
+                       op.visible = visible;
+               if (visible) {
+                   if (parent != null && !parent.visible)
+                       parent.setVisible(true);
+               } else {
+                   for (UpdateNode n : children)
+                       n.setVisible(false);
+               }
+       }
+       
+       public void setAllVisible(boolean visible) {
+        this.visible = visible;
+        if (op != null)
+            op.visible = visible;
+        for (UpdateNode n : children)
+             n.setAllVisible(visible);
+    }
 
 }