View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 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.model.tree;
14  
15  import java.awt.Component;
16  
17  import javax.swing.ImageIcon;
18  import javax.swing.JTree;
19  import javax.swing.tree.DefaultTreeCellRenderer;
20  
21  import com.eviware.soapui.model.ModelItem;
22  import com.eviware.soapui.model.testsuite.TestStep;
23  import com.eviware.soapui.support.Tools;
24  
25  /***
26   * TreeCellRenderer for SoapUITreeNodes
27   * 
28   * @author Ole.Matzura
29   */
30  
31  public class SoapUITreeNodeRenderer extends DefaultTreeCellRenderer
32  {
33     public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf,
34           int row, boolean hasFocus)
35     {
36        super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
37        
38        ModelItem modelItem = ((SoapUITreeNode)value).getModelItem();
39        ImageIcon icon = modelItem.getIcon();
40        setIcon( icon );
41        
42        if( modelItem instanceof TestStep && ((TestStep)modelItem).isDisabled() )
43        {
44        	setText( getText() + " (disabled)" );
45        	setEnabled( false );
46        }
47        else
48        	setEnabled( true );
49        	
50        
51        String toolTipText = tree.getToolTipText();
52        if( toolTipText == null )
53        {
54        	String description = modelItem.getDescription();
55        	if( description == null || description.trim().length() == 0 )
56        		description = modelItem.getName();
57        	
58        	if( description != null && description.trim().indexOf( '\n' ) > 0 )
59        		description = Tools.convertToHtml( description );
60        	
61  			setToolTipText( description );
62        }
63        else
64        	setToolTipText( toolTipText.length() > 0 ? toolTipText : null );
65  
66        return this;
67     }
68  }