]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/TreeNode.java
Sync git svn branch with SVN repository r33334.
[simantics/platform.git] / bundles / org.simantics.browsing.ui.nattable / src / org / simantics / browsing / ui / nattable / TreeNode.java
index 941c6f319be56e491909cc35472e7173a5040ccf..30a37e3292205da607911c2d757528bf555d47f5 100644 (file)
@@ -38,6 +38,7 @@ public class TreeNode implements IAdaptable {
        TreeNode parent;\r
        List<TreeNode> children = new ArrayList<TreeNode>();\r
        boolean expanded;\r
+       boolean autoExpanded = false;\r
        \r
        public TreeNode(NodeContext context, GeViewerContext explorerContext) {\r
                this.context = context;\r
@@ -47,13 +48,13 @@ public class TreeNode implements IAdaptable {
                explorerContext.getContextToNodeMap().add(context, this);\r
        }\r
        \r
-       int getDepth() {\r
+       public int getDepth() {\r
                if (parent == null)\r
                        return 0;\r
                return parent.getDepth() + 1;\r
        }\r
        \r
-       int listIndex;\r
+       int listIndex = -1;\r
        \r
        public int getListIndex() {\r
                return listIndex;\r
@@ -79,6 +80,27 @@ public class TreeNode implements IAdaptable {
                return expanded;\r
        }\r
        \r
+       public boolean isHidden() {\r
+               TreeNode n = parent;\r
+               while (n != null) {\r
+                       if (!n.isExpanded())\r
+                               return true;\r
+                       n = n.getParent();\r
+               }\r
+               return false;\r
+       }\r
+       \r
+       public TreeNode getCollapsedAncestor() {\r
+               TreeNode collapsed = null;\r
+               TreeNode n = parent;\r
+               while (n != null) {\r
+                       if (!n.isExpanded())\r
+                               collapsed = n;\r
+                       n = n.getParent();\r
+               }\r
+               return collapsed;\r
+       }\r
+       \r
        public NodeContext getContext() {\r
                return context;\r
        }\r
@@ -92,9 +114,8 @@ public class TreeNode implements IAdaptable {
        Map<String, String> runtimeLabels;\r
        \r
        public String getValueString(int column) {\r
-               if (column == 0) {\r
+               if (column == 0)\r
                        initData();\r
-               }\r
                if (labeler != null) {\r
                        String key = explorerContext.getGe().getColumns()[column].getKey();\r
                        String s = null;\r
@@ -199,7 +220,7 @@ public class TreeNode implements IAdaptable {
 \r
        }\r
        \r
-       private void initData() {\r
+       public void initData() {\r
                labeler = manager.query(context, BuiltinKeys.SELECTED_LABELER);\r
                imager = manager.query(context, BuiltinKeys.SELECTED_IMAGER);\r
                labelDecorators = manager.query(context, BuiltinKeys.LABEL_DECORATORS);\r
@@ -319,7 +340,13 @@ public class TreeNode implements IAdaptable {
                                \r
                        }\r
                        for (int i = oldCount; i < childContexts.length; i++) {\r
-                               addChild(childContexts[i], explorerContext);\r
+                               Integer oldIndex = indexes.getLeft(i);\r
+                               if (oldIndex == null) {\r
+                                       addChild(childContexts[i], explorerContext);\r
+                               } else {\r
+                                       TreeNode n = oldChildren.get(oldIndex);\r
+                                       children.add(n);\r
+                               }\r
                        }\r
                        } else {\r
                                for (int i = 0; i < childContexts.length; i++) {\r
@@ -363,5 +390,10 @@ public class TreeNode implements IAdaptable {
                \r
                return context.getAdapter(adapter);\r
        }\r
+       \r
+       @Override\r
+       public String toString() {\r
+               return "TreeNode: " + listIndex + " " + (expanded ? "(+)" : "(-)") + " " + context ;\r
+       }\r
 \r
 }\r