use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.
the class MainFrame method addQuickComponentHotkeys.
private void addQuickComponentHotkeys(JTree treevar) {
Action quickComponent = new AbstractAction("Quick Component") {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent actionEvent) {
String propname = "gui.quick_" + actionEvent.getActionCommand();
String comp = JMeterUtils.getProperty(propname);
log.debug("Event {}: {}", propname, comp);
if (comp == null) {
log.warn("No component set through property: {}", propname);
return;
}
GuiPackage guiPackage = GuiPackage.getInstance();
try {
guiPackage.updateCurrentNode();
TestElement testElement = guiPackage.createTestElement(SaveService.aliasToClass(comp));
JMeterTreeNode parentNode = guiPackage.getCurrentNode();
while (!MenuFactory.canAddTo(parentNode, testElement)) {
parentNode = (JMeterTreeNode) parentNode.getParent();
}
if (parentNode.getParent() == null) {
log.debug("Cannot add element on very top level");
} else {
JMeterTreeNode node = guiPackage.getTreeModel().addComponent(testElement, parentNode);
guiPackage.getMainFrame().getTree().setSelectionPath(new TreePath(node.getPath()));
}
} catch (Exception err) {
// $NON-NLS-1$
log.warn("Failed to perform quick component add: {}", comp, err);
}
}
};
InputMap inputMap = treevar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
KeyStroke[] keyStrokes = new KeyStroke[] { KeyStrokes.CTRL_0, KeyStrokes.CTRL_1, KeyStrokes.CTRL_2, KeyStrokes.CTRL_3, KeyStrokes.CTRL_4, KeyStrokes.CTRL_5, KeyStrokes.CTRL_6, KeyStrokes.CTRL_7, KeyStrokes.CTRL_8, KeyStrokes.CTRL_9 };
for (int n = 0; n < keyStrokes.length; n++) {
treevar.getActionMap().put(ActionNames.QUICK_COMPONENT + String.valueOf(n), quickComponent);
inputMap.put(keyStrokes[n], ActionNames.QUICK_COMPONENT + String.valueOf(n));
}
}
use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.
the class ApplyNamingConvention method doAction.
@Override
public void doAction(ActionEvent e) {
GuiPackage guiPackage = GuiPackage.getInstance();
JMeterTreeNode currentNode = guiPackage.getTreeListener().getCurrentNode();
if (!(currentNode.getUserObject() instanceof Controller)) {
Toolkit.getDefaultToolkit().beep();
return;
}
try {
applyNamingPolicyToCurrentNode(guiPackage, currentNode);
} catch (Exception err) {
Toolkit.getDefaultToolkit().beep();
log.error("Failed to apply naming policy", err);
JMeterUtils.reportErrorToUser("Failed to apply naming policy", err);
}
}
use of org.apache.jmeter.gui.tree.JMeterTreeNode 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));
}
use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.
the class ChangeParent method doAction.
@Override
public void doAction(ActionEvent e) {
String name = ((Component) e.getSource()).getName();
GuiPackage guiPackage = GuiPackage.getInstance();
JMeterTreeNode currentNode = guiPackage.getTreeListener().getCurrentNode();
if (!(currentNode.getUserObject() instanceof Controller)) {
Toolkit.getDefaultToolkit().beep();
return;
}
try {
guiPackage.updateCurrentNode();
TestElement controller = guiPackage.createTestElement(name);
changeParent(controller, guiPackage, currentNode);
} catch (Exception err) {
Toolkit.getDefaultToolkit().beep();
log.error("Failed to change parent", err);
}
}
use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.
the class UndoHistory method add.
/**
* Add tree model copy to the history
* <p>
* This method relies on the rule that the record in history made AFTER
* change has been made to test plan
*
* @param treeModel JMeterTreeModel
* @param comment String
*/
public void add(JMeterTreeModel treeModel, String comment) {
if (!isEnabled()) {
log.debug("undo.history.size is set to 0, undo/redo feature is disabled");
return;
}
// don't add element if we are in the middle of undo/redo or a big loading
if (working) {
log.debug("Not adding history because of noop");
return;
}
JMeterTreeNode root = (JMeterTreeNode) treeModel.getRoot();
if (root.getChildCount() < 1) {
log.debug("Not adding history because of no children");
return;
}
String name = root.getName();
log.debug("Adding history element {}: {}", name, comment);
working = true;
// get test plan tree
HashTree tree = treeModel.getCurrentSubTree((JMeterTreeNode) treeModel.getRoot());
// first clone to not convert original tree
tree = (HashTree) tree.getTree(tree.getArray()[0]).clone();
position++;
while (history.size() > position) {
if (log.isDebugEnabled()) {
log.debug("Removing further record, position: {}, size: {}", position, history.size());
}
history.remove(history.size() - 1);
}
// cloning is required because we need to immute stored data
HashTree copy = UndoCommand.convertAndCloneSubTree(tree);
history.add(new UndoHistoryItem(copy, comment));
log.debug("Added history element, position: {}, size: {}", position, history.size());
working = false;
notifyListeners();
}
Aggregations