jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1199806 - in /jmeter/trunk/src/core/org/apache/jmeter/testbeans: BeanInfoSupport.java gui/GenericTestBeanCustomizer.java gui/GuiEditor.java
Date Wed, 09 Nov 2011 15:44:33 GMT
Author: sebb
Date: Wed Nov  9 15:44:33 2011
New Revision: 1199806

URL: http://svn.apache.org/viewvc?rev=1199806&view=rev
Log:
Allow customisation of property editor (override the default)

Added:
    jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/GuiEditor.java   (with props)
Modified:
    jmeter/trunk/src/core/org/apache/jmeter/testbeans/BeanInfoSupport.java
    jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/GenericTestBeanCustomizer.java

Modified: jmeter/trunk/src/core/org/apache/jmeter/testbeans/BeanInfoSupport.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/testbeans/BeanInfoSupport.java?rev=1199806&r1=1199805&r2=1199806&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/testbeans/BeanInfoSupport.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/testbeans/BeanInfoSupport.java Wed Nov  9 15:44:33
2011
@@ -29,6 +29,7 @@ import java.util.MissingResourceExceptio
 import java.util.ResourceBundle;
 
 import org.apache.jmeter.testbeans.gui.GenericTestBeanCustomizer;
+import org.apache.jmeter.testbeans.gui.GuiEditor;
 import org.apache.jmeter.util.JMeterUtils;
 import org.apache.jorphan.logging.LoggingManager;
 import org.apache.log.Logger;
@@ -161,6 +162,21 @@ public abstract class BeanInfoSupport ex
     }
 
     /**
+     * Get the property descriptor for the property of the given name.
+     *
+     * @param name
+     *            property name
+     * @return descriptor for a property of that name, or null if there's none
+     */
+    protected PropertyDescriptor property(String name, GuiEditor editor) {
+        PropertyDescriptor property = property(name);
+        if (property != null) {
+            property.setValue(GenericTestBeanCustomizer.GUITYPE, editor);
+        }
+        return property;
+    }
+
+    /**
      * Set the bean's 16x16 colour icon.
      *
      * @param resourceName

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=1199806&r1=1199805&r2=1199806&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 Wed
Nov  9 15:44:33 2011
@@ -112,12 +112,15 @@ public class GenericTestBeanCustomizer e
 
     public static final String RESOURCE_BUNDLE = "resourceBundle"; //$NON-NLS-1$
 
+    public static final String GUITYPE = "guiType"; // $NON-NLS-$
+
     public static final String ORDER(String group) {
         return "group." + group + ".order";
     }
 
     public static final String DEFAULT_GROUP = "";
 
+    @SuppressWarnings("unused") // TODO - use or remove
     private int scrollerCount = 0;
 
     /**
@@ -214,7 +217,7 @@ public class GenericTestBeanCustomizer e
             }
 
             if (propertyEditor == null) {
-                log.debug("No editor for property " + name);
+                log.warn("No editor for property " + name);
                 editors[i] = null;
                 continue;
             }
@@ -276,23 +279,29 @@ public class GenericTestBeanCustomizer e
             }
         }
 
-        boolean notNull = Boolean.TRUE.equals(descriptor.getValue(NOT_UNDEFINED));
-        boolean notExpression = Boolean.TRUE.equals(descriptor.getValue(NOT_EXPRESSION));
-        boolean notOther = Boolean.TRUE.equals(descriptor.getValue(NOT_OTHER));
+        boolean notNull = notNull(descriptor);
+        boolean notExpression = notExpression(descriptor);
+        boolean notOther = notOther(descriptor);
 
         PropertyEditor guiEditor;
-        if (notNull && tags == null) {
-            guiEditor = new FieldStringEditor();
+        Object guiType = descriptor.getValue(GUITYPE);
+        if (guiType instanceof GuiEditor) {
+            guiEditor = ((GuiEditor) guiType).getInstance(descriptor);            
         } else {
-            ComboStringEditor e = new ComboStringEditor();
-            e.setNoUndefined(notNull);
-            e.setNoEdit(notExpression && notOther);
-            e.setTags(tags);
-
-            guiEditor = 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;
+            }
         }
 
-        WrapperEditor wrapper = new WrapperEditor(typeEditor, guiEditor, !notNull, // acceptsNull
+        WrapperEditor wrapper = new WrapperEditor(typeEditor, guiEditor,
+                !notNull, // acceptsNull
                 !notExpression, // acceptsExpressions
                 !notOther, // acceptsOther
                 descriptor.getValue(DEFAULT));
@@ -300,6 +309,21 @@ public class GenericTestBeanCustomizer e
         return wrapper;
     }
 
+    static boolean notOther(PropertyDescriptor descriptor) {
+        boolean notOther = Boolean.TRUE.equals(descriptor.getValue(NOT_OTHER));
+        return notOther;
+    }
+
+    static boolean notExpression(PropertyDescriptor descriptor) {
+        boolean notExpression = Boolean.TRUE.equals(descriptor.getValue(NOT_EXPRESSION));
+        return notExpression;
+    }
+
+    static boolean notNull(PropertyDescriptor descriptor) {
+        boolean notNull = Boolean.TRUE.equals(descriptor.getValue(NOT_UNDEFINED));
+        return notNull;
+    }
+
     /**
      * Set the value of the i-th property, properly reporting a possible
      * failure.

Added: jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/GuiEditor.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/GuiEditor.java?rev=1199806&view=auto
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/GuiEditor.java (added)
+++ jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/GuiEditor.java Wed Nov  9 15:44:33
2011
@@ -0,0 +1,37 @@
+/*
+ * 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.beans.PropertyDescriptor;
+import java.beans.PropertyEditor;
+
+/**
+ * Allow direct specification of property editors.
+ */
+public enum GuiEditor {
+    FileEditor     {@Override PropertyEditor getInstance(PropertyDescriptor descriptor) {
return new FileEditor(descriptor); }},
+    PasswordEditor {@Override PropertyEditor getInstance(PropertyDescriptor descriptor) {
return new PasswordEditor(); }},
+    /** @deprecated TableEditor does not work currently */
+    @Deprecated
+    TableEditor    {@Override PropertyEditor getInstance(PropertyDescriptor descriptor) {
return new TableEditor(); }},
+    TextAreaEditor {@Override PropertyEditor getInstance(PropertyDescriptor descriptor) {
return new TextAreaEditor(); }},
+    ;
+    // Some editors may need the descriptor
+    abstract PropertyEditor getInstance(PropertyDescriptor descriptor);
+}
\ No newline at end of file

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

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



Mime
View raw message