1 package org.apache.jmeter.module; 2 3 import java.awt.Image ; 4 import java.beans.PropertyChangeEvent ; 5 import java.beans.PropertyChangeListener ; 6 import java.lang.reflect.InvocationTargetException ; 7 import java.util.Map ; 8 import java.util.ResourceBundle ; 9 import javax.swing.Action ; 10 import org.apache.jmeter.module.integration.JMeterIntegrationEngine; 11 import org.apache.jmeter.testelement.TestPlan; 12 import org.apache.jmeter.util.JMeterUtils; 13 import org.openide.filesystems.FileUtil; 14 import org.openide.loaders.DataNode; 15 import org.openide.nodes.Children; 16 import org.openide.nodes.PropertySupport; 17 import org.openide.nodes.Sheet; 18 19 public class JMXTypeDataNode extends DataNode { 20 private static final ResourceBundle bundle = ResourceBundle.getBundle("org/apache/jmeter/images/icon") ; 21 22 private final static String NB_ENABLED = "nb.enabled"; 23 private final static String NB_RAMPUP = "nb.rampup"; 24 private final static String NB_PORT = "nb.port"; 25 private final static String NB_SERVER = "nb.server"; 26 private final static String NB_USERS = "nb.users"; 27 28 private class MapBasedProperty extends PropertySupport.ReadWrite { 29 private Map vars = null; 30 31 public MapBasedProperty(final Map vars, final String name, final Class clz, final String displayName, final String shortDescription) { 32 super(name, clz, displayName, shortDescription); 33 this.vars = vars; 34 } 35 36 public void setValue(Object value) throws IllegalAccessException , IllegalArgumentException , InvocationTargetException { 37 vars.put(getName(), value != null ? value.toString() : null); 38 } 39 40 public Object getValue() throws IllegalAccessException , InvocationTargetException { 41 Object result = vars.get(getName()); 42 Class typeClass = getValueType(); 43 Class intClass = Integer .class; 44 45 if (getValueType().equals(Integer .class)) { 46 result = Integer.parseInt(result.toString()); 47 } 48 return result; 49 } 50 } 51 52 public JMXTypeDataNode(JMXTypeDataObject obj) { 53 super(obj, Children.LEAF); 54 55 if (obj == null) { 56 return; 57 } 58 } 59 60 public Image getOpenedIcon(int i) { 61 Image icon = null; 62 icon = JMeterUtils.getImage("feather.gif").getImage(); 63 64 return icon != null ? icon : super.getOpenedIcon(i); 65 } 66 67 public Image getIcon(int i) { 68 Image icon = null; 69 icon = JMeterUtils.getImage("feather.gif").getImage(); 70 71 return icon != null ? icon : super.getIcon(i); 72 } 73 74 77 public Action getPreferredAction() { 78 return null; 79 } 80 81 protected Sheet createSheet() { 82 Sheet retValue; 83 84 Sheet.Set expert = null; 85 try { 86 JMeterIntegrationEngine engine = JMeterIntegrationEngine.getDefault(); 87 final String path = FileUtil.toFile(getDataObject().getPrimaryFile()).getCanonicalPath(); 88 TestPlan root = (TestPlan)engine.getRoot(path); 89 final Map vars = root.getUserDefinedVariables(); 90 91 if (vars.containsKey(NB_ENABLED)) { 92 expert = Sheet.createExpertSet(); 93 expert.put(new MapBasedProperty(vars, NB_SERVER, String .class, "Target server", "Sets the target server")); 94 expert.put(new MapBasedProperty(vars, NB_PORT, Integer .class, "Target server port", "Sets the target server port")); 95 expert.put(new MapBasedProperty(vars, NB_USERS, Integer .class, "Number of users", "The number of simulated users")); 96 expert.put(new MapBasedProperty(vars, NB_RAMPUP, Integer .class, "Rampup time", "The interval between two simulated users (in seconds)")); 97 98 expert.addPropertyChangeListener(new PropertyChangeListener () { 99 public void propertyChange(PropertyChangeEvent evt) { 100 System.out.println("Property changed"); 101 } 102 }); 103 } 104 105 } catch (Exception e) {} 106 107 retValue = super.createSheet(); 108 retValue.addPropertyChangeListener(new PropertyChangeListener () { 109 public void propertyChange(PropertyChangeEvent evt) { 110 System.out.println("Property changed; the sheet"); 111 } 112 }); 113 if (expert != null) { 114 retValue.put(expert); 115 } 116 return retValue; 117 } 118 119 120 } 121 | Popular Tags |