Search in sources :

Example 11 with JMeterTreeNode

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

the class ResetSearchCommand method doAction.

/**
     * @see Command#doAction(ActionEvent)
     */
@Override
public void doAction(ActionEvent e) {
    GuiPackage guiPackage = GuiPackage.getInstance();
    JMeterTreeModel jMeterTreeModel = guiPackage.getTreeModel();
    for (JMeterTreeNode jMeterTreeNode : jMeterTreeModel.getNodesOfType(Searchable.class)) {
        if (jMeterTreeNode.getUserObject() instanceof Searchable) {
            List<JMeterTreeNode> matchingNodes = jMeterTreeNode.getPathToThreadGroup();
            for (JMeterTreeNode jMeterTreeNode2 : matchingNodes) {
                jMeterTreeNode2.setMarkedBySearch(false);
            }
        }
    }
    GuiPackage.getInstance().getMainFrame().repaint();
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) Searchable(org.apache.jmeter.gui.Searchable)

Example 12 with JMeterTreeNode

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

the class Load method insertLoadedTree.

/**
     * Inserts (or merges) the tree into the GUI.
     * Does not check if the previous tree has been saved.
     * Clears the existing GUI test plan if we are inserting a complete plan.
     * @param id the id for the ActionEvent that is created
     * @param tree the tree to load
     * @param merging true if the tree is to be merged; false if it is to replace the existing tree
     * @return true if the loaded tree was a full test plan
     * @throws IllegalUserActionException if the tree cannot be merged at the selected position or the tree is empty
     */
// Does not appear to be used externally; called by #loadProjectFile()
public static boolean insertLoadedTree(final int id, final HashTree tree, final boolean merging) throws IllegalUserActionException {
    if (tree == null) {
        throw new IllegalUserActionException("Empty TestPlan or error reading test plan - see log file");
    }
    final boolean isTestPlan = tree.getArray()[0] instanceof TestPlan;
    // If we are loading a new test plan, initialize the tree with the testplan node we are loading
    final GuiPackage guiInstance = GuiPackage.getInstance();
    if (isTestPlan && !merging) {
        // Why does this not call guiInstance.clearTestPlan() ?
        // Is there a reason for not clearing everything?
        guiInstance.clearTestPlan((TestElement) tree.getArray()[0]);
    }
    if (merging) {
        // Check if target of merge is reasonable
        final TestElement te = (TestElement) tree.getArray()[0];
        if (!(te instanceof WorkBench || te instanceof TestPlan)) {
            // These are handled specially by addToTree
            final boolean ok = MenuFactory.canAddTo(guiInstance.getCurrentNode(), te);
            if (!ok) {
                String name = te.getName();
                String className = te.getClass().getName();
                className = className.substring(className.lastIndexOf('.') + 1);
                throw new IllegalUserActionException("Can't merge " + name + " (" + className + ") here");
            }
        }
    }
    final HashTree newTree = guiInstance.addSubTree(tree);
    guiInstance.updateCurrentGui();
    guiInstance.getMainFrame().getTree().setSelectionPath(new TreePath(((JMeterTreeNode) newTree.getArray()[0]).getPath()));
    final HashTree subTree = guiInstance.getCurrentSubTree();
    // Send different event wether we are merging a test plan into another test plan,
    // or loading a testplan from scratch
    ActionEvent actionEvent = new ActionEvent(subTree.get(subTree.getArray()[subTree.size() - 1]), id, merging ? ActionNames.SUB_TREE_MERGED : ActionNames.SUB_TREE_LOADED);
    ActionRouter.getInstance().actionPerformed(actionEvent);
    final JTree jTree = guiInstance.getMainFrame().getTree();
    if (EXPAND_TREE && !merging) {
        // don't automatically expand when merging
        for (int i = 0; i < jTree.getRowCount(); i++) {
            jTree.expandRow(i);
        }
    } else {
        jTree.expandRow(0);
    }
    jTree.setSelectionPath(jTree.getPathForRow(1));
    FocusRequester.requestFocus(jTree);
    return isTestPlan;
}
Also used : HashTree(org.apache.jorphan.collections.HashTree) TestPlan(org.apache.jmeter.testelement.TestPlan) ActionEvent(java.awt.event.ActionEvent) TestElement(org.apache.jmeter.testelement.TestElement) WorkBench(org.apache.jmeter.testelement.WorkBench) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) GuiPackage(org.apache.jmeter.gui.GuiPackage) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Example 13 with JMeterTreeNode

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

