KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > gui > tree > JMeterTreeNode


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/tree/JMeterTreeNode.java,v 1.24 2004/03/05 13:18:37 sebb Exp $
2
/*
3  * Copyright 2002-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.gui.tree;
20
21 import java.awt.Image JavaDoc;
22 import java.beans.BeanInfo JavaDoc;
23 import java.beans.IntrospectionException JavaDoc;
24 import java.beans.Introspector JavaDoc;
25 import java.util.Collection JavaDoc;
26
27 import javax.swing.ImageIcon JavaDoc;
28 import javax.swing.JPopupMenu JavaDoc;
29 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
30
31 import org.apache.jmeter.gui.GUIFactory;
32 import org.apache.jmeter.gui.GuiPackage;
33 import org.apache.jmeter.testbeans.TestBean;
34 import org.apache.jmeter.testelement.AbstractTestElement;
35 import org.apache.jmeter.testelement.TestElement;
36 import org.apache.jmeter.testelement.property.BooleanProperty;
37 import org.apache.jmeter.testelement.property.StringProperty;
38 import org.apache.jorphan.logging.LoggingManager;
39 import org.apache.log.Logger;
40
41 /**
42  * @author Michael Stover
43  * @version $Revision: 1.24 $
44  */

45 public class JMeterTreeNode
46     extends DefaultMutableTreeNode JavaDoc
47 {
48     transient private static Logger log = LoggingManager.getLoggerForClass();
49     private JMeterTreeModel treeModel;
50     //boolean enabled = true;
51

52     public JMeterTreeNode(){// Allow serializable test to work
53
// TODO: is the serializable test necessary now that JMeterTreeNode is no longer a GUI component?
54
this(null,null);
55     }
56     
57     public JMeterTreeNode(TestElement userObj, JMeterTreeModel treeModel)
58     {
59         super(userObj);
60         this.treeModel = treeModel;
61     }
62
63     public boolean isEnabled()
64     {
65         return (
66             (AbstractTestElement) getTestElement()).getPropertyAsBoolean(
67             TestElement.ENABLED);
68     }
69
70     public void setEnabled(boolean enabled)
71     {
72         getTestElement().setProperty(
73             new BooleanProperty(TestElement.ENABLED, enabled));
74         treeModel.nodeChanged(this);
75     }
76
77     public ImageIcon JavaDoc getIcon()
78     {
79         try
80         {
81             if (getTestElement() instanceof TestBean)
82             {
83                 try
84                 {
85                     Image JavaDoc img= Introspector.getBeanInfo(
86                         getTestElement().getClass())
87                             .getIcon(BeanInfo.ICON_COLOR_16x16);
88                     if (img == null) return null;
89                     return new ImageIcon JavaDoc(img);
90                 }
91                 catch (IntrospectionException JavaDoc e1)
92                 {
93                     log.error("Can't obtain icon", e1);
94                     throw new org.apache.jorphan.util.JMeterError(e1);
95                 }
96             }
97             else
98             {
99                 return GUIFactory.getIcon(
100                     Class.forName(
101                         getTestElement().getPropertyAsString(
102                             TestElement.GUI_CLASS)));
103             }
104         }
105         catch (ClassNotFoundException JavaDoc e)
106         {
107             log.warn("Can't get icon for class " + getTestElement(), e);
108             return null;
109         }
110     }
111
112     public Collection JavaDoc getMenuCategories()
113     {
114         try
115         {
116             return GuiPackage
117                 .getInstance()
118                 .getGui(getTestElement())
119                 .getMenuCategories();
120         }
121         catch (Exception JavaDoc e)
122         {
123             log.error("Can't get popup menu for gui", e);
124             return null;
125         }
126     }
127
128     public JPopupMenu JavaDoc createPopupMenu()
129     {
130         try
131         {
132             return GuiPackage
133                 .getInstance()
134                 .getGui(getTestElement())
135                 .createPopupMenu();
136         }
137         catch (Exception JavaDoc e)
138         {
139             log.error("Can't get popup menu for gui", e);
140             return null;
141         }
142     }
143
144     public TestElement getTestElement()
145     {
146         return (TestElement) getUserObject();
147     }
148
149     public String JavaDoc getStaticLabel()
150     {
151         return GuiPackage
152             .getInstance()
153             .getGui((TestElement) getUserObject())
154             .getStaticLabel();
155     }
156
157     public String JavaDoc getDocAnchor()
158     {
159         return GuiPackage
160             .getInstance()
161             .getGui((TestElement) getUserObject())
162             .getDocAnchor();
163     }
164
165     public void setName(String JavaDoc name)
166     {
167         ((TestElement) getUserObject()).setProperty(
168             new StringProperty(TestElement.NAME, name));
169     }
170
171     public String JavaDoc getName()
172     {
173         return ((TestElement) getUserObject()).getPropertyAsString(
174             TestElement.NAME);
175     }
176
177     public void nameChanged()
178     {
179         treeModel.nodeChanged(this);
180     }
181 }
182
Popular Tags