Search in sources :

Example 51 with JMeterTreeNode

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

the class ModuleControllerGui method findPathInTreeModel.

/**
     * Recursively traverse module to run tree in order to find JMeterTreeNode element given by testPlanPath
     * in a DefaultMutableTreeNode tree
     * 
     * @param level - current search level
     * @param testPlanPath - path of a test plan tree element
     * @param parent - module to run tree parent element
     * 
     * @return path of a found element 
     */
private TreeNode[] findPathInTreeModel(int level, TreeNode[] testPlanPath, DefaultMutableTreeNode parent) {
    if (level >= testPlanPath.length) {
        return EMPTY_TREE_NODES;
    }
    int childCount = parent.getChildCount();
    JMeterTreeNode searchedTreeNode = (JMeterTreeNode) testPlanPath[level];
    for (int i = 0; i < childCount; i++) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) parent.getChildAt(i);
        JMeterTreeNode childUserObj = (JMeterTreeNode) child.getUserObject();
        if (childUserObj.equals(searchedTreeNode)) {
            if (level == (testPlanPath.length - 1)) {
                return child.getPath();
            } else {
                return findPathInTreeModel(level + 1, testPlanPath, child);
            }
        }
    }
    return EMPTY_TREE_NODES;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Example 52 with JMeterTreeNode

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

the class ModuleControllerGui method reinitialize.

private void reinitialize() {
    ((DefaultMutableTreeNode) moduleToRunTreeModel.getRoot()).removeAllChildren();
    GuiPackage gp = GuiPackage.getInstance();
    JMeterTreeNode root;
    if (gp != null) {
        root = (JMeterTreeNode) GuiPackage.getInstance().getTreeModel().getRoot();
        buildTreeNodeModel(root, 0, null);
        moduleToRunTreeModel.nodeStructureChanged((TreeNode) moduleToRunTreeModel.getRoot());
    }
    if (selected != null) {
        //expand Module to run tree to selected node and set selection path to it
        this.focusSelectedOnTree(selected);
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Example 53 with JMeterTreeNode

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

the class ModuleControllerGui method focusSelectedOnTree.

/**
     * Expand module to run tree to selected JMeterTreeNode and set selection path to it
     * @param selected - referenced module to run
     */
private void focusSelectedOnTree(JMeterTreeNode selected) {
    TreeNode[] path = selected.getPath();
    TreeNode[] filteredPath = new TreeNode[path.length - 1];
    //ignore first element of path - WorkBench, (why WorkBench is appearing in the path ???)
    for (int i = 1; i < path.length; i++) {
        filteredPath[i - 1] = path[i];
    }
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) moduleToRunTreeNodes.getModel().getRoot();
    //treepath of test plan tree and module to run tree cannot be compared directly - moduleToRunTreeModel.getPathToRoot()
    //custom method for finding an JMeterTreeNode element in DefaultMutableTreeNode have to be used 
    TreeNode[] dmtnPath = this.findPathInTreeModel(1, filteredPath, root);
    if (dmtnPath.length > 0) {
        TreePath treePath = new TreePath(dmtnPath);
        moduleToRunTreeNodes.setSelectionPath(treePath);
        moduleToRunTreeNodes.scrollPathToVisible(treePath);
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 54 with JMeterTreeNode

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

the class ModuleControllerGui method actionPerformed.

/**
     * Implementation of Expand button - moves focus to a test plan tree element referenced by 
     * selected element in Module to run tree
     */
@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == expandButton) {
        JMeterTreeNode tn = null;
        DefaultMutableTreeNode selected = (DefaultMutableTreeNode) this.moduleToRunTreeNodes.getLastSelectedPathComponent();
        if (selected != null && selected.getUserObject() instanceof JMeterTreeNode) {
            tn = (JMeterTreeNode) selected.getUserObject();
        }
        if (tn != null) {
            TreePath treePath = new TreePath(tn.getPath());
            //changing selection in a test plan tree
            GuiPackage.getInstance().getTreeListener().getJTree().setSelectionPath(treePath);
            //expanding tree to make referenced element visible in test plan tree
            GuiPackage.getInstance().getTreeListener().getJTree().scrollPathToVisible(treePath);
        }
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Example 55 with JMeterTreeNode

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

the class ModuleController method cloneTreeNode.

private 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)

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