This is an automated email from the ASF dual-hosted git repository. pmouawad pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/jmeter.git
The following commit(s) were added to refs/heads/master by this push: new 2b783f9 Bug 64275: Function Helper Dialog: Improve UX 2b783f9 is described below commit 2b783f96ae798d62db9d3645e268d83a3aac7c72 Author: pmouawad <p.moua...@ubik-ingenierie.com> AuthorDate: Sun May 3 21:39:18 2020 +0200 Bug 64275: Function Helper Dialog: Improve UX Allow lookup of function name when typing first characters --- .../apache/jmeter/functions/gui/FunctionHelper.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/core/src/main/java/org/apache/jmeter/functions/gui/FunctionHelper.java b/src/core/src/main/java/org/apache/jmeter/functions/gui/FunctionHelper.java index c2cb842..06bf4a4 100644 --- a/src/core/src/main/java/org/apache/jmeter/functions/gui/FunctionHelper.java +++ b/src/core/src/main/java/org/apache/jmeter/functions/gui/FunctionHelper.java @@ -26,6 +26,7 @@ import java.io.Reader; import java.io.StringReader; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; import javax.swing.AbstractAction; import javax.swing.Action; @@ -79,6 +80,8 @@ public class FunctionHelper extends JDialog implements ActionListener, ChangeLis private static final String RESET_VARS = "RESET_VARS"; + private static final String FUNCTION_PREFIX = "__"; + private JLabeledChoice functionList; private ArgumentsPanel parameterPanel; @@ -172,7 +175,8 @@ public class FunctionHelper extends JDialog implements ActionListener, ChangeLis private void initializeFunctionList() { String[] functionNames = CompoundVariable.getFunctionNames(); Arrays.sort(functionNames, String::compareToIgnoreCase); - functionList = new JLabeledChoice(JMeterUtils.getResString("choose_function"), functionNames); //$NON-NLS-1$ + functionList = new JLabeledChoice(JMeterUtils.getResString("choose_function"), + Arrays.stream(functionNames).map(e -> e.substring(FUNCTION_PREFIX.length())).collect(Collectors.toList()).toArray(new String[0])); //$NON-NLS-1$ functionList.addChangeListener(this); } @@ -198,7 +202,7 @@ public class FunctionHelper extends JDialog implements ActionListener, ChangeLis */ protected void initParameterPanel() throws InstantiationException, IllegalAccessException { Arguments args = new Arguments(); - Function function = CompoundVariable.getFunctionClass(functionList.getText()).newInstance(); + Function function = CompoundVariable.getFunctionClass(getFunctionName(functionList.getText())).newInstance(); List<String> argumentDesc = function.getArgumentDesc(); for (String help : argumentDesc) { args.addArgument(help, ""); //$NON-NLS-1$ @@ -207,11 +211,19 @@ public class FunctionHelper extends JDialog implements ActionListener, ChangeLis parameterPanel.revalidate(); } + /** + * @param text Function name without __ prefix + * @return String function name with __ prefix + */ + private static final String getFunctionName(String text) { + return FUNCTION_PREFIX+text; + } + @Override public void actionPerformed(ActionEvent e) { String actionCommand = e.getActionCommand(); if(GENERATE.equals(actionCommand)) { - String functionName = functionList.getText(); + String functionName = getFunctionName(functionList.getText()); Arguments args = (Arguments) parameterPanel.createTestElement(); String functionCall = buildFunctionCallString(functionName, args); cutPasteFunction.setText(functionCall); @@ -310,7 +322,7 @@ public class FunctionHelper extends JDialog implements ActionListener, ChangeLis private class HelpListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { - String[] source = new String[] { Help.HELP_FUNCTIONS, functionList.getText() }; + String[] source = new String[] { Help.HELP_FUNCTIONS, getFunctionName(functionList.getText()) }; ActionRouter.getInstance().doActionNow( new ActionEvent(source, e.getID(), ActionNames.HELP));