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