]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/GETreeData.java
Sync git svn branch with SVN repository r33144.
[simantics/platform.git] / bundles / org.simantics.browsing.ui.nattable / src / org / simantics / browsing / ui / nattable / GETreeData.java
diff --git a/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/GETreeData.java b/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/GETreeData.java
new file mode 100644 (file)
index 0000000..956a2d1
--- /dev/null
@@ -0,0 +1,106 @@
+package org.simantics.browsing.ui.nattable;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.eclipse.nebula.widgets.nattable.tree.ITreeData;\r
+\r
+public class GETreeData implements ITreeData<TreeNode> {\r
+       List<TreeNode> list;\r
+       \r
+       public GETreeData(List<TreeNode> list) {\r
+               this.list = list;\r
+       }\r
+       \r
+       @Override\r
+       public String formatDataForDepth(int depth, TreeNode object) {\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public List<TreeNode> getChildren(TreeNode object) {\r
+               return (List<TreeNode>)object.getChildren();\r
+       }\r
+       \r
+       @Override\r
+       public TreeNode getDataAtIndex(int index) {\r
+               if (index < 0 || index >= list.size() )\r
+                       return null;\r
+               return list.get(index);\r
+       }\r
+       \r
+       @Override\r
+       public int getDepthOfData(TreeNode object) {\r
+               int count = object.getDepth()-1; // -1 removes invisible root.\r
+               return count;\r
+       }\r
+       \r
+       @Override\r
+       public boolean hasChildren(TreeNode object) {\r
+               return object.getChildren().size() > 0;\r
+       }\r
+       \r
+       @Override\r
+       public int indexOf(TreeNode child) {\r
+               return child.getListIndex();\r
+       }\r
+       \r
+       @Override\r
+       public boolean hasChildren(int index) {\r
+               return hasChildren(list.get(index));\r
+       }\r
+       \r
+       @Override\r
+       public String formatDataForDepth(int depth, int index) {\r
+               return formatDataForDepth(depth, list.get(index));\r
+       }\r
+       \r
+       @Override\r
+       public List<TreeNode> getChildren(int index) {\r
+               return getChildren(list.get(index));\r
+       }\r
+       \r
+       @Override\r
+       public List<TreeNode> getChildren(TreeNode object, boolean fullDepth) {\r
+               if (!fullDepth) {\r
+                       return getChildren(object);\r
+               } else {\r
+                       List<TreeNode> list = new ArrayList<TreeNode>();\r
+                       _convertToList(list, object);\r
+                       return list;\r
+               }\r
+               \r
+       }\r
+       private void _convertToList(List<TreeNode> list, TreeNode task) {\r
+               list.add(task);\r
+               for (TreeNode t : task.getChildren()) {\r
+                       _convertToList(list, t);\r
+               }\r
+       }\r
+       @Override\r
+       public int getDepthOfData(int index) {\r
+               return getDepthOfData(list.get(index));\r
+       }\r
+       \r
+       @Override\r
+       public boolean isValidIndex(int index) {\r
+               if (index < 0)\r
+                       return false;\r
+               if (index >= list.size())\r
+                       return false;\r
+               return true;\r
+       }\r
+       \r
+       @Override\r
+       public int getElementCount() {\r
+               return list.size();\r
+       }\r
+       \r
+       public boolean isRoot(TreeNode object) {\r
+               TreeNode parent = object.getParent();\r
+               parent = parent.getParent();\r
+               return (parent == null);\r
+       }\r
+\r
+       \r
+}
\ No newline at end of file