List of utility methods to do JTree Path
String | checkNode(TreePath path) check Node String type = ""; if (null != path) { TreePath parentPath = path.getParentPath(); DefaultMutableTreeNode currNode = (DefaultMutableTreeNode) path.getLastPathComponent(); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) parentPath.getLastPathComponent(); if (("My Flows".equals(currNode.getUserObject()) || "Company Flows".equals(currNode.getUserObject())) && parentNode.isRoot()) { type = ADD_FOLDER_NEW_FLOW; ... |
TreePath | createTreePath(TreeNode treeNode) create Tree Path List<TreeNode> list = new ArrayList<TreeNode>(); list.add(treeNode); TreeNode parent = treeNode.getParent(); while (parent != null) { list.add(0, parent); parent = parent.getParent(); return new TreePath(list.toArray()); ... |
TreePath | createTreePathFromTreeNode(TreeNode treeNode) create Tree Path From Tree Node ArrayList<TreeNode> list = new ArrayList<TreeNode>(); do { list.add(treeNode); treeNode = treeNode.getParent(); } while (treeNode != null); Collections.reverse(list); return new TreePath(list.toArray(new Object[list.size()])); |
void | doNode(JTree tree, TreeNode parentNode, TreePath parentPath) do Node if (parentNode.getChildCount() > 0) { for (Enumeration e = parentNode.children(); e.hasMoreElements();) { TreeNode childNode = (TreeNode) e.nextElement(); TreePath path = parentPath.pathByAddingChild(childNode); tree.expandPath(path); doNode(tree, childNode, path); |
TreePath | find2(JTree tree, TreePath parent, Object[] nodes, int depth, boolean byName) find TreeNode node = (TreeNode) parent.getLastPathComponent(); Object o = node; if (o == null) return null; if (byName) { o = o.toString(); System.err.println(o + " : " + nodes[depth]); ... |
DefaultMutableTreeNode | findOrAddNode(JTree tree, TreePath parent, String packageName) find Or Add Node final DefaultMutableTreeNode node = (DefaultMutableTreeNode) parent.getLastPathComponent(); for (final Enumeration e = node.children(); e.hasMoreElements();) { final DefaultMutableTreeNode n = (DefaultMutableTreeNode) e.nextElement(); if (packageName.equals(n.toString())) return n; final DefaultMutableTreeNode nodeCls = new DefaultMutableTreeNode(packageName); node.add(nodeCls); ... |
TreePath | findTreePath(TreePath path, TreeNode node, String pathName) find Tree Path if (path == null || pathName == null || node == null) { return null; if (pathName.equals(getTreePathString(path))) { return path; if (node.getChildCount() >= 0) { for (Enumeration<?> e = node.children(); e.hasMoreElements();) { ... |
DefaultMutableTreeNode | findV2MetaTreeNode(String nodeXmlPath) find V Meta Tree Node return elementNodehash.get(nodeXmlPath);
|
int | getDepth(JTree tree) get Depth TreeNode root = (TreeNode) tree.getModel().getRoot(); if (root.getChildCount() == 0) return 0; else return 1 + getDepth(root.getChildAt(0)); |
Enumeration | getExpatnedTreePaths(JTree tree) Method to be used in conjunction with #expandTreePaths(JTree,Enumeration) TreePath pathToRoot = new TreePath(tree.getModel().getRoot()); Enumeration<TreePath> expandPaths = tree.getExpandedDescendants(pathToRoot); return expandPaths; |