jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject svn commit: r1841688 - in /jmeter/trunk: src/core/org/apache/jmeter/testbeans/gui/FieldStringEditor.java xdocs/changes.xml
Date Sat, 22 Sep 2018 16:10:00 GMT
Author: fschumacher
Date: Sat Sep 22 16:10:00 2018
New Revision: 1841688

URL: http://svn.apache.org/viewvc?rev=1841688&view=rev
Log:
Allow null values in FieldStringEditor.

Based on patch by Mingun (alexander_sergey at mail.ru)
Closes #394

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/FieldStringEditor.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/FieldStringEditor.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/FieldStringEditor.java?rev=1841688&r1=1841687&r2=1841688&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/FieldStringEditor.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/FieldStringEditor.java Sat Sep 22
16:10:00 2018
@@ -27,7 +27,7 @@ import javax.swing.JTextField;
 
 
 /**
- * This class implements a property editor for non-null String properties that
+ * This class implements a property editor for possible null String properties that
  * supports custom editing (i.e.: provides a GUI component) based on a text
  * field.
  * <p>
@@ -47,7 +47,7 @@ class FieldStringEditor extends Property
      * Value on which we started the editing. Used to avoid firing
      * PropertyChanged events when there's not been such change.
      */
-    private String initialValue = "";
+    private String initialValue;
 
     protected FieldStringEditor() {
         super();
@@ -55,6 +55,7 @@ class FieldStringEditor extends Property
         textField = new JTextField();
         textField.addActionListener(this);
         textField.addFocusListener(this);
+        initialValue = textField.getText();
     }
 
     @Override
@@ -77,8 +78,10 @@ class FieldStringEditor extends Property
     public void setValue(Object value) {
         if (value instanceof String) {
             setAsText((String) value);
+        } else if (value == null) {
+            setAsText("");
         } else {
-            throw new IllegalArgumentException();
+            throw new IllegalArgumentException("Expected String but got " + value.getClass()
+ ", value=" + value);
         }
     }
 
@@ -99,7 +102,7 @@ class FieldStringEditor extends Property
     public void firePropertyChange() {
         String newValue = getAsText();
 
-        if (initialValue.equals(newValue)) {
+        if (equalOldValueOrBothNull(newValue)) {
             return;
         }
         initialValue = newValue;
@@ -107,6 +110,10 @@ class FieldStringEditor extends Property
         super.firePropertyChange();
     }
 
+    private boolean equalOldValueOrBothNull(String newValue) {
+        return initialValue != null && initialValue.equals(newValue) || initialValue
== null && newValue == null;
+    }
+
     /**
      * {@inheritDoc}
      */

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1841688&r1=1841687&r2=1841688&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Sat Sep 22 16:10:00 2018
@@ -108,6 +108,7 @@ Summary
 
 <h3>General</h3>
 <ul>
+  <li><pr>394</pr>Allow <code>null</code> values in <code>FieldStringEditor</code>.
Based on patch by Mingun (alexander_sergey at mail.ru)</li>
 </ul>
 
 <ch_section>Non-functional changes</ch_section>
@@ -168,6 +169,7 @@ Summary
 </p>
 <ul>
     <li>Till Neunast (https://github.com/tilln)</li>
+    <li>Mingun (alexander_sergey at mail.ru)</li>
 </ul>
 <p>We also thank bug reporters who helped us improve JMeter.</p>
 <p>



Mime
View raw message