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