FrameworkDirectoryNode (FrameworkDirectoryNode node) { if (node.getChildCount() == 1) { final TreeNode child = node.getChildAt(0); if (child instanceof FrameworkDirectoryNode) { return collapseDirectoryNode((FrameworkDirectoryNode)child); } } for (int i = 0; i < node.getChildCount(); i++) { TreeNode child = node.getChildAt(i); if (child instanceof FrameworkDirectoryNode) { final FrameworkDirectoryNode collapsed = collapseDirectoryNode((FrameworkDirectoryNode)child); if (collapsed != child) { node.remove(i); node.insert(collapsed, i); } } } return node; }