1 18 19 package org.apache.jmeter.gui.tree; 20 21 import java.awt.Image ; 22 import java.beans.BeanInfo ; 23 import java.beans.IntrospectionException ; 24 import java.beans.Introspector ; 25 import java.util.Collection ; 26 27 import javax.swing.ImageIcon ; 28 import javax.swing.JPopupMenu ; 29 import javax.swing.tree.DefaultMutableTreeNode ; 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 45 public class JMeterTreeNode 46 extends DefaultMutableTreeNode 47 { 48 transient private static Logger log = LoggingManager.getLoggerForClass(); 49 private JMeterTreeModel treeModel; 50 52 public JMeterTreeNode(){ 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 getIcon() 78 { 79 try 80 { 81 if (getTestElement() instanceof TestBean) 82 { 83 try 84 { 85 Image img= Introspector.getBeanInfo( 86 getTestElement().getClass()) 87 .getIcon(BeanInfo.ICON_COLOR_16x16); 88 if (img == null) return null; 89 return new ImageIcon (img); 90 } 91 catch (IntrospectionException 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 e) 106 { 107 log.warn("Can't get icon for class " + getTestElement(), e); 108 return null; 109 } 110 } 111 112 public Collection getMenuCategories() 113 { 114 try 115 { 116 return GuiPackage 117 .getInstance() 118 .getGui(getTestElement()) 119 .getMenuCategories(); 120 } 121 catch (Exception e) 122 { 123 log.error("Can't get popup menu for gui", e); 124 return null; 125 } 126 } 127 128 public JPopupMenu createPopupMenu() 129 { 130 try 131 { 132 return GuiPackage 133 .getInstance() 134 .getGui(getTestElement()) 135 .createPopupMenu(); 136 } 137 catch (Exception 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 getStaticLabel() 150 { 151 return GuiPackage 152 .getInstance() 153 .getGui((TestElement) getUserObject()) 154 .getStaticLabel(); 155 } 156 157 public String getDocAnchor() 158 { 159 return GuiPackage 160 .getInstance() 161 .getGui((TestElement) getUserObject()) 162 .getDocAnchor(); 163 } 164 165 public void setName(String name) 166 { 167 ((TestElement) getUserObject()).setProperty( 168 new StringProperty(TestElement.NAME, name)); 169 } 170 171 public String 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 |