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  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.project.Project;
23  import com.eviware.soapui.model.testsuite.TestCase;
24  import com.eviware.soapui.model.testsuite.TestStep;
25  import com.eviware.soapui.model.testsuite.TestSuite;
26  import com.eviware.soapui.support.Tools;
27  
28  /***
29   * TreeCellRenderer for SoapUITreeNodes
30   * 
31   * @author Ole.Matzura
32   */
33  
34  public class SoapUITreeNodeRenderer extends DefaultTreeCellRenderer
35  {
36     public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf,
37           int row, boolean hasFocus)
38     {
39     	ModelItem modelItem = ((SoapUITreeNode)value).getModelItem();
40     	if( modelItem instanceof Project )
41     	{
42     		Project project = ( Project ) modelItem;
43     		if( !project.isOpen() && !project.isDisabled() )
44     		{
45     			leaf = false;
46     			expanded = false;
47     		}
48     	}
49     	
50        super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
51        
52        ImageIcon icon = modelItem.getIcon();
53        setIcon( icon );
54        
55        if( modelItem instanceof TestStep && ((TestStep)modelItem).isDisabled() )
56        {
57        	setEnabled( false );
58        }
59        else if( modelItem instanceof TestCase && ((TestCase)modelItem).isDisabled() )
60        {
61        	setEnabled( false );
62        }
63        else if( modelItem instanceof TestSuite && ((TestSuite)modelItem).isDisabled() )
64        {
65        	setEnabled( false );
66        }
67        else 
68        {
69        	setEnabled( true );
70        }
71        
72        String toolTipText = tree.getToolTipText();
73        if( toolTipText == null )
74        {
75        	String description = modelItem.getDescription();
76        	if( description == null || description.trim().length() == 0 )
77        		description = modelItem.getName();
78        	
79        	if( description != null && description.trim().indexOf( '\n' ) > 0 )
80        		description = Tools.convertToHtml( description );
81        	
82  			setToolTipText( description );
83        }
84        else
85        	setToolTipText( toolTipText.length() > 0 ? toolTipText : null );
86  
87        return this;
88     }
89  }