View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
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  		// Traverse children
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  		// Expansion or collapse must be done bottom-up
40  		if( expand )
41  		{
42  			tree.expandPath( parent );
43  		}
44  		else
45  		{
46  			tree.collapsePath( parent );
47  		}
48  	}
49  }