jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1514461 - in /jmeter/trunk: src/core/org/apache/jmeter/testbeans/gui/EnumEditor.java src/core/org/apache/jmeter/testbeans/gui/TypeEditor.java xdocs/changes.xml
Date Thu, 15 Aug 2013 20:06:13 GMT
Author: sebb
Date: Thu Aug 15 20:06:12 2013
New Revision: 1514461

URL: http://svn.apache.org/r1514461
Log:
Need GUI Editor to process fields which are based on Enums with localised display strings
Bugzilla Id: 55241

Added:
    jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/EnumEditor.java   (with props)
Modified:
    jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/TypeEditor.java
    jmeter/trunk/xdocs/changes.xml

Added: jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/EnumEditor.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/EnumEditor.java?rev=1514461&view=auto
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/EnumEditor.java (added)
+++ jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/EnumEditor.java Thu Aug 15 20:06:12
2013
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jmeter.testbeans.gui;
+
+import java.awt.Component;
+import java.beans.PropertyDescriptor;
+import java.beans.PropertyEditorSupport;
+import java.util.ResourceBundle;
+
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JComboBox;
+
+import org.apache.jmeter.gui.ClearGui;
+
+/**
+ * This class implements a property editor for String properties based on an enum
+ * that supports custom editing (i.e.: provides a GUI component) based on a
+ * combo box.
+ * <p>
+ * The provided GUI is a combo box with an option for each value in the enum.
+ * <p>
+ * The resource bundle must be provided by the attribute
+ * GenericTestBeanCustomizer.RESOURCE_BUNDLE
+ */
+class EnumEditor extends PropertyEditorSupport implements ClearGui {
+
+    private final JComboBox combo;
+
+    private final DefaultComboBoxModel model;
+
+    private final Enum<?>[] eNum;
+
+    private final ResourceBundle rb;
+
+    private final int defaultIndex;
+
+    public EnumEditor(PropertyDescriptor descriptor) {
+        model = new DefaultComboBoxModel();
+        combo = new JComboBox(model);
+        combo.setEditable(false);
+        rb = (ResourceBundle) descriptor.getValue(GenericTestBeanCustomizer.RESOURCE_BUNDLE);
+        eNum = (Enum<?>[]) descriptor.getValue(GenericTestBeanCustomizer.TAGS);
+        for(Enum<?> e : eNum) {
+            model.addElement(rb.getObject(e.toString()));
+        }
+        Enum<?> def = (Enum<?>) descriptor.getValue(GenericTestBeanCustomizer.DEFAULT);
+        if (def != null) {
+            this.defaultIndex = def.ordinal();
+        } else {
+            this.defaultIndex = 0;
+        }
+        combo.setSelectedIndex(defaultIndex);
+    }
+
+    @Override
+    public boolean supportsCustomEditor() {
+        return true;
+    }
+
+    @Override
+    public Component getCustomEditor() {
+        return combo;
+    }
+
+    @Override
+    public Object getValue() {
+        return Integer.valueOf(combo.getSelectedIndex());
+    }
+
+    @Override
+    public String getAsText() {
+        Object value = combo.getSelectedItem();
+        return (String) value;
+    }
+
+    @Override
+    public void setValue(Object value) {
+        if (value instanceof Enum<?>){
+            combo.setSelectedIndex(((Enum<?>) value).ordinal());
+        } else if (value instanceof Integer) {
+            combo.setSelectedIndex(((Integer) value).intValue());
+        } else {
+            combo.setSelectedItem(value);
+        }
+    }
+
+    @Override
+    public void setAsText(String value) {
+        combo.setSelectedItem(value);
+    }
+
+    @Override
+    public void clearGui() {
+        combo.setSelectedIndex(defaultIndex);
+    }
+
+}
\ No newline at end of file

Propchange: jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/EnumEditor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/EnumEditor.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/TypeEditor.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/TypeEditor.java?rev=1514461&r1=1514460&r2=1514461&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/TypeEditor.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/TypeEditor.java Thu Aug 15 20:06:12
2013
@@ -29,6 +29,7 @@ public enum TypeEditor {
     PasswordEditor {@Override PropertyEditor getInstance(PropertyDescriptor descriptor) {
return new PasswordEditor(); }},
     TableEditor    {@Override PropertyEditor getInstance(PropertyDescriptor descriptor) {
return new TableEditor(); }},
     TextAreaEditor {@Override PropertyEditor getInstance(PropertyDescriptor descriptor) {
return new TextAreaEditor(descriptor); }},
+    EnumEditor     {@Override PropertyEditor getInstance(PropertyDescriptor descriptor) {
return new EnumEditor(descriptor); }},
     ;
     // Some editors may need the descriptor
     abstract PropertyEditor getInstance(PropertyDescriptor descriptor);

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1514461&r1=1514460&r2=1514461&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Thu Aug 15 20:06:12 2013
@@ -343,6 +343,7 @@ Previously the default was 1, which coul
 
 <h3>I18N</h3>
 <ul>
+<li><bugzilla>55241</bugzilla> - Need GUI Editor to process fields which
are based on Enums with localised display strings</li>
 </ul>
 
 <h3>General</h3>



Mime
View raw message