Search in sources :

Example 56 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.

the class ModuleController method setNodePath.

private void setNodePath() {
    List<String> nodePath = new ArrayList<>();
    if (selectedNode != null) {
        TreeNode[] path = selectedNode.getPath();
        for (TreeNode node : path) {
            nodePath.add(((JMeterTreeNode) node).getName());
        }
    }
    setProperty(new CollectionProperty(NODE_PATH, nodePath));
}
Also used : CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TreeNode(javax.swing.tree.TreeNode) ArrayList(java.util.ArrayList)

Example 57 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.

the class JMeter method convertSubTree.

/**
     * Remove disabled elements
     * Replace the ReplaceableController with the target subtree
     *
     * @param tree The {@link HashTree} to convert
     */
public static void convertSubTree(HashTree tree) {
    LinkedList<Object> copyList = new LinkedList<>(tree.list());
    for (Object o : copyList) {
        if (o instanceof TestElement) {
            TestElement item = (TestElement) o;
            if (item.isEnabled()) {
                if (item instanceof ReplaceableController) {
                    ReplaceableController rc = ensureReplaceableControllerIsLoaded(item);
                    HashTree subTree = tree.getTree(item);
                    if (subTree != null) {
                        HashTree replacementTree = rc.getReplacementSubTree();
                        if (replacementTree != null) {
                            convertSubTree(replacementTree);
                            tree.replaceKey(item, rc);
                            tree.set(rc, replacementTree);
                        }
                    }
                } else {
                    // not Replaceable Controller
                    convertSubTree(tree.getTree(item));
                }
            } else {
                // Not enabled
                tree.remove(item);
            }
        } else {
            // Not a TestElement
            JMeterTreeNode item = (JMeterTreeNode) o;
            if (item.isEnabled()) {
                // @see StandardJMeterEngine.run()
                if (item.getUserObject() instanceof ReplaceableController) {
                    TestElement controllerAsItem = item.getTestElement();
                    ReplaceableController rc = ensureReplaceableControllerIsLoaded(controllerAsItem);
                    HashTree subTree = tree.getTree(item);
                    if (subTree != null) {
                        HashTree replacementTree = rc.getReplacementSubTree();
                        if (replacementTree != null) {
                            convertSubTree(replacementTree);
                            tree.replaceKey(item, rc);
                            tree.set(rc, replacementTree);
                        }
                    }
                } else {
                    // Not a ReplaceableController
                    convertSubTree(tree.getTree(item));
                    TestElement testElement = item.getTestElement();
                    tree.replaceKey(item, testElement);
                }
            } else {
                // Not enabled
                tree.remove(item);
            }
        }
    }
}
Also used : HashTree(org.apache.jorphan.collections.HashTree) ReplaceableController(org.apache.jmeter.control.ReplaceableController) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TestElement(org.apache.jmeter.testelement.TestElement) RemoteThreadsListenerTestElement(org.apache.jmeter.threads.RemoteThreadsListenerTestElement) LinkedList(java.util.LinkedList)

Example 58 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.

the class RecordController method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == clearButton) {
        GuiPackage guiPackage = GuiPackage.getInstance();
        JMeterTreeNode currentNode = guiPackage.getTreeListener().getCurrentNode();
        if (!(currentNode.getUserObject() instanceof org.apache.jmeter.protocol.http.control.RecordingController)) {
            Toolkit.getDefaultToolkit().beep();
            return;
        }
        try {
            guiPackage.updateCurrentNode();
            JMeterTreeModel treeModel = guiPackage.getTreeModel();
            int childCount = currentNode.getChildCount();
            for (int i = 0; i < childCount; i++) {
                JMeterTreeNode node = (JMeterTreeNode) currentNode.getChildAt(0);
                treeModel.removeNodeFromParent(node);
            }
        } catch (Exception err) {
            Toolkit.getDefaultToolkit().beep();
            log.error("Error while removing recorded samples", err);
        }
    }
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) RecordingController(org.apache.jmeter.protocol.http.control.RecordingController)

Example 59 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode 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);
    }
}
Also used : TreePath(javax.swing.tree.TreePath) GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TestElement(org.apache.jmeter.testelement.TestElement)

Example 60 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.

the class ApplyNamingConvention method applyNamingPolicyToCurrentNode.

/**
     * Apply the naming policy of currentNode children
     * @param guiPackage {@link GuiPackage}
     * @param currentNode Parent node of elements on which we apply naming policy
     */
private void applyNamingPolicyToCurrentNode(GuiPackage guiPackage, JMeterTreeNode currentNode) {
    TreeNodeNamingPolicy namingPolicy = guiPackage.getNamingPolicy();
    guiPackage.updateCurrentNode();
    Enumeration<JMeterTreeNode> enumeration = currentNode.children();
    int index = 0;
    namingPolicy.resetState(currentNode);
    while (enumeration.hasMoreElements()) {
        JMeterTreeNode childNode = enumeration.nextElement();
        namingPolicy.rename(currentNode, childNode, index);
        index++;
    }
}
Also used : JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Aggregations

JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)68 GuiPackage (org.apache.jmeter.gui.GuiPackage)21 JMeterTreeModel (org.apache.jmeter.gui.tree.JMeterTreeModel)18 TestElement (org.apache.jmeter.testelement.TestElement)18 TreePath (javax.swing.tree.TreePath)10 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)10 IOException (java.io.IOException)7 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)7 TestPlan (org.apache.jmeter.testelement.TestPlan)7 HashTree (org.apache.jorphan.collections.HashTree)7 ActionEvent (java.awt.event.ActionEvent)6 JTree (javax.swing.JTree)6 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)6 Controller (org.apache.jmeter.control.Controller)6 JMeterTreeListener (org.apache.jmeter.gui.tree.JMeterTreeListener)6 TreeNode (javax.swing.tree.TreeNode)5 LinkedList (java.util.LinkedList)4 JMeterGUIComponent (org.apache.jmeter.gui.JMeterGUIComponent)4 WorkBench (org.apache.jmeter.testelement.WorkBench)4 ListedHashTree (org.apache.jorphan.collections.ListedHashTree)4