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  
13  
14  package com.eviware.soapui.support.dnd;
15  
16  import java.awt.Component;
17  
18  import javax.swing.JTree;
19  import javax.swing.tree.TreePath;
20  
21  import com.eviware.soapui.SoapUI;
22  import com.eviware.soapui.model.ModelItem;
23  import com.eviware.soapui.model.tree.SoapUITreeNode;
24  
25  public class NavigatorDragAndDropable extends JTreeDragAndDropable<ModelItem>
26  {
27  	public NavigatorDragAndDropable( JTree tree )
28  	{
29  		super( tree );
30  	}
31  
32  	@Override
33  	public ModelItem getModelItemAtRow( int row )
34  	{
35  		TreePath pathForRow = getTree().getPathForRow( row );
36  		return pathForRow == null ? null : ( ( SoapUITreeNode ) pathForRow.getLastPathComponent() ).getModelItem();
37  	}
38  
39  	@Override
40  	public int getRowForModelItem( ModelItem modelItem )
41  	{
42  		if( modelItem == null )
43  			return -1;
44  
45  		TreePath treePath = SoapUI.getNavigator().getTreePath( modelItem );
46  		return getTree().getRowForPath( treePath );
47  	}
48  
49  	public Component getRenderer( ModelItem modelItem )
50  	{
51  		TreePath treePath = SoapUI.getNavigator().getTreePath( modelItem );
52  		int row = getTree().getRowForPath( treePath );
53  		SoapUITreeNode treeNode = ( SoapUITreeNode ) treePath.getLastPathComponent();
54  
55  		return getTree().getCellRenderer().getTreeCellRendererComponent( getTree(), treeNode, true,
56  					getTree().isExpanded( row ), treeNode.isLeaf(), row, true );
57  	}
58  
59  	@Override
60  	public void toggleExpansion( ModelItem last )
61  	{
62  		if( last == SoapUI.getWorkspace() )
63  			return;
64  
65  		super.toggleExpansion( last );
66  	}
67  }