Search in sources :

Example 1 with JMeterGUIComponent

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;
}
Also used : GuiPackage(org.apache.jmeter.gui.GuiPackage) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) JMeterGUIComponent(org.apache.jmeter.gui.JMeterGUIComponent) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) AbstractConfigGui(org.apache.jmeter.config.gui.AbstractConfigGui)

Example 2 with JMeterGUIComponent

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));
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TreeNode(javax.swing.tree.TreeNode) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) JMeterGUIComponent(org.apache.jmeter.gui.JMeterGUIComponent) Controller(org.apache.jmeter.control.Controller)

Example 3 with JMeterGUIComponent

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;
}
Also used : TestBeanGUI(org.apache.jmeter.testbeans.gui.TestBeanGUI) TestSuite(junit.framework.TestSuite) JMeterGUIComponent(org.apache.jmeter.gui.JMeterGUIComponent)

Example 4 with JMeterGUIComponent

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);
                }
            }
        }
    }
}
Also used : Clearable(org.apache.jmeter.samplers.Clearable) GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) JMeterGUIComponent(org.apache.jmeter.gui.JMeterGUIComponent)

Example 5 with JMeterGUIComponent

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);
}
Also used : GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterGUIComponent(org.apache.jmeter.gui.JMeterGUIComponent)

Aggregations

JMeterGUIComponent (org.apache.jmeter.gui.JMeterGUIComponent)8 GuiPackage (org.apache.jmeter.gui.GuiPackage)3 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)3 TestBeanGUI (org.apache.jmeter.testbeans.gui.TestBeanGUI)3 TestSuite (junit.framework.TestSuite)2 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)2 HeadlessException (java.awt.HeadlessException)1 IOException (java.io.IOException)1 JComponent (javax.swing.JComponent)1 JTree (javax.swing.JTree)1 TreeNode (javax.swing.tree.TreeNode)1 TreePath (javax.swing.tree.TreePath)1 AbstractConfigGui (org.apache.jmeter.config.gui.AbstractConfigGui)1 ObsoleteGui (org.apache.jmeter.config.gui.ObsoleteGui)1 Controller (org.apache.jmeter.control.Controller)1 JMeterTreeModel (org.apache.jmeter.gui.tree.JMeterTreeModel)1 Clearable (org.apache.jmeter.samplers.Clearable)1 Printable (org.apache.jmeter.visualizers.Printable)1