Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotkeys to add elements #16

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions bin/jmeter.properties
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ not_in_menu=org.apache.jmeter.protocol.http.modifier.gui.ParamModifierGui, HTTP
# The bigger it is, the more it consumes memory
#undo.history.size=0

# Hotkeys to add JMeter components, will add elements when you press Ctrl+0 .. Ctrl+9
gui.quick_0=ThreadGroupGui
gui.quick_1=HttpTestSampleGui
gui.quick_2=RegexExtractorGui
gui.quick_3=AssertionGui
gui.quick_4=ConstantTimerGui
gui.quick_5=TestActionGui
gui.quick_6=JSR223PostProcessor
gui.quick_7=JSR223PreProcessor
gui.quick_8=DebugSampler
gui.quick_9=ViewResultsFullVisualizer

#---------------------------------------------------------------------------
# Remote hosts and RMI configuration
#---------------------------------------------------------------------------
Expand Down
54 changes: 54 additions & 0 deletions src/core/org/apache/jmeter/gui/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.DropMode;
import javax.swing.ImageIcon;
import javax.swing.InputMap;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
Expand All @@ -63,6 +66,7 @@
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.KeyStroke;
import javax.swing.MenuElement;
import javax.swing.SwingUtilities;
import javax.swing.tree.DefaultMutableTreeNode;
Expand All @@ -74,15 +78,19 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.gui.action.ActionNames;
import org.apache.jmeter.gui.action.ActionRouter;
import org.apache.jmeter.gui.action.KeyStrokes;
import org.apache.jmeter.gui.action.LoadDraggedFile;
import org.apache.jmeter.gui.tree.JMeterCellRenderer;
import org.apache.jmeter.gui.tree.JMeterTreeListener;
import org.apache.jmeter.gui.tree.JMeterTreeNode;
import org.apache.jmeter.gui.tree.JMeterTreeTransferHandler;
import org.apache.jmeter.gui.util.EscapeDialog;
import org.apache.jmeter.gui.util.JMeterMenuBar;
import org.apache.jmeter.gui.util.JMeterToolBar;
import org.apache.jmeter.gui.util.MenuFactory;
import org.apache.jmeter.samplers.Clearable;
import org.apache.jmeter.samplers.Remoteable;
import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.TestStateListener;
import org.apache.jmeter.threads.JMeterContextService;
Expand Down Expand Up @@ -647,9 +655,55 @@ public String getToolTipText(MouseEvent event) {
treevar.setDropMode(DropMode.ON_OR_INSERT);
treevar.setTransferHandler(new JMeterTreeTransferHandler());

addQuickComponentHotkeys(treevar);

return treevar;
}

private void addQuickComponentHotkeys(JTree treevar) {
Action quickComponent = new AbstractAction("Quick Component") {
@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) {
log.warn("Failed to perform quick component add: " + comp, err); // $NON-NLS-1$
}
}
};

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

/**
* Create the tree cell renderer used to draw the nodes in the test tree.
*
Expand Down
1 change: 1 addition & 0 deletions src/core/org/apache/jmeter/gui/action/ActionNames.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public final class ActionNames {
public static final String MOVE_RIGHT = "move_right"; // $NON-NLS-1$
public static final String UNDO = "undo"; // $NON-NLS-1$
public static final String REDO = "redo"; // $NON-NLS-1$
public static final String QUICK_COMPONENT = "quick_component"; // $NON-NLS-1$

// Prevent instantiation
private ActionNames(){
Expand Down
12 changes: 12 additions & 0 deletions src/core/org/apache/jmeter/gui/action/KeyStrokes.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ private KeyStrokes(){
public static final KeyStroke ALT_DOWN_ARROW = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.ALT_DOWN_MASK);
public static final KeyStroke ALT_LEFT_ARROW = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, InputEvent.ALT_DOWN_MASK);
public static final KeyStroke ALT_RIGHT_ARROW = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.ALT_DOWN_MASK);

// component hotkeys
public static final KeyStroke CTRL_0 = KeyStroke.getKeyStroke(KeyEvent.VK_0, CONTROL_MASK);
public static final KeyStroke CTRL_1 = KeyStroke.getKeyStroke(KeyEvent.VK_1, CONTROL_MASK);
public static final KeyStroke CTRL_2 = KeyStroke.getKeyStroke(KeyEvent.VK_2, CONTROL_MASK);
public static final KeyStroke CTRL_3 = KeyStroke.getKeyStroke(KeyEvent.VK_3, CONTROL_MASK);
public static final KeyStroke CTRL_4 = KeyStroke.getKeyStroke(KeyEvent.VK_4, CONTROL_MASK);
public static final KeyStroke CTRL_5 = KeyStroke.getKeyStroke(KeyEvent.VK_5, CONTROL_MASK);
public static final KeyStroke CTRL_6 = KeyStroke.getKeyStroke(KeyEvent.VK_6, CONTROL_MASK);
public static final KeyStroke CTRL_7 = KeyStroke.getKeyStroke(KeyEvent.VK_7, CONTROL_MASK);
public static final KeyStroke CTRL_8 = KeyStroke.getKeyStroke(KeyEvent.VK_8, CONTROL_MASK);
public static final KeyStroke CTRL_9 = KeyStroke.getKeyStroke(KeyEvent.VK_9, CONTROL_MASK);

/**
* Check if an event matches the KeyStroke definition.
Expand Down
1 change: 1 addition & 0 deletions xdocs/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Summary
<h3>General</h3>
<ul>
<li><bug>57913</bug>Automated backups of last saved JMX files. Contributed by Benoit Vatan (benoit.vatan at gmail.com)</li>
<li><bug>57988</bug> Shortcuts (Ctrl+1 .. Ctrl+9) to quick add elements into test plan. Implemented by Andrey Pokhilko (andrey at blazemeter.com) and contributed by BlazeMeter Ltd.</li>
</ul>
<ch_section>Non-functional changes</ch_section>
<ul>
Expand Down
52 changes: 52 additions & 0 deletions xdocs/usermanual/hints_and_tips.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,58 @@ values: <code>22x22</code> (default size), <code>32x32</code> or <code>48x48</co
</description>
</subsection>

<subsection name="&sect-num;.5 Adding Elements with Hotkeys" anchor="component_hotkeys">
<p>
When you do intense scripting with JMeter, there is a way to add elements to test plan quickly
with keyboard shortcuts. Default bindings are:
</p>
<dl>
<dt>
<code>Ctrl+0</code>
</dt>
<dd>Thread Group</dd>
<dt>
<code>Ctrl+1</code>
</dt>
<dd>HTTP Request</dd>
<dt>
<code>Ctrl+2</code>
</dt>
<dd>Regular Expression Extractor</dd>
<dt>
<code>Ctrl+3</code>
</dt>
<dd>Response Assertion</dd>
<dt>
<code>Ctrl+4</code>
</dt>
<dd>Constant Timer</dd>
<dt>
<code>Ctrl+5</code>
</dt>
<dd>Test Action</dd>
<dt>
<code>Ctrl+6</code>
</dt>
<dd>JSR223 PostProcessor</dd>
<dt>
<code>Ctrl+7</code>
</dt>
<dd>JSR223 PreProcessor</dd>
<dt>
<code>Ctrl+8</code>
</dt>
<dd>Debug Sampler</dd>
<dt>
<code>Ctrl+9</code>
</dt>
<dd>View Results Tree</dd>
</dl>
<p>
To change these binding, please find "gui.quick_*" properties within jmeter.properties file as example,
it is recommended to put overrides for them into user.properties file.
</p>
</subsection>
</section>

</body>
Expand Down