use of org.apache.jmeter.gui.tree.JMeterTreeModel in project jmeter by apache.
the class ProxyControl method setAuthorization.
/**
* Find if there is any AuthManager in JMeterTreeModel
* If there is no one, create and add it to tree
* Add authorization object to AuthManager
* @param authorization {@link Authorization}
* @param target {@link JMeterTreeNode}
*/
private void setAuthorization(Authorization authorization, JMeterTreeNode target) {
JMeterTreeModel jmeterTreeModel = getJmeterTreeModel();
List<JMeterTreeNode> authManagerNodes = jmeterTreeModel.getNodesOfType(AuthManager.class);
if (authManagerNodes.isEmpty()) {
try {
log.debug("Creating HTTP Authentication manager for authorization:" + authorization);
AuthManager authManager = newAuthorizationManager(authorization);
jmeterTreeModel.addComponent(authManager, target);
} catch (IllegalUserActionException e) {
log.error("Failed to add Authorization Manager to target node:" + target.getName(), e);
}
} else {
AuthManager authManager = (AuthManager) authManagerNodes.get(0).getTestElement();
authManager.addAuth(authorization);
}
}
use of org.apache.jmeter.gui.tree.JMeterTreeModel in project jmeter by apache.
the class ProxyControl method notifyTestListenersOfStart.
/**
* This will notify test listeners directly within the Proxy that the 'test'
* (here meaning the proxy recording) has started.
*/
private void notifyTestListenersOfStart() {
JMeterTreeModel treeModel = getJmeterTreeModel();
JMeterTreeNode myNode = treeModel.getNodeOf(this);
Enumeration<JMeterTreeNode> kids = myNode.children();
while (kids.hasMoreElements()) {
JMeterTreeNode subNode = kids.nextElement();
if (subNode.isEnabled()) {
TestElement testElement = subNode.getTestElement();
if (testElement instanceof TestStateListener) {
((TestStateListener) testElement).testStarted();
}
}
}
}
use of org.apache.jmeter.gui.tree.JMeterTreeModel in project jmeter by apache.
the class GenerateTreeGui method actionPerformed.
@Override
public void actionPerformed(ActionEvent action) {
GuiPackage guiPackage = GuiPackage.getInstance();
JMeterTreeModel treeModel = guiPackage.getTreeModel();
JMeterTreeNode myTarget = findFirstNodeOfType(org.apache.jmeter.threads.ThreadGroup.class, treeModel);
if (myTarget == null) {
JMeterUtils.reportErrorToUser("Cannot find Thread Group");
return;
}
addElements(MenuFactory.CONTROLLERS, "Controllers", guiPackage, treeModel, myTarget);
addElements(MenuFactory.CONFIG_ELEMENTS, "Config Elements", guiPackage, treeModel, myTarget);
addElements(MenuFactory.TIMERS, "Timers", guiPackage, treeModel, myTarget);
addElements(MenuFactory.PRE_PROCESSORS, "Pre Processors", guiPackage, treeModel, myTarget);
addElements(MenuFactory.SAMPLERS, "Samplers", guiPackage, treeModel, myTarget);
addElements(MenuFactory.POST_PROCESSORS, "Post Processors", guiPackage, treeModel, myTarget);
addElements(MenuFactory.ASSERTIONS, "Assertions", guiPackage, treeModel, myTarget);
addElements(MenuFactory.LISTENERS, "Listeners", guiPackage, treeModel, myTarget);
}
use of org.apache.jmeter.gui.tree.JMeterTreeModel in project jmeter by apache.
the class UndoHistory method treeNodesInserted.
/**
* Record adding nodes as the undo step
*
* @param tme {@link TreeModelEvent} with event details
*/
@Override
public void treeNodesInserted(TreeModelEvent tme) {
String name = ((JMeterTreeNode) tme.getTreePath().getLastPathComponent()).getName();
log.debug("Nodes inserted {}", name);
final JMeterTreeModel sender = (JMeterTreeModel) tme.getSource();
add(sender, "Add " + name);
}
use of org.apache.jmeter.gui.tree.JMeterTreeModel in project jmeter by apache.
the class ChangeParent method changeParent.
private void changeParent(TestElement newParent, GuiPackage guiPackage, JMeterTreeNode currentNode) {
// keep the old name if it was not the default one
Controller currentController = (Controller) currentNode.getUserObject();
JMeterGUIComponent currentGui = guiPackage.getCurrentGui();
String defaultName = JMeterUtils.getResString(currentGui.getLabelResource());
if (StringUtils.isNotBlank(currentController.getName()) && !currentController.getName().equals(defaultName)) {
newParent.setName(currentController.getName());
}
JMeterTreeModel treeModel = guiPackage.getTreeModel();
JMeterTreeNode newNode = new JMeterTreeNode(newParent, treeModel);
JMeterTreeNode parentNode = (JMeterTreeNode) currentNode.getParent();
int index = parentNode.getIndex(currentNode);
treeModel.insertNodeInto(newNode, parentNode, index);
treeModel.removeNodeFromParent(currentNode);
int childCount = currentNode.getChildCount();
for (int i = 0; i < childCount; i++) {
// Using index 0 is voluntary as child is removed in next step and added to new parent
JMeterTreeNode node = (JMeterTreeNode) currentNode.getChildAt(0);
treeModel.removeNodeFromParent(node);
treeModel.insertNodeInto(node, newNode, newNode.getChildCount());
}
// select the node
TreeNode[] nodes = treeModel.getPathToRoot(newNode);
JTree tree = guiPackage.getTreeListener().getJTree();
tree.setSelectionPath(new TreePath(nodes));
}
Aggregations