01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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: public Component getTreeCellRendererComponent(JTree tree,
33: Object value, boolean sel, boolean expanded, boolean leaf,
34: int row, boolean hasFocus) {
35: super .getTreeCellRendererComponent(tree, value, sel, expanded,
36: leaf, row, hasFocus);
37:
38: ModelItem modelItem = ((SoapUITreeNode) value).getModelItem();
39: ImageIcon icon = modelItem.getIcon();
40: setIcon(icon);
41:
42: if (modelItem instanceof TestStep
43: && ((TestStep) modelItem).isDisabled()) {
44: setText(getText() + " (disabled)");
45: setEnabled(false);
46: } else
47: setEnabled(true);
48:
49: String toolTipText = tree.getToolTipText();
50: if (toolTipText == null) {
51: String description = modelItem.getDescription();
52: if (description == null || description.trim().length() == 0)
53: description = modelItem.getName();
54:
55: if (description != null
56: && description.trim().indexOf('\n') > 0)
57: description = Tools.convertToHtml(description);
58:
59: setToolTipText(description);
60: } else
61: setToolTipText(toolTipText.length() > 0 ? toolTipText
62: : null);
63:
64: return this;
65: }
66: }
|