Search in sources :

Example 76 with JMeterTreeNode

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

the class Duplicate method doAction.

@Override
public void doAction(ActionEvent e) {
    GuiPackage instance = GuiPackage.getInstance();
    JMeterTreeListener treeListener = instance.getTreeListener();
    JMeterTreeNode[] copiedNodes = Copy.cloneTreeNodes(treeListener.getSelectedNodes());
    JMeterTreeNode currentNode = treeListener.getCurrentNode();
    JMeterTreeNode parentNode = (JMeterTreeNode) currentNode.getParent();
    JMeterTreeModel treeModel = instance.getTreeModel();
    for (int nodeIndex = copiedNodes.length - 1; nodeIndex >= 0; nodeIndex--) {
        JMeterTreeNode copiedNode = copiedNodes[nodeIndex];
        int index = parentNode.getIndex(currentNode) + 1;
        treeModel.insertNodeInto(copiedNode, parentNode, index);
    }
    instance.getMainFrame().repaint();
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeListener(org.apache.jmeter.gui.tree.JMeterTreeListener) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Example 77 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 78 with JMeterTreeNode

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

the class Copy method doAction.

@Override
public void doAction(ActionEvent e) {
    JMeterTreeListener treeListener = GuiPackage.getInstance().getTreeListener();
    JMeterTreeNode[] nodes = treeListener.getSelectedNodes();
    nodes = keepOnlyAncestors(nodes);
    nodes = cloneTreeNodes(nodes);
    setCopiedNodes(nodes);
}
Also used : JMeterTreeListener(org.apache.jmeter.gui.tree.JMeterTreeListener) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Example 79 with JMeterTreeNode

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

the class Copy method cloneTreeNode.

public static JMeterTreeNode cloneTreeNode(JMeterTreeNode node) {
    JMeterTreeNode treeNode = (JMeterTreeNode) node.clone();
    treeNode.setUserObject(((TestElement) node.getUserObject()).clone());
    cloneChildren(treeNode, node);
    return treeNode;
}
Also used : JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Example 80 with JMeterTreeNode

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

the class Copy method cloneChildren.

@SuppressWarnings("JdkObsolete")
private static void cloneChildren(JMeterTreeNode to, JMeterTreeNode from) {
    Enumeration<?> enumFrom = from.children();
    while (enumFrom.hasMoreElements()) {
        JMeterTreeNode child = (JMeterTreeNode) enumFrom.nextElement();
        JMeterTreeNode childClone = (JMeterTreeNode) child.clone();
        childClone.setUserObject(((TestElement) child.getUserObject()).clone());
        to.add(childClone);
        cloneChildren((JMeterTreeNode) to.getLastChild(), child);
    }
}
Also used : JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Aggregations

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