use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.
the class GuiPackage method createTestElement.
/**
* 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);
// Probably a missing jar
throw new RuntimeException(e.toString(), e);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
log.error("Problem retrieving gui for " + objClass, e);
// Programming error: bail out.
throw new RuntimeException(e.toString(), e);
}
}
use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.
the class AddToTree method doAction.
/**
* Adds the specified class to the current node of the tree.
*/
@Override
public void doAction(ActionEvent e) {
GuiPackage guiPackage = GuiPackage.getInstance();
try {
guiPackage.updateCurrentNode();
TestElement testElement = guiPackage.createTestElement(((JComponent) e.getSource()).getName());
JMeterTreeNode parentNode = guiPackage.getCurrentNode();
JMeterTreeNode node = guiPackage.getTreeModel().addComponent(testElement, parentNode);
guiPackage.getNamingPolicy().nameOnCreation(node);
guiPackage.getMainFrame().getTree().setSelectionPath(new TreePath(node.getPath()));
} catch (Exception err) {
// $NON-NLS-1$
log.error("Exception while adding a component to tree.", err);
String msg = err.getMessage();
if (msg == null) {
msg = err.toString();
}
JMeterUtils.reportErrorToUser(msg);
}
}
use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.
the class AddParent method doAction.
@Override
public void doAction(ActionEvent e) {
String name = ((Component) e.getSource()).getName();
GuiPackage guiPackage = GuiPackage.getInstance();
try {
guiPackage.updateCurrentNode();
TestElement controller = guiPackage.createTestElement(name);
addParentToTree(controller);
} catch (Exception err) {
log.error("Exception while adding a TestElement.", err);
}
}
use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.
the class GenerateTreeGui method addSimpleController.
/**
* Helper method to add a Simple Controller to contain the elements.
* Called from Application Thread that needs to update GUI (JMeterTreeModel)
* @param model
* Test component tree model
* @param node
* Node in the tree where we will add the Controller
* @param name
* A name for the Controller
* @return the new node
*/
private JMeterTreeNode addSimpleController(JMeterTreeModel model, JMeterTreeNode node, String name) {
final TestElement sc = new GenericController();
sc.setProperty(TestElement.GUI_CLASS, LOGIC_CONTROLLER_GUI);
// Use old style
sc.setProperty(TestElement.NAME, name);
return addToTree(model, node, sc);
}
use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.
the class GenerateTreeGui method addElements.
private void addElements(String menuKey, String title, GuiPackage guiPackage, JMeterTreeModel treeModel, JMeterTreeNode myTarget) {
myTarget = addSimpleController(treeModel, myTarget, title);
JPopupMenu jp = MenuFactory.makeMenu(menuKey, "").getPopupMenu();
for (Component comp : jp.getComponents()) {
JMenuItem jmi = (JMenuItem) comp;
try {
TestElement testElement = guiPackage.createTestElement(jmi.getName());
addToTree(treeModel, myTarget, testElement);
} catch (Exception e) {
addSimpleController(treeModel, myTarget, jmi.getName() + " " + e.getMessage());
}
}
}
Aggregations