]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java
Process changes in smaller chunks
[simantics/interop.git] / org.simantics.interop.update / src / org / simantics / interop / update / model / UpdateNode.java
index 54d6b2ce670bc3f28d4e3fa75e73dc1adaf34522..f68f887dca33c98e925862c203dab27926ae5480 100644 (file)
@@ -1,7 +1,9 @@
 package org.simantics.interop.update.model;
 
 import java.util.ArrayList;
-import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
 
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.simantics.db.ReadGraph;
@@ -20,7 +22,7 @@ public class UpdateNode {
        private boolean visible = true;
        
        
-       private Collection<UpdateNode> children = new ArrayList<UpdateNode>();
+       private List<UpdateNode> children;
        /**
         * 
         * @param resource old Resource if status is DELETED or EXISTS.
@@ -69,11 +71,16 @@ public class UpdateNode {
                return status;
        }
        
-       public Collection<UpdateNode> getChildren() {
+       @SuppressWarnings("unchecked")
+       public List<UpdateNode> getChildren() {
+               if (children == null)
+                       return Collections.EMPTY_LIST;
                return children;
        }
        
        public void addChild(UpdateNode node) {
+               if (children == null)
+                       children = new ArrayList<UpdateNode>(2);
                children.add(node);
                node.parent = this;
                if (op != null && node.op != null) {
@@ -83,6 +90,17 @@ public class UpdateNode {
                        }
                }
        }
+       
+       public void sort() {
+               if (children == null)
+                       return;
+               Collections.sort(this.children, new Comparator<UpdateNode>() {
+                       @Override
+                       public int compare(UpdateNode o1, UpdateNode o2) {
+                               return o1.getLabel().compareTo(o2.getLabel());
+                       }
+               });
+       }
 
        public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException {
                return null;
@@ -122,17 +140,19 @@ public class UpdateNode {
                    if (parent != null && !parent.visible)
                        parent.setVisible(true);
                } else {
-                   for (UpdateNode n : children)
-                       n.setVisible(false);
+                       if (children != null)
+                               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);
-    }
+               this.visible = visible;
+               if (op != null)
+                       op.visible = visible;
+               if (children != null)
+                       for (UpdateNode n : children)
+                               n.setAllVisible(visible);
+       }
 
 }