View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 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.ArrayList;
15  import java.util.List;
16  
17  import javax.swing.tree.TreeNode;
18  import javax.swing.tree.TreePath;
19  
20  /***
21   * 
22   * @author lars
23   */
24  public class TreePathUtils
25  {
26     public static TreePath getPath(TreeNode treeNode)
27     {
28        List<Object> nodes = new ArrayList<Object>();
29        if( treeNode != null )
30        {
31           nodes.add( treeNode );
32           treeNode = treeNode.getParent();
33           while( treeNode != null )
34           {
35              nodes.add( 0, treeNode );
36              treeNode = treeNode.getParent();
37           }
38        }
39  
40        return nodes.isEmpty() ? null : new TreePath( nodes.toArray() );
41     }
42  }