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;
}
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);
}
}
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);
}
}
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);
}
}
}
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;
}
Aggregations