use of org.apache.jmeter.gui.JMeterGUIComponent in project jmeter by apache.
the class JMeterTreeModel method addComponent.
/**
* Add a {@link TestElement} to a {@link JMeterTreeNode}
* @param component The {@link TestElement} to be used as data for the newly created node
* @param node The {@link JMeterTreeNode} into which the newly created node is to be inserted
* @return new {@link JMeterTreeNode} for the given <code>component</code>
* @throws IllegalUserActionException
* when the user object for the <code>node</code> is not an instance
* of {@link AbstractConfigGui}
*/
public JMeterTreeNode addComponent(TestElement component, JMeterTreeNode node) throws IllegalUserActionException {
if (node.getUserObject() instanceof AbstractConfigGui) {
throw new IllegalUserActionException("This node cannot hold sub-elements");
}
GuiPackage guiPackage = GuiPackage.getInstance();
if (guiPackage != null) {
// The node can be added in non GUI mode at startup
guiPackage.updateCurrentNode();
JMeterGUIComponent guicomp = guiPackage.getGui(component);
guicomp.clearGui();
guicomp.configure(component);
guicomp.modifyTestElement(component);
// put the gui object back
guiPackage.getCurrentGui();
// to the way it was.
}
JMeterTreeNode newNode = new JMeterTreeNode(component, this);
// disable the loaded node
try {
newNode.setEnabled(component.isEnabled());
} catch (Exception e) {
// TODO - can this ever happen?
newNode.setEnabled(true);
}
this.insertNodeInto(newNode, node, node.getChildCount());
return newNode;
}
use of org.apache.jmeter.gui.JMeterGUIComponent in project jmeter by apache.
the class ChangeParent method changeParent.
private void changeParent(TestElement newParent, GuiPackage guiPackage, JMeterTreeNode currentNode) {
// keep the old name if it was not the default one
Controller currentController = (Controller) currentNode.getUserObject();
JMeterGUIComponent currentGui = guiPackage.getCurrentGui();
String defaultName = JMeterUtils.getResString(currentGui.getLabelResource());
if (StringUtils.isNotBlank(currentController.getName()) && !currentController.getName().equals(defaultName)) {
newParent.setName(currentController.getName());
}
JMeterTreeModel treeModel = guiPackage.getTreeModel();
JMeterTreeNode newNode = new JMeterTreeNode(newParent, treeModel);
JMeterTreeNode parentNode = (JMeterTreeNode) currentNode.getParent();
int index = parentNode.getIndex(currentNode);
treeModel.insertNodeInto(newNode, parentNode, index);
treeModel.removeNodeFromParent(currentNode);
int childCount = currentNode.getChildCount();
for (int i = 0; i < childCount; i++) {
// Using index 0 is voluntary as child is removed in next step and added to new parent
JMeterTreeNode node = (JMeterTreeNode) currentNode.getChildAt(0);
treeModel.removeNodeFromParent(node);
treeModel.insertNodeInto(node, newNode, newNode.getChildCount());
}
// select the node
TreeNode[] nodes = treeModel.getPathToRoot(newNode);
JTree tree = guiPackage.getTreeListener().getJTree();
tree.setSelectionPath(new TreePath(nodes));
}
use of org.apache.jmeter.gui.JMeterGUIComponent in project jmeter by apache.
the class JMeterTest method suiteBeanComponents.
/*
* Test GUI elements - create the suite of tests
*/
private static Test suiteBeanComponents() throws Exception {
TestSuite suite = new TestSuite("BeanComponents");
for (Object o : getObjects(TestBean.class)) {
Class<?> c = o.getClass();
try {
JMeterGUIComponent item = new TestBeanGUI(c);
TestSuite ts = new TestSuite(item.getClass().getName());
ts.addTest(new JMeterTest("GUIComponents2", item));
ts.addTest(new JMeterTest("runGUITitle", item));
suite.addTest(ts);
} catch (IllegalArgumentException e) {
System.out.println("o.a.j.junit.JMeterTest Cannot create test for " + c.getName() + " " + e);
e.printStackTrace(System.out);
}
}
return suite;
}
use of org.apache.jmeter.gui.JMeterGUIComponent in project jmeter by apache.
the class Clear method doAction.
@Override
public void doAction(ActionEvent e) {
GuiPackage guiPackage = GuiPackage.getInstance();
final String actionCommand = e.getActionCommand();
if (actionCommand.equals(ActionNames.CLEAR)) {
JMeterGUIComponent guiComp = guiPackage.getCurrentGui();
if (guiComp instanceof Clearable) {
((Clearable) guiComp).clearData();
}
} else {
guiPackage.getMainFrame().clearData();
for (JMeterTreeNode node : guiPackage.getTreeModel().getNodesOfType(Clearable.class)) {
JMeterGUIComponent guiComp = guiPackage.getGui(node.getTestElement());
if (guiComp instanceof Clearable) {
Clearable item = (Clearable) guiComp;
try {
item.clearData();
} catch (Exception ex) {
log.error("Can't clear: {} {}", node, guiComp, ex);
}
}
}
}
}
use of org.apache.jmeter.gui.JMeterGUIComponent in project jmeter by apache.
the class EditCommand method doAction.
@Override
public void doAction(ActionEvent e) {
GuiPackage guiPackage = GuiPackage.getInstance();
JMeterGUIComponent currentGui = guiPackage.getCurrentGui();
guiPackage.getMainFrame().setMainPanel((javax.swing.JComponent) currentGui);
guiPackage.getMainFrame().setEditMenu(guiPackage.getTreeListener().getCurrentNode().createPopupMenu());
guiPackage.getMainFrame().setFileLoadEnabled(true);
guiPackage.getMainFrame().setFileSaveEnabled(true);
}
Aggregations