1
2
3
4
5
6
7
8
9
10
11
12 package com.eviware.soapui.support.swing;
13
14 import java.util.Enumeration;
15
16 import javax.swing.JTree;
17 import javax.swing.tree.TreeNode;
18 import javax.swing.tree.TreePath;
19
20 /***
21 *
22 */
23 public class TreeUtils
24 {
25 public static void expandAll(JTree tree, TreePath parent, boolean expand)
26 {
27
28 TreeNode node = (TreeNode) parent.getLastPathComponent();
29 if (node.getChildCount() >= 0)
30 {
31 for(Enumeration e = node.children(); e.hasMoreElements(); )
32 {
33 TreeNode n = (TreeNode) e.nextElement();
34 TreePath path = parent.pathByAddingChild(n);
35 expandAll(tree, path, expand);
36 }
37 }
38
39
40 if (expand)
41 {
42 tree.expandPath(parent);
43 }
44 else
45 {
46 tree.collapsePath(parent);
47 }
48 }
49 }