the class Move method doAction.

/**
     * @see Command#doAction(ActionEvent)
     */
@Override
public void doAction(ActionEvent e) {
    JMeterTreeListener treeListener = GuiPackage.getInstance().getTreeListener();
    if (treeListener.getSelectedNodes().length != 1) {
        // we can only move a single node
        return;
    }
    JMeterTreeNode currentNode = treeListener.getCurrentNode();
    JMeterTreeNode parentNode = getParentNode(currentNode);
    if (parentNode != null) {
        String action = e.getActionCommand();
        int index = parentNode.getIndex(currentNode);
        if (ActionNames.MOVE_UP.equals(action)) {
            if (index > 0) {
                // we stay within the same parent node
                int newIndx = index - 1;
                moveAndSelectNode(currentNode, parentNode, newIndx);
            }
        } else if (ActionNames.MOVE_DOWN.equals(action)) {
            if (index < parentNode.getChildCount() - 1) {
                // we stay within the same parent node
                int newIndx = index + 1;
                moveAndSelectNode(currentNode, parentNode, newIndx);
            }
        } else if (ActionNames.MOVE_LEFT.equals(action)) {
            JMeterTreeNode parentParentNode = getParentNode(parentNode);
            // move to the parent
            if (parentParentNode != null && canAddTo(parentParentNode, currentNode)) {
                moveAndSelectNode(currentNode, parentParentNode, parentParentNode.getIndex(parentNode));
            }
        } else if (ActionNames.MOVE_RIGHT.equals(action)) {
            JMeterTreeNode after = (JMeterTreeNode) parentNode.getChildAfter(currentNode);
            if (after != null && canAddTo(after, currentNode)) {
                // move as a child of the next sibling
                moveAndSelectNode(currentNode, after, 0);
            }
        // Commented as per sebb 
        // http://mail-archives.apache.org/mod_mbox/jmeter-dev/201307.mbox/%3CCAOGo0VZ0z3GMbfsq_gSB%2Bp7nTUqLng6Gy2ecvYbD8_AKb-Dt5w%40mail.gmail.com%3E
        /*
                else {
                    // move as a sibling of the parent
                    JMeterTreeNode parentParentNode = getParentNode(parentNode);
                    after = (JMeterTreeNode) parentParentNode
                            .getChildAfter(parentNode);
                    if (after != null
                            && canAddTo(parentParentNode, currentNode)) {
                        moveAndSelectNode(currentNode, parentParentNode,
                                parentParentNode.getIndex(after));
                    }
                }
                */
        }
    }
    GuiPackage.getInstance().getMainFrame().repaint();
}
Also used : JMeterTreeListener(org.apache.jmeter.gui.tree.JMeterTreeListener) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Example 14 with JMeterTreeNode

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

the class Move method moveAndSelectNode.

private static void moveAndSelectNode(JMeterTreeNode currentNode, JMeterTreeNode parentNode, int newIndx) {
    GuiPackage guiInstance = GuiPackage.getInstance();
    guiInstance.getTreeModel().removeNodeFromParent(currentNode);
    guiInstance.getTreeModel().insertNodeInto(currentNode, parentNode, newIndx);
    // select the node
    TreeNode[] nodes = guiInstance.getTreeModel().getPathToRoot(currentNode);
    JTree jTree = guiInstance.getMainFrame().getTree();
    jTree.setSelectionPath(new TreePath(nodes));
}
Also used : JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TreeNode(javax.swing.tree.TreeNode)

Example 15 with JMeterTreeNode

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

the class Cut method doAction.

/**
     * @see Command#doAction(ActionEvent)
     */
@Override
public void doAction(ActionEvent e) {
    GuiPackage guiPack = GuiPackage.getInstance();
    JMeterTreeNode[] currentNodes = guiPack.getTreeListener().getSelectedNodes();
    currentNodes = Copy.keepOnlyAncestors(currentNodes);
    Copy.setCopiedNodes(currentNodes);
    for (JMeterTreeNode currentNode : currentNodes) {
        guiPack.getTreeModel().removeNodeFromParent(currentNode);
    }
    guiPack.getMainFrame().repaint();
}
Also used : GuiPackage(org.apache.jmeter.gui.GuiPackage) 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