public JMeterGUIComponent getGui(TestElement node) { String testClassName = node.getPropertyAsString(TestElement.TEST_CLASS); String guiClassName = node.getPropertyAsString(TestElement.GUI_CLASS); try { Class testClass; if (testClassName.equals("")) { // $NON-NLS-1$ testClass = node.getClass(); } else { testClass = Class.forName(testClassName); } Class guiClass = null; if (!guiClassName.equals("")) { // $NON-NLS-1$ guiClass = Class.forName(guiClassName); } return getGui(node, guiClass, testClass); } catch (ClassNotFoundException e) { log.error("Could not get GUI for " + node, e); return null; } } /** * Get a JMeterGUIComponent for the specified test element. If the GUI has * already been created, that instance will be returned. Otherwise, if a GUI * component of the same type has been created, and the component is not * marked as an {@link UnsharedComponent}, that shared component will be * returned. Otherwise, a new instance of the component will be created. * * @param node * the test element which this GUI is being created for * @param guiClass * the fully qualifed class name of the GUI component which will * be created if it doesn't already exist * @param testClass * the fully qualifed class name of the test elements which have * to be edited by the returned GUI component * * @return the GUI component corresponding to the specified test element */ public JMeterGUIComponent getGui(TestElement node, Class guiClass, Class testClass) { try { JMeterGUIComponent comp = (JMeterGUIComponent) nodesToGui.get(node); if (comp == null) { comp = getGuiFromCache(guiClass, testClass); nodesToGui.put(node, comp); } log.debug("Gui retrieved = " + comp); return comp; } catch (Exception e) { log.error("Problem retrieving gui", e); return null; } } /** * Remove a test element from the tree. This removes the reference to any * associated GUI component. * * @param node * the test element being removed */ public void removeNode(TestElement node) { nodesToGui.remove(node); } /** * Convenience method for grabbing the gui for the current node. * * @return the GUI component associated with the currently selected node */ public JMeterGUIComponent getCurrentGui() { try { updateCurrentNode(); TestElement curNode = treeListener.getCurrentNode().getTestElement(); JMeterGUIComponent comp = getGui(curNode); comp.clearGui(); log.debug("Updating gui to new node"); comp.configure(curNode); currentNodeUpdated = false; return comp; } catch (Exception e) { log.error("Problem retrieving gui", e); return null; } } /** * Find the JMeterTreeNode for a certain TestElement object. * * @param userObject * the test element to search for * @return the tree node associated with the test element */ public JMeterTreeNode getNodeOf(TestElement userObject) { return treeModel.getNodeOf(userObject); } /** * Create a TestElement corresponding to the specified GUI class. * * @param guiClass * the fully qualified class name of the GUI component or a * TestBean class for TestBeanGUIs. * @param testClass * the fully qualified class name of the test elements edited by * this GUI component. * @return the test element corresponding to the specified GUI class. */ public TestElement createTestElement(Class guiClass, Class testClass) { try { JMeterGUIComponent comp = getGuiFromCache(guiClass, testClass); comp.clearGui(); TestElement node = comp.createTestElement(); nodesToGui.put(node, comp); return node; } catch (Exception e) { log.error("Problem retrieving gui", e); return null; } } /** * Create a TestElement for a GUI or TestBean class. * <p> * This is a utility method to help actions do with one single String * parameter. * * @param objClass * the fully qualified class name of the GUI component or of the * TestBean subclass for which a TestBeanGUI is wanted. * @return the test element corresponding to the specified GUI class. */ public TestElement createTestElement(String objClass) { JMeterGUIComponent comp; Class c; try { c = Class.forName(objClass); if (TestBean.class.isAssignableFrom(c)) { comp = getGuiFromCache(TestBeanGUI.class, c); } else { comp = getGuiFromCache(c, null); } comp.clearGui(); TestElement node = comp.createTestElement(); nodesToGui.put(node, comp); return node; } catch (NoClassDefFoundError e) { log.error("Problem retrieving gui for " + objClass, e); String msg="Cannot find class: "+e.getMessage(); JOptionPane.showMessageDialog(null, msg, "Missing jar? See log file." , JOptionPane.ERROR_MESSAGE); throw new RuntimeException(e.toString()); // Probably a missing // jar } catch (ClassNotFoundException e) { log.error("Problem retrieving gui for " + objClass, e); throw new RuntimeException(e.toString()); // Programming error: // bail out. } catch (InstantiationException e) { log.error("Problem retrieving gui for " + objClass, e); throw new RuntimeException(e.toString()); // Programming error: // bail out. } catch (IllegalAccessException e) { log.error("Problem retrieving gui for " + objClass, e); throw new RuntimeException(e.toString()); // Programming error: // bail out. } } /** * Get an instance of the specified JMeterGUIComponent class. If an instance * of the GUI class has previously been created and it is not marked as an * {@link UnsharedComponent}, that shared instance will be returned. * Otherwise, a new instance of the component will be created, and shared * components will be cached for future retrieval. * * @param guiClass * the fully qualified class name of the GUI component. This * class must implement JMeterGUIComponent. * @param testClass * the fully qualified class name of the test elements edited by * this GUI component. This class must implement TestElement. * @return an instance of the specified class * * @throws InstantiationException * if an instance of the object cannot be created * @throws IllegalAccessException * if access rights do not allow the default constructor to be * called * @throws ClassNotFoundException * if the specified GUI class cannot be found */ private JMeterGUIComponent getGuiFromCache(Class guiClass, Class testClass) throws InstantiationException, IllegalAccessException { JMeterGUIComponent comp; if (guiClass == TestBeanGUI.class) { comp = (TestBeanGUI) testBeanGUIs.get(testClass); if (comp == null) { comp = new TestBeanGUI(testClass); testBeanGUIs.put(testClass, comp); } } else { comp = (JMeterGUIComponent) guis.get(guiClass); if (comp == null) { comp = (JMeterGUIComponent) guiClass.newInstance(); if (!(comp instanceof UnsharedComponent)) { guis.put(guiClass, comp); } } } return comp; } /** * Update the GUI for the currently selected node. The GUI component is * configured to reflect the settings in the current tree node. * */ public void updateCurrentGui() { updateCurrentNode(); currentNode = treeListener.getCurrentNode(); TestElement element = currentNode.getTestElement(); JMeterGUIComponent comp = getGui(element); comp.configure(element); currentNodeUpdated = false; } /** * This method should be called in order for GuiPackage to change the * current node. This will save any changes made to the earlier node before * choosing the new node. */ public void updateCurrentNode() { try { if (currentNode != null && !currentNodeUpdated) { log.debug("Updating current node " + currentNode.getName()); JMeterGUIComponent comp = getGui(currentNode.getTestElement()); TestElement el = currentNode.getTestElement(); comp.modifyTestElement(el); } // The current node is now updated currentNodeUpdated = true; currentNode = treeListener.getCurrentNode(); } catch (Exception e) { log.error("Problem retrieving gui", e); } } public JMeterTreeNode getCurrentNode() { return treeListener.getCurrentNode(); } public TestElement getCurrentElement() { return getCurrentNode().getTestElement(); } /** * The dirty property is a flag that indicates whether there are parts of * JMeter's test tree that the user has not saved since last modification. * Various (@link Command actions) set this property when components are * modified/created/saved. * * @param dirty * the new value of the dirty flag */ public void setDirty(boolean dirty) { this.dirty = dirty; } /** * Retrieves the state of the 'dirty' property, a flag that indicates if * there are test tree components that have been modified since they were * last saved. * * @return true if some tree components have been modified since they were * last saved, false otherwise */ public boolean isDirty() { return dirty; } /** * Add a subtree to the currently selected node. * * @param subTree * the subtree to add. * * @return the resulting subtree starting with the currently selected node * * @throws IllegalUserActionException * if a subtree cannot be added to the currently selected node */ public HashTree addSubTree(HashTree subTree) throws IllegalUserActionException { return treeModel.addSubTree(subTree, treeListener.getCurrentNode()); } /** * Get the currently selected subtree. * * @return the subtree of the currently selected node */ public HashTree getCurrentSubTree() { return treeModel.getCurrentSubTree(treeListener.getCurrentNode());
public JMeterGUIComponent getGui(TestElement node) { String testClassName = node.getPropertyAsString(TestElement.TEST_CLASS); String guiClassName = node.getPropertyAsString(TestElement.GUI_CLASS); try { Class testClass; if (testClassName.equals("")) { testClass = node.getClass(); } else { testClass = Class.forName(testClassName); } Class guiClass = null; if (!guiClassName.equals("")) { guiClass = Class.forName(guiClassName); } return getGui(node, guiClass, testClass); } catch (ClassNotFoundException e) { log.error("Could not get GUI for " + node, e); return null; } } /** * Get a JMeterGUIComponent for the specified test element. If the GUI has * already been created, that instance will be returned. Otherwise, if a GUI * component of the same type has been created, and the component is not * marked as an {@link UnsharedComponent}, that shared component will be * returned. Otherwise, a new instance of the component will be created. * * @param node * the test element which this GUI is being created for * @param guiClass * the fully qualifed class name of the GUI component which will * be created if it doesn't already exist * @param testClass * the fully qualifed class name of the test elements which have * to be edited by the returned GUI component * * @return the GUI component corresponding to the specified test element */ public JMeterGUIComponent getGui(TestElement node, Class guiClass, Class testClass) { try { JMeterGUIComponent comp = (JMeterGUIComponent) nodesToGui.get(node); if (comp == null) { comp = getGuiFromCache(guiClass, testClass); nodesToGui.put(node, comp); } log.debug("Gui retrieved = " + comp); return comp; } catch (Exception e) { log.error("Problem retrieving gui", e); return null; } } /** * Remove a test element from the tree. This removes the reference to any * associated GUI component. * * @param node * the test element being removed */ public void removeNode(TestElement node) { nodesToGui.remove(node); } /** * Convenience method for grabbing the gui for the current node. * * @return the GUI component associated with the currently selected node */ public JMeterGUIComponent getCurrentGui() { try { updateCurrentNode(); TestElement curNode = treeListener.getCurrentNode().getTestElement(); JMeterGUIComponent comp = getGui(curNode); comp.clearGui(); log.debug("Updating gui to new node"); comp.configure(curNode); currentNodeUpdated = false; return comp; } catch (Exception e) { log.error("Problem retrieving gui", e); return null; } } /** * Find the JMeterTreeNode for a certain TestElement object. * * @param userObject * the test element to search for * @return the tree node associated with the test element */ public ReportTreeNode getNodeOf(TestElement userObject) { return treeModel.getNodeOf(userObject); } /** * Create a TestElement corresponding to the specified GUI class. * * @param guiClass * the fully qualified class name of the GUI component or a * TestBean class for TestBeanGUIs. * @param testClass * the fully qualified class name of the test elements edited by * this GUI component. * @return the test element corresponding to the specified GUI class. */ public TestElement createTestElement(Class guiClass, Class testClass) { try { JMeterGUIComponent comp = getGuiFromCache(guiClass, testClass); comp.clearGui(); TestElement node = comp.createTestElement(); nodesToGui.put(node, comp); return node; } catch (Exception e) { log.error("Problem retrieving gui", e); return null; } } /** * Create a TestElement for a GUI or TestBean class. * <p> * This is a utility method to help actions do with one single String * parameter. * * @param objClass * the fully qualified class name of the GUI component or of the * TestBean subclass for which a TestBeanGUI is wanted. * @return the test element corresponding to the specified GUI class. */ public TestElement createTestElement(String objClass) { JMeterGUIComponent comp; Class c; try { c = Class.forName(objClass); if (TestBean.class.isAssignableFrom(c)) { comp = getGuiFromCache(TestBeanGUI.class, c); } else { comp = getGuiFromCache(c, null); } comp.clearGui(); TestElement node = comp.createTestElement(); nodesToGui.put(node, comp); return node; } catch (NoClassDefFoundError e) { log.error("Problem retrieving gui for " + objClass, e); throw new RuntimeException(e.toString()); // Probably a missing // jar } catch (ClassNotFoundException e) { log.error("Problem retrieving gui for " + objClass, e); throw new RuntimeException(e.toString()); // Programming error: // bail out. } catch (InstantiationException e) { log.error("Problem retrieving gui for " + objClass, e); throw new RuntimeException(e.toString()); // Programming error: // bail out. } catch (IllegalAccessException e) { log.error("Problem retrieving gui for " + objClass, e); throw new RuntimeException(e.toString()); // Programming error: // bail out. } } /** * Get an instance of the specified JMeterGUIComponent class. If an instance * of the GUI class has previously been created and it is not marked as an * {@link UnsharedComponent}, that shared instance will be returned. * Otherwise, a new instance of the component will be created, and shared * components will be cached for future retrieval. * * @param guiClass * the fully qualified class name of the GUI component. This * class must implement JMeterGUIComponent. * @param testClass * the fully qualified class name of the test elements edited by * this GUI component. This class must implement TestElement. * @return an instance of the specified class * * @throws InstantiationException * if an instance of the object cannot be created * @throws IllegalAccessException * if access rights do not allow the default constructor to be * called * @throws ClassNotFoundException * if the specified GUI class cannot be found */ private JMeterGUIComponent getGuiFromCache(Class guiClass, Class testClass) throws InstantiationException, IllegalAccessException { JMeterGUIComponent comp; if (guiClass == TestBeanGUI.class) { comp = (TestBeanGUI) testBeanGUIs.get(testClass); if (comp == null) { comp = new TestBeanGUI(testClass); testBeanGUIs.put(testClass, comp); } } else { comp = (JMeterGUIComponent) guis.get(guiClass); if (comp == null) { comp = (JMeterGUIComponent) guiClass.newInstance(); if (!(comp instanceof UnsharedComponent)) { guis.put(guiClass, comp); } } } return comp; } /** * Update the GUI for the currently selected node. The GUI component is * configured to reflect the settings in the current tree node. * */ public void updateCurrentGui() { updateCurrentNode(); currentNode = treeListener.getCurrentNode(); TestElement element = currentNode.getTestElement(); JMeterGUIComponent comp = getGui(element); comp.configure(element); currentNodeUpdated = false; } /** * This method should be called in order for GuiPackage to change the * current node. This will save any changes made to the earlier node before * choosing the new node. */ public void updateCurrentNode() { try { if (currentNode != null && !currentNodeUpdated) { log.debug("Updating current node " + currentNode.getName()); JMeterGUIComponent comp = getGui(currentNode.getTestElement()); TestElement el = currentNode.getTestElement(); comp.modifyTestElement(el); } if (currentNode != treeListener.getCurrentNode()) { currentNodeUpdated = true; } currentNode = treeListener.getCurrentNode(); } catch (Exception e) { log.error("Problem retrieving gui", e); } } public ReportTreeNode getCurrentNode() { return treeListener.getCurrentNode(); } public TestElement getCurrentElement() { return getCurrentNode().getTestElement(); } /** * The dirty property is a flag that indicates whether there are parts of * JMeter's test tree that the user has not saved since last modification. * Various (@link Command actions) set this property when components are * modified/created/saved. * * @param dirty * the new value of the dirty flag */ public void setDirty(boolean dirty) { this.dirty = dirty; } /** * Retrieves the state of the 'dirty' property, a flag that indicates if * there are test tree components that have been modified since they were * last saved. * * @return true if some tree components have been modified since they were * last saved, false otherwise */ public boolean isDirty() { return dirty; } /** * Add a subtree to the currently selected node. * * @param subTree * the subtree to add. * * @return the resulting subtree starting with the currently selected node * * @throws IllegalUserActionException * if a subtree cannot be added to the currently selected node */ public HashTree addSubTree(HashTree subTree) throws IllegalUserActionException { return treeModel.addSubTree(subTree, treeListener.getCurrentNode()); } /** * Get the currently selected subtree. * * @return the subtree of the currently selected node */ public HashTree getCurrentSubTree() { return treeModel.getCurrentSubTree(treeListener.getCurrentNode());
Clone fragments detected by clone detection tool
File path: /jakarta-jmeter-2.3.2/src/org/apache/jmeter/gui/GuiPackage.java File path: /jakarta-jmeter-2.3.2/src/org/apache/jmeter/gui/ReportGuiPackage.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
public JMeterGUIComponent getGui(TestElement node) {
1
public JMeterGUIComponent getGui(TestElement node) {
2
		String testClassName = node.getPropertyAsString(TestElement.TEST_CLASS);
2
		String testClassName = node.getPropertyAsString(TestElement.TEST_CLASS);
3
		String guiClassName = node.getPropertyAsString(TestElement.GUI_CLASS);
3
		String guiClassName = node.getPropertyAsString(TestElement.GUI_CLASS);
4
		try {
4
		try {
5
			Class testClass;
5
			Class testClass;
6
			if (testClassName.equals("")) { // $NON-NLS-1$
6
			if (testClassName.equals("")) {
7
				testClass = node.getClass();
7
				testClass = node.getClass();
8
			} else {
8
			} else {
9
				testClass = Class.forName(testClassName);
9
				testClass = Class.forName(testClassName);
10
			}
10
			}
11
			Class guiClass = null;
11
			Class guiClass = null;
12
			if (!guiClassName.equals("")) { // $NON-NLS-1$
12
			if (!guiClassName.equals("")) {
13
				guiClass = Class.forName(guiClassName);
13
				guiClass = Class.forName(guiClassName);
14
			}
14
			}
15
			return getGui(node, guiClass, testClass);
15
			return getGui(node, guiClass, testClass);
16
		} catch (ClassNotFoundException e) {
16
		} catch (ClassNotFoundException e) {
17
			log.error("Could not get GUI for " + node, e);
17
			log.error("Could not get GUI for " + node, e);
18
			return null;
18
			return null;
19
		}
19
		}
20
	}
20
	}
21
	/**
21
	/**
22
	 * Get a JMeterGUIComponent for the specified test element. If the GUI has
22
	 * Get a JMeterGUIComponent for the specified test element. If the GUI has
23
	 * already been created, that instance will be returned. Otherwise, if a GUI
23
	 * already been created, that instance will be returned. Otherwise, if a GUI
24
	 * component of the same type has been created, and the component is not
24
	 * component of the same type has been created, and the component is not
25
	 * marked as an {@link UnsharedComponent}, that shared component will be
25
	 * marked as an {@link UnsharedComponent}, that shared component will be
26
	 * returned. Otherwise, a new instance of the component will be created.
26
	 * returned. Otherwise, a new instance of the component will be created.
27
	 * 
27
	 * 
28
	 * @param node
28
	 * @param node
29
	 *            the test element which this GUI is being created for
29
	 *            the test element which this GUI is being created for
30
	 * @param guiClass
30
	 * @param guiClass
31
	 *            the fully qualifed class name of the GUI component which will
31
	 *            the fully qualifed class name of the GUI component which will
32
	 *            be created if it doesn't already exist
32
	 *            be created if it doesn't already exist
33
	 * @param testClass
33
	 * @param testClass
34
	 *            the fully qualifed class name of the test elements which have
34
	 *            the fully qualifed class name of the test elements which have
35
	 *            to be edited by the returned GUI component
35
	 *            to be edited by the returned GUI component
36
	 * 
36
	 * 
37
	 * @return the GUI component corresponding to the specified test element
37
	 * @return the GUI component corresponding to the specified test element
38
	 */
38
	 */
39
	public JMeterGUIComponent getGui(TestElement node, Class guiClass, Class testClass) {
39
	public JMeterGUIComponent getGui(TestElement node, Class guiClass, Class testClass) {
40
		try {
40
		try {
41
			JMeterGUIComponent comp = (JMeterGUIComponent) nodesToGui.get(node);
41
			JMeterGUIComponent comp = (JMeterGUIComponent) nodesToGui.get(node);
42
			if (comp == null) {
42
			if (comp == null) {
43
				comp = getGuiFromCache(guiClass, testClass);
43
				comp = getGuiFromCache(guiClass, testClass);
44
				nodesToGui.put(node, comp);
44
				nodesToGui.put(node, comp);
45
			}
45
			}
46
			log.debug("Gui retrieved = " + comp);
46
			log.debug("Gui retrieved = " + comp);
47
			return comp;
47
			return comp;
48
		} catch (Exception e) {
48
		} catch (Exception e) {
49
			log.error("Problem retrieving gui", e);
49
			log.error("Problem retrieving gui", e);
50
			return null;
50
			return null;
51
		}
51
		}
52
	}
52
	}
53
	/**
53
	/**
54
	 * Remove a test element from the tree. This removes the reference to any
54
	 * Remove a test element from the tree. This removes the reference to any
55
	 * associated GUI component.
55
	 * associated GUI component.
56
	 * 
56
	 * 
57
	 * @param node
57
	 * @param node
58
	 *            the test element being removed
58
	 *            the test element being removed
59
	 */
59
	 */
60
	public void removeNode(TestElement node) {
60
	public void removeNode(TestElement node) {
61
		nodesToGui.remove(node);
61
		nodesToGui.remove(node);
62
	}
62
	}
63
	/**
63
	/**
64
	 * Convenience method for grabbing the gui for the current node.
64
	 * Convenience method for grabbing the gui for the current node.
65
	 * 
65
	 * 
66
	 * @return the GUI component associated with the currently selected node
66
	 * @return the GUI component associated with the currently selected node
67
	 */
67
	 */
68
	public JMeterGUIComponent getCurrentGui() {
68
	public JMeterGUIComponent getCurrentGui() {
69
		try {
69
		try {
70
			updateCurrentNode();
70
			updateCurrentNode();
71
			TestElement curNode = treeListener.getCurrentNode().getTestElement();
71
			TestElement curNode = treeListener.getCurrentNode().getTestElement();
72
			JMeterGUIComponent comp = getGui(curNode);
72
			JMeterGUIComponent comp = getGui(curNode);
73
			comp.clearGui();
73
			comp.clearGui();
74
			log.debug("Updating gui to new node");
74
			log.debug("Updating gui to new node");
75
			comp.configure(curNode);
75
			comp.configure(curNode);
76
			currentNodeUpdated = false;
76
			currentNodeUpdated = false;
77
			return comp;
77
			return comp;
78
		} catch (Exception e) {
78
		} catch (Exception e) {
79
			log.error("Problem retrieving gui", e);
79
			log.error("Problem retrieving gui", e);
80
			return null;
80
			return null;
81
		}
81
		}
82
	}
82
	}
83
	/**
83
	/**
84
	 * Find the JMeterTreeNode for a certain TestElement object.
84
	 * Find the JMeterTreeNode for a certain TestElement object.
85
	 * 
85
	 * 
86
	 * @param userObject
86
	 * @param userObject
87
	 *            the test element to search for
87
	 *            the test element to search for
88
	 * @return the tree node associated with the test element
88
	 * @return the tree node associated with the test element
89
	 */
89
	 */
90
	public JMeterTreeNode getNodeOf(TestElement userObject) {
90
	public ReportTreeNode getNodeOf(TestElement userObject) {
91
		return treeModel.getNodeOf(userObject);
91
		return treeModel.getNodeOf(userObject);
92
	}
92
	}
93
	/**
93
	/**
94
	 * Create a TestElement corresponding to the specified GUI class.
94
	 * Create a TestElement corresponding to the specified GUI class.
95
	 * 
95
	 * 
96
	 * @param guiClass
96
	 * @param guiClass
97
	 *            the fully qualified class name of the GUI component or a
97
	 *            the fully qualified class name of the GUI component or a
98
	 *            TestBean class for TestBeanGUIs.
98
	 *            TestBean class for TestBeanGUIs.
99
	 * @param testClass
99
	 * @param testClass
100
	 *            the fully qualified class name of the test elements edited by
100
	 *            the fully qualified class name of the test elements edited by
101
	 *            this GUI component.
101
	 *            this GUI component.
102
	 * @return the test element corresponding to the specified GUI class.
102
	 * @return the test element corresponding to the specified GUI class.
103
	 */
103
	 */
104
	public TestElement createTestElement(Class guiClass, Class testClass) {
104
	public TestElement createTestElement(Class guiClass, Class testClass) {
105
		try {
105
		try {
106
			JMeterGUIComponent comp = getGuiFromCache(guiClass, testClass);
106
			JMeterGUIComponent comp = getGuiFromCache(guiClass, testClass);
107
			comp.clearGui();
107
			comp.clearGui();
108
			TestElement node = comp.createTestElement();
108
			TestElement node = comp.createTestElement();
109
			nodesToGui.put(node, comp);
109
			nodesToGui.put(node, comp);
110
			return node;
110
			return node;
111
		} catch (Exception e) {
111
		} catch (Exception e) {
112
			log.error("Problem retrieving gui", e);
112
			log.error("Problem retrieving gui", e);
113
			return null;
113
			return null;
114
		}
114
		}
115
	}
115
	}
116
	/**
116
	/**
117
	 * Create a TestElement for a GUI or TestBean class.
117
	 * Create a TestElement for a GUI or TestBean class.
118
	 * <p>
118
	 * <p>
119
	 * This is a utility method to help actions do with one single String
119
	 * This is a utility method to help actions do with one single String
120
	 * parameter.
120
	 * parameter.
121
	 * 
121
	 * 
122
	 * @param objClass
122
	 * @param objClass
123
	 *            the fully qualified class name of the GUI component or of the
123
	 *            the fully qualified class name of the GUI component or of the
124
	 *            TestBean subclass for which a TestBeanGUI is wanted.
124
	 *            TestBean subclass for which a TestBeanGUI is wanted.
125
	 * @return the test element corresponding to the specified GUI class.
125
	 * @return the test element corresponding to the specified GUI class.
126
	 */
126
	 */
127
	public TestElement createTestElement(String objClass) {
127
	public TestElement createTestElement(String objClass) {
128
		JMeterGUIComponent comp;
128
		JMeterGUIComponent comp;
129
		Class c;
129
		Class c;
130
		try {
130
		try {
131
			c = Class.forName(objClass);
131
			c = Class.forName(objClass);
132
			if (TestBean.class.isAssignableFrom(c)) {
132
			if (TestBean.class.isAssignableFrom(c)) {
133
				comp = getGuiFromCache(TestBeanGUI.class, c);
133
				comp = getGuiFromCache(TestBeanGUI.class, c);
134
			} else {
134
			} else {
135
				comp = getGuiFromCache(c, null);
135
				comp = getGuiFromCache(c, null);
136
			}
136
			}
137
			comp.clearGui();
137
			comp.clearGui();
138
			TestElement node = comp.createTestElement();
138
			TestElement node = comp.createTestElement();
139
			nodesToGui.put(node, comp);
139
			nodesToGui.put(node, comp);
140
			return node;
140
			return node;
141
		} catch (NoClassDefFoundError e) {
141
		} catch (NoClassDefFoundError e) {
142
			log.error("Problem retrieving gui for " + objClass, e);
142
			log.error("Problem retrieving gui for " + objClass, e);
143
            String msg="Cannot find class: "+e.getMessage();
144
            JOptionPane.showMessageDialog(null,
145
                    msg,
146
                    "Missing jar? See log file." , 
147
                    JOptionPane.ERROR_MESSAGE);
148
			throw new RuntimeException(e.toString()); // Probably a missing
143
			throw new RuntimeException(e.toString()); // Probably a missing
149
														// jar
144
														// jar
150
		} catch (ClassNotFoundException e) {
145
		} catch (ClassNotFoundException e) {
151
			log.error("Problem retrieving gui for " + objClass, e);
146
			log.error("Problem retrieving gui for " + objClass, e);
152
			throw new RuntimeException(e.toString()); // Programming error:
147
			throw new RuntimeException(e.toString()); // Programming error:
153
														// bail out.
148
														// bail out.
154
		} catch (InstantiationException e) {
149
		} catch (InstantiationException e) {
155
			log.error("Problem retrieving gui for " + objClass, e);
150
			log.error("Problem retrieving gui for " + objClass, e);
156
			throw new RuntimeException(e.toString()); // Programming error:
151
			throw new RuntimeException(e.toString()); // Programming error:
157
														// bail out.
152
														// bail out.
158
		} catch (IllegalAccessException e) {
153
		} catch (IllegalAccessException e) {
159
			log.error("Problem retrieving gui for " + objClass, e);
154
			log.error("Problem retrieving gui for " + objClass, e);
160
			throw new RuntimeException(e.toString()); // Programming error:
155
			throw new RuntimeException(e.toString()); // Programming error:
161
														// bail out.
156
														// bail out.
162
		}
157
		}
163
	}
158
	}
164
	/**
159
	/**
165
	 * Get an instance of the specified JMeterGUIComponent class. If an instance
160
	 * Get an instance of the specified JMeterGUIComponent class. If an instance
166
	 * of the GUI class has previously been created and it is not marked as an
161
	 * of the GUI class has previously been created and it is not marked as an
167
	 * {@link UnsharedComponent}, that shared instance will be returned.
162
	 * {@link UnsharedComponent}, that shared instance will be returned.
168
	 * Otherwise, a new instance of the component will be created, and shared
163
	 * Otherwise, a new instance of the component will be created, and shared
169
	 * components will be cached for future retrieval.
164
	 * components will be cached for future retrieval.
170
	 * 
165
	 * 
171
	 * @param guiClass
166
	 * @param guiClass
172
	 *            the fully qualified class name of the GUI component. This
167
	 *            the fully qualified class name of the GUI component. This
173
	 *            class must implement JMeterGUIComponent.
168
	 *            class must implement JMeterGUIComponent.
174
	 * @param testClass
169
	 * @param testClass
175
	 *            the fully qualified class name of the test elements edited by
170
	 *            the fully qualified class name of the test elements edited by
176
	 *            this GUI component. This class must implement TestElement.
171
	 *            this GUI component. This class must implement TestElement.
177
	 * @return an instance of the specified class
172
	 * @return an instance of the specified class
178
	 * 
173
	 * 
179
	 * @throws InstantiationException
174
	 * @throws InstantiationException
180
	 *             if an instance of the object cannot be created
175
	 *             if an instance of the object cannot be created
181
	 * @throws IllegalAccessException
176
	 * @throws IllegalAccessException
182
	 *             if access rights do not allow the default constructor to be
177
	 *             if access rights do not allow the default constructor to be
183
	 *             called
178
	 *             called
184
	 * @throws ClassNotFoundException
179
	 * @throws ClassNotFoundException
185
	 *             if the specified GUI class cannot be found
180
	 *             if the specified GUI class cannot be found
186
	 */
181
	 */
187
	private JMeterGUIComponent getGuiFromCache(Class guiClass, Class testClass) throws InstantiationException,
182
	private JMeterGUIComponent getGuiFromCache(Class guiClass, Class testClass) throws InstantiationException,
188
			IllegalAccessException {
183
			IllegalAccessException {
189
		JMeterGUIComponent comp;
184
		JMeterGUIComponent comp;
190
		if (guiClass == TestBeanGUI.class) {
185
		if (guiClass == TestBeanGUI.class) {
191
			comp = (TestBeanGUI) testBeanGUIs.get(testClass);
186
			comp = (TestBeanGUI) testBeanGUIs.get(testClass);
192
			if (comp == null) {
187
			if (comp == null) {
193
				comp = new TestBeanGUI(testClass);
188
				comp = new TestBeanGUI(testClass);
194
				testBeanGUIs.put(testClass, comp);
189
				testBeanGUIs.put(testClass, comp);
195
			}
190
			}
196
		} else {
191
		} else {
197
			comp = (JMeterGUIComponent) guis.get(guiClass);
192
			comp = (JMeterGUIComponent) guis.get(guiClass);
198
			if (comp == null) {
193
			if (comp == null) {
199
				comp = (JMeterGUIComponent) guiClass.newInstance();
194
				comp = (JMeterGUIComponent) guiClass.newInstance();
200
				if (!(comp instanceof UnsharedComponent)) {
195
				if (!(comp instanceof UnsharedComponent)) {
201
					guis.put(guiClass, comp);
196
					guis.put(guiClass, comp);
202
				}
197
				}
203
			}
198
			}
204
		}
199
		}
205
		return comp;
200
		return comp;
206
	}
201
	}
207
	/**
202
	/**
208
	 * Update the GUI for the currently selected node. The GUI component is
203
	 * Update the GUI for the currently selected node. The GUI component is
209
	 * configured to reflect the settings in the current tree node.
204
	 * configured to reflect the settings in the current tree node.
210
	 * 
205
	 * 
211
	 */
206
	 */
212
	public void updateCurrentGui() {
207
	public void updateCurrentGui() {
213
		updateCurrentNode();
208
		updateCurrentNode();
214
		currentNode = treeListener.getCurrentNode();
209
		currentNode = treeListener.getCurrentNode();
215
		TestElement element = currentNode.getTestElement();
210
		TestElement element = currentNode.getTestElement();
216
		JMeterGUIComponent comp = getGui(element);
211
		JMeterGUIComponent comp = getGui(element);
217
		comp.configure(element);
212
		comp.configure(element);
218
		currentNodeUpdated = false;
213
		currentNodeUpdated = false;
219
	}
214
	}
220
	/**
215
	/**
221
	 * This method should be called in order for GuiPackage to change the
216
	 * This method should be called in order for GuiPackage to change the
222
	 * current node. This will save any changes made to the earlier node before
217
	 * current node. This will save any changes made to the earlier node before
223
	 * choosing the new node.
218
	 * choosing the new node.
224
	 */
219
	 */
225
	public void updateCurrentNode() {
220
	public void updateCurrentNode() {
226
		try {
221
		try {
227
			if (currentNode != null && !currentNodeUpdated) {
222
			if (currentNode != null && !currentNodeUpdated) {
228
				log.debug("Updating current node " + currentNode.getName());
223
				log.debug("Updating current node " + currentNode.getName());
229
				JMeterGUIComponent comp = getGui(currentNode.getTestElement());
224
				JMeterGUIComponent comp = getGui(currentNode.getTestElement());
230
				TestElement el = currentNode.getTestElement();
225
				TestElement el = currentNode.getTestElement();
231
				comp.modifyTestElement(el);
226
				comp.modifyTestElement(el);
232
			}
227
			}
233
			// The current node is now updated
228
			if (currentNode != treeListener.getCurrentNode()) {
234
			currentNodeUpdated = true;
229
				currentNodeUpdated = true;
235
			
230
			}
236
currentNode = treeListener.getCurrentNode();
231
			currentNode = treeListener.getCurrentNode();
237
		} catch (Exception e) {
232
		} catch (Exception e) {
238
			log.error("Problem retrieving gui", e);
233
			log.error("Problem retrieving gui", e);
239
		}
234
		}
240
	}
235
	}
241
	public JMeterTreeNode getCurrentNode() {
236
	public ReportTreeNode getCurrentNode() {
242
		return treeListener.getCurrentNode();
237
		return treeListener.getCurrentNode();
243
	}
238
	}
244
	public TestElement getCurrentElement() {
239
	public TestElement getCurrentElement() {
245
		return getCurrentNode().getTestElement();
240
		return getCurrentNode().getTestElement();
246
	}
241
	}
247
	/**
242
	/**
248
	 * The dirty property is a flag that indicates whether there are parts of
243
	 * The dirty property is a flag that indicates whether there are parts of
249
	 * JMeter's test tree that the user has not saved since last modification.
244
	 * JMeter's test tree that the user has not saved since last modification.
250
	 * Various (@link Command actions) set this property when components are
245
	 * Various (@link Command actions) set this property when components are
251
	 * modified/created/saved.
246
	 * modified/created/saved.
252
	 * 
247
	 * 
253
	 * @param dirty
248
	 * @param dirty
254
	 *            the new value of the dirty flag
249
	 *            the new value of the dirty flag
255
	 */
250
	 */
256
	public void setDirty(boolean dirty) {
251
	public void setDirty(boolean dirty) {
257
		this.dirty = dirty;
252
		this.dirty = dirty;
258
	}
253
	}
259
	/**
254
	/**
260
	 * Retrieves the state of the 'dirty' property, a flag that indicates if
255
	 * Retrieves the state of the 'dirty' property, a flag that indicates if
261
	 * there are test tree components that have been modified since they were
256
	 * there are test tree components that have been modified since they were
262
	 * last saved.
257
	 * last saved.
263
	 * 
258
	 * 
264
	 * @return true if some tree components have been modified since they were
259
	 * @return true if some tree components have been modified since they were
265
	 *         last saved, false otherwise
260
	 *         last saved, false otherwise
266
	 */
261
	 */
267
	public boolean isDirty() {
262
	public boolean isDirty() {
268
		return dirty;
263
		return dirty;
269
	}
264
	}
270
	/**
265
	/**
271
	 * Add a subtree to the currently selected node.
266
	 * Add a subtree to the currently selected node.
272
	 * 
267
	 * 
273
	 * @param subTree
268
	 * @param subTree
274
	 *            the subtree to add.
269
	 *            the subtree to add.
275
	 * 
270
	 * 
276
	 * @return the resulting subtree starting with the currently selected node
271
	 * @return the resulting subtree starting with the currently selected node
277
	 * 
272
	 * 
278
	 * @throws IllegalUserActionException
273
	 * @throws IllegalUserActionException
279
	 *             if a subtree cannot be added to the currently selected node
274
	 *             if a subtree cannot be added to the currently selected node
280
	 */
275
	 */
281
	public HashTree addSubTree(HashTree subTree) throws IllegalUserActionException {
276
	public HashTree addSubTree(HashTree subTree) throws IllegalUserActionException {
282
		return treeModel.addSubTree(subTree, treeListener.getCurrentNode());
277
		return treeModel.addSubTree(subTree, treeListener.getCurrentNode());
283
	}
278
	}
284
	/**
279
	/**
285
	 * Get the currently selected subtree.
280
	 * Get the currently selected subtree.
286
	 * 
281
	 * 
287
	 * @return the subtree of the currently selected node
282
	 * @return the subtree of the currently selected node
288
	 */
283
	 */
289
	public HashTree getCurrentSubTree() {
284
	public HashTree getCurrentSubTree() {
290
		return treeModel.getCurrentSubTree(treeListener.getCurrentNode());
285
		return treeModel.getCurrentSubTree(treeListener.getCurrentNode());
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones location
Number of node comparisons0