You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by se...@apache.org on 2013/08/16 19:58:02 UTC

svn commit: r1514823 - in /jmeter/trunk: src/core/org/apache/jmeter/testbeans/gui/ComboStringEditor.java src/core/org/apache/jmeter/testbeans/gui/FileEditor.java src/core/org/apache/jmeter/testbeans/gui/GenericTestBeanCustomizer.java xdocs/changes.xml

Author: sebb
Date: Fri Aug 16 17:58:01 2013
New Revision: 1514823

URL: http://svn.apache.org/r1514823
Log:
ComboStringEditor could be simplified to make most settings final
Bugzilla Id: 55435

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

Modified: jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/ComboStringEditor.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/ComboStringEditor.java?rev=1514823&r1=1514822&r2=1514823&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/ComboStringEditor.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/ComboStringEditor.java Fri Aug 16 17:58:01 2013
@@ -20,7 +20,6 @@ import java.awt.Component;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
 import java.beans.PropertyEditorSupport;
-import java.util.Arrays;
 
 import javax.swing.DefaultComboBoxModel;
 import javax.swing.JComboBox;
@@ -45,21 +44,12 @@ import org.apache.jmeter.util.JMeterUtil
  */
 class ComboStringEditor extends PropertyEditorSupport implements ItemListener {
 
-    /**
-     * The list of options to be offered by this editor.
-     */
-    private String[] tags = new String[0];
-
-    /**
-     * True iif the editor should not accept (nor produce) a null value.
-     */
-    private boolean noUndefined = false;
+    private static final String[] EMPTY_STRING_ARRAY = new String[0];
 
     /**
-     * True iif the editor should not accept (nor produce) any non-null values
-     * different from the provided tags.
+     * The list of options to be offered by this editor.
      */
-    private boolean noEdit = false;
+    private final String[] tags;
 
     /**
      * The edited property's default value.
@@ -85,12 +75,27 @@ class ComboStringEditor extends Property
 
     private static final Object EDIT = new UniqueObject(JMeterUtils.getResString("property_edit")); //$NON-NLS-1$
 
+    @Deprecated // only for use from test code
     ComboStringEditor() {
+        this(null, false, false);
+    }
+
+    ComboStringEditor(String []tags, boolean noEdit, boolean noUndefined) {
         // Create the combo box we will use to edit this property:
 
+        this.tags = tags == null ? EMPTY_STRING_ARRAY : tags;
+
         model = new DefaultComboBoxModel();
-        model.addElement(UNDEFINED);
-        model.addElement(EDIT);
+
+        if (!noUndefined) {
+            model.addElement(UNDEFINED);
+        }
+        for (String tag : this.tags) {
+            model.addElement(tag);
+        }
+        if (!noEdit) {
+            model.addElement(EDIT);
+        }
 
         combo = new JComboBox(model);
         combo.addItemListener(this);
@@ -131,7 +136,7 @@ class ComboStringEditor extends Property
         if (value == UNDEFINED) {
             return null;
         }
-        return (String) value;
+        return (String) value; // TODO I10N
     }
 
     /**
@@ -152,7 +157,7 @@ class ComboStringEditor extends Property
         if (value == null) {
             combo.setSelectedItem(UNDEFINED);
         } else {
-            combo.setSelectedItem(value);
+            combo.setSelectedItem(value); // TODO I10N
         }
 
         if (!startingEdit && combo.getSelectedIndex() >= 0) {
@@ -187,7 +192,7 @@ class ComboStringEditor extends Property
 
         textField.requestFocus();
 
-        String text = initialEditValue;
+        String text = initialEditValue; // TODO I10N
         if (initialEditValue == null) {
             text = ""; // will revert to last valid value if invalid
         }
@@ -206,14 +211,6 @@ class ComboStringEditor extends Property
         return initialEditValue;
     }
 
-    public boolean getNoEdit() {
-        return noEdit;
-    }
-
-    public boolean getNoUndefined() {
-        return noUndefined;
-    }
-
     /**
      * {@inheritDoc}
      */
@@ -230,58 +227,6 @@ class ComboStringEditor extends Property
     }
 
     /**
-     * @param b
-     */
-    public void setNoEdit(boolean b) {
-        if (noEdit == b) {
-            return;
-        }
-        noEdit = b;
-
-        if (noEdit) {
-            model.removeElement(EDIT);
-        } else {
-            model.addElement(EDIT);
-        }
-    }
-
-    /**
-     * @param b
-     */
-    public void setNoUndefined(boolean b) {
-        if (noUndefined == b) {
-            return;
-        }
-        noUndefined = b;
-
-        if (noUndefined) {
-            model.removeElement(UNDEFINED);
-        } else {
-            model.insertElementAt(UNDEFINED, 0);
-        }
-    }
-
-    /**
-     * @param strings
-     */
-    public void setTags(String[] strings) {
-        if (Arrays.equals(tags,strings)) {
-            return;
-        }
-
-        for (int i = 0; i < tags.length; i++) {
-            model.removeElement(tags[i]);
-        }
-
-        tags = strings == null ? new String[0] : strings;
-
-        int b = noUndefined ? 0 : 1; // base index for tags
-        for (int i = 0; i < tags.length; i++) {
-            model.insertElementAt(tags[i], b + i);
-        }
-    }
-
-    /**
      * This is a funny hack: if you use a plain String, entering the text of the
      * string in the editor will make the combo revert to that option -- which
      * actually amounts to making that string 'reserved'. I preferred to avoid

Modified: jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/FileEditor.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/FileEditor.java?rev=1514823&r1=1514822&r2=1514823&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/FileEditor.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/FileEditor.java Fri Aug 16 17:58:01 2013
@@ -79,9 +79,7 @@ public class FileEditor implements Prope
         boolean notExpression = GenericTestBeanCustomizer.notExpression(descriptor);
         boolean notOther = GenericTestBeanCustomizer.notOther(descriptor);
         Object defaultValue = descriptor.getValue(GenericTestBeanCustomizer.DEFAULT);
-        ComboStringEditor cse = new ComboStringEditor();
-        cse.setNoUndefined(notNull);
-        cse.setNoEdit(notExpression && notOther);
+        ComboStringEditor cse = new ComboStringEditor(null, notExpression && notOther, notNull);
         editor = new WrapperEditor(this, new SimpleFileEditor(), cse,
                 !notNull, // acceptsNull
                 !notExpression, // acceptsExpressions

Modified: jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/GenericTestBeanCustomizer.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/GenericTestBeanCustomizer.java?rev=1514823&r1=1514822&r2=1514823&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/GenericTestBeanCustomizer.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/GenericTestBeanCustomizer.java Fri Aug 16 17:58:01 2013
@@ -384,12 +384,7 @@ public class GenericTestBeanCustomizer e
         if (notNull && tags == null) {
             guiEditor = new FieldStringEditor();
         } else {
-            ComboStringEditor e = new ComboStringEditor();
-            e.setNoUndefined(notNull);
-            e.setNoEdit(notExpression && notOther);
-            e.setTags(tags);
-
-            guiEditor = e;
+            guiEditor = new ComboStringEditor(tags, notExpression && notOther, notNull);
         }
 
         WrapperEditor wrapper = new WrapperEditor(typeEditor, guiEditor,

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1514823&r1=1514822&r2=1514823&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Fri Aug 16 17:58:01 2013
@@ -405,6 +405,7 @@ Previously the default was 1, which coul
 <li>Moved commons-lang (2.6) to lib/doc as it's only needed by Velocity.</li>
 <li>Re-organised and simplified NOTICE and LICENSE files.</li>
 <li><bugzilla>55411</bugzilla> -  NativeCommand could be useful elsewhere. Copied code to o.a.jorphan.exec.</li>
+<li><bugzilla>55435</bugzilla> - ComboStringEditor could be simplified to make most settings final</li>
 </ul>
 
 <h2>Thanks</h2>