KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > module > JMXTypeDataNode


1 package org.apache.jmeter.module;
2
3 import java.awt.Image JavaDoc;
4 import java.beans.PropertyChangeEvent JavaDoc;
5 import java.beans.PropertyChangeListener JavaDoc;
6 import java.lang.reflect.InvocationTargetException JavaDoc;
7 import java.util.Map JavaDoc;
8 import java.util.ResourceBundle JavaDoc;
9 import javax.swing.Action JavaDoc;
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 JavaDoc bundle = ResourceBundle.getBundle("org/apache/jmeter/images/icon") ;
21   
22   private final static String JavaDoc NB_ENABLED = "nb.enabled";
23   private final static String JavaDoc NB_RAMPUP = "nb.rampup";
24   private final static String JavaDoc NB_PORT = "nb.port";
25   private final static String JavaDoc NB_SERVER = "nb.server";
26   private final static String JavaDoc NB_USERS = "nb.users";
27   
28   private class MapBasedProperty extends PropertySupport.ReadWrite {
29     private Map JavaDoc vars = null;
30     
31     public MapBasedProperty(final Map JavaDoc vars, final String JavaDoc name, final Class JavaDoc clz, final String JavaDoc displayName, final String JavaDoc shortDescription) {
32       super(name, clz, displayName, shortDescription);
33       this.vars = vars;
34     }
35     
36     public void setValue(Object JavaDoc value) throws IllegalAccessException JavaDoc, IllegalArgumentException JavaDoc, InvocationTargetException JavaDoc {
37       vars.put(getName(), value != null ? value.toString() : null);
38     }
39     
40     public Object JavaDoc getValue() throws IllegalAccessException JavaDoc, InvocationTargetException JavaDoc {
41       Object JavaDoc result = vars.get(getName());
42       Class JavaDoc typeClass = getValueType();
43       Class JavaDoc intClass = Integer JavaDoc.class;
44       
45       if (getValueType().equals(Integer JavaDoc.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 JavaDoc getOpenedIcon(int i) {
61     Image JavaDoc icon = null;
62     icon = JMeterUtils.getImage("feather.gif").getImage();
63     
64     return icon != null ? icon : super.getOpenedIcon(i);
65   }
66   
67   public Image JavaDoc getIcon(int i) {
68     Image JavaDoc icon = null;
69     icon = JMeterUtils.getImage("feather.gif").getImage();
70     
71     return icon != null ? icon : super.getIcon(i);
72   }
73   
74   /**
75    * Dont use preferred action! The preferred action is called at the creation of new node *TWICE*
76    */

77   public Action JavaDoc 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 JavaDoc path = FileUtil.toFile(getDataObject().getPrimaryFile()).getCanonicalPath();
88       TestPlan root = (TestPlan)engine.getRoot(path);
89       final Map JavaDoc vars = root.getUserDefinedVariables();
90       
91       if (vars.containsKey(NB_ENABLED)) {
92         expert = Sheet.createExpertSet();
93         expert.put(new MapBasedProperty(vars, NB_SERVER, String JavaDoc.class, "Target server", "Sets the target server"));
94         expert.put(new MapBasedProperty(vars, NB_PORT, Integer JavaDoc.class, "Target server port", "Sets the target server port"));
95         expert.put(new MapBasedProperty(vars, NB_USERS, Integer JavaDoc.class, "Number of users", "The number of simulated users"));
96         expert.put(new MapBasedProperty(vars, NB_RAMPUP, Integer JavaDoc.class, "Rampup time", "The interval between two simulated users (in seconds)"));
97         
98         expert.addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
99           public void propertyChange(PropertyChangeEvent JavaDoc evt) {
100             System.out.println("Property changed");
101           }
102         });
103       }
104       
105     } catch (Exception JavaDoc e) {}
106     
107     retValue = super.createSheet();
108     retValue.addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
109       public void propertyChange(PropertyChangeEvent JavaDoc 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