Hello, It is really a good idea, why not open a bugzilla and attach a patch for this ?
Thanks Regards On Fri, Jul 5, 2013 at 5:40 PM, Marko Vlahovic <[email protected]> wrote: > Hi > > *Problem Statement:* > In my daily work i used BeanShell elements extensively and i find them to > be very powerful giving the edge to jmeter over the other test frameworks. > However, writing Java or Python code in JTextArea is really painful and > error prone (and it can hurt the eyes too). > > *Proposal:* > I would like to propose to Jmeter Dev Community to include > rsyntaxtextarea-2.0.7.jar library that can do syntax highlighting, code > folding, undo typing, and redo typing. The library is published under BSD > license and more details can be found here: > http://fifesoft.com/rsyntaxtextarea/ > The jar file needs to be compiled from source (It is very easy to do. Took > me only 5 minutes to compile and add it to jmeter project in eclipse) > > *Implementation change Proposal:* > The following is the list of files that i changed to make Syntax > Highlighting work: > M > > src/protocol/java/org/apache/jmeter/protocol/java/control/gui/BeanShellSamplerGui.java > M > src/components/org/apache/jmeter/assertions/gui/BeanShellAssertionGui.java > ? src/core/org/apache/jmeter/testbeans/gui/textarea.properties > M src/core/org/apache/jmeter/testbeans/gui/TextAreaEditor.java > M src/core/org/apache/jmeter/testbeans/gui/WrapperEditor.java > M > src/core/org/apache/jmeter/testbeans/gui/GenericTestBeanCustomizer.java > > I also had to add the following in build.properties > rsyntaxtextarea.version = 2.0.7 > rsyntaxtextarea.jar = > rsyntaxtextarea-${rsyntaxtextarea.version}.jar > rsyntaxtextarea.md5 = a4bdaabc88ff5464002a43c654bbf856 > > the following in .classpath > <classpathentry kind="lib" path="lib/rsyntaxtextarea-2.0.7.jar"/> > > And the following in build.xml > <include name="${lib.dir}/${rsyntaxtextarea.jar}"/> > </patternset> > ... > <pathelement location="${lib.dir}/${xstream.jar}"/> > <pathelement location="${lib.dir}/${rsyntaxtextarea.jar}"/> > ... > > *Implementation Details** TextAreaEditor.java and textarea.properties*: > Instead of JTextArea, textUI uses RSyntaxTextArea. In order to have numbers > for lines i also changes the scroller to RTextScrollPane. > To support different languages from BSF and JSR elements new private field > languageProperties is added. This field keeps mapping between different > languages and syntaxes available in SyntaxConstants interface. Mappings are > defined in textarea.properties file Also the TextAreaEditor implements > PropertyChangeListener so that propertyChange events can be captured. In > summary: > > public class TextAreaEditor extends PropertyEditorSupport implements > FocusListener, PropertyChangeListener { > > private RSyntaxTextArea textUI; > > private RTextScrollPane scroller; > > private Properties languageProperties; > ... > private final void init() {// called from ctor, so must not be > overridable > textUI = new RSyntaxTextArea(20,20); > textUI.discardAllEdits(); > textUI.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA); > textUI.setCodeFoldingEnabled(true); > textUI.setAntiAliasingEnabled(true); > textUI.addFocusListener(this); > textUI.setWrapStyleWord(true); > textUI.setLineWrap(true); > scroller = new RTextScrollPane(textUI); > scroller.setFoldIndicatorEnabled(true); > languageProperties = > > JMeterUtils.loadProperties("org/apache/jmeter/testbeans/gui/textarea.properties"); > } > ... > @Override > public void propertyChange(PropertyChangeEvent evt){ > Object source = evt.getSource(); > if (source instanceof ComboStringEditor && source !=null){ > ComboStringEditor cse = (ComboStringEditor)source; > String lang = cse.getAsText().toLowerCase(); > if (languageProperties.containsKey(lang)){ > > textUI.setSyntaxEditingStyle(languageProperties.getProperty(lang)); > } > else{ > > textUI.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE); > } > > } > } > > *Implementation Details BeanShellAssertionGui.java and ** > BeanShellSamplerGui.java* > This is not a java bean element so direct change was applied: > > private RSyntaxTextArea scriptField;// script area > ... > private JPanel createScriptPanel() { > scriptField = new RSyntaxTextArea(20,20); > > scriptField.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA); > scriptField.setCodeFoldingEnabled(true); > scriptField.setAntiAliasingEnabled(true); > scriptField.setLineWrap(true); > scriptField.setWrapStyleWord(true); > ... > JPanel panel = new JPanel(new BorderLayout()); > panel.add(label, BorderLayout.NORTH); > panel.add(new RTextScrollPane(scriptField), BorderLayout.CENTER); > > > *Implementation Details **GenericTestBeanCustomizer.java* > Changes made here were necessary to enable Syntax Highlighting changes when > different language is selected in ComboBox in BSF and JSR elements. > > GenericTestBeanCustomizer(BeanInfo beanInfo) { > super(); > ... > // Added in the "for" loop for descriptors > //Find the index of textAreaEditor > if (propertyEditor instanceof TextAreaEditor) > { > textAreaEditorIndex = i; > } > > //Figure out the index of scriptLanguage ComboBOx > if (name.equals("scriptLanguage")){ > scriptLanguageIndex=i; > } > ... > > // This is after the for loop. In case of BSF and JSR elements i > want to add textAreaEditor as > // a listener to scriptLanguage ComboBox. > String beanName = this.beanInfo.getBeanDescriptor().getName(); > if (beanName.startsWith("BSF") || beanName.startsWith("JSR223")){ > WrapperEditor we = (WrapperEditor) > editors[scriptLanguageIndex]; > TextAreaEditor tae = (TextAreaEditor) > editors[textAreaEditorIndex]; > we.addChangeListener(tae); > } > ... > > *Implementation Details **WrapperEditor.java* > In the GenericTestBeanCustomizer constructor i used > e.addChangeListener(tae) > to add listener to comboBox. Consequently, WrapperEditor class had to be > modified, thus addChangeListener method is added that will do actual > listener adding on the guiEditor > > public void addChangeListener(PropertyChangeListener listener){ > guiEditor.addPropertyChangeListener(listener); > } > > *Conclusion* > I found Syntax Highlighting to significantly improve look and feel of > Scripting elements in Jmeter. Especially revording was to find that > RSyntaxTextArea has integrated undo/redo. It is available by simply right > clicking in the TextArea. > Nevertheless, all the changes proposed are cosmetic and up to you to decide > if it would be worth changing in Jmeter. > > Best Regards > Marko > -- Cordialement. Philippe Mouawad.
