jsalvata    2004/01/08 14:22:14

  Modified:    src/core/org/apache/jmeter/testbeans/gui Tag:
                        testbeans_experimental_branch FileEditor.java
                        TestBeanGUI.java WrapperEditor.java
               src/core/org/apache/jmeter/testbeans Tag:
                        testbeans_experimental_branch TestBean.java
  Log:
  * Undid an erroneous change in TestBeanGui.configure, which I did just out of 
analogy with TestBean.prepare.
  * Moved wrapInProperty to where it can be private.
  * Internationalized bean name in menu.
  * The ultimate beanification challenge: removed the addTestElement from the 
HTTPSamplerBean and added generic code in the TestBean that should be able to perform 
the same function (hopefully).
  * Also made an attempt to put multiple properties per line, but failed, so it's not 
committed.
  * Added the possibility to provide a non-null initial value for the property editors.
  * Added the possibility to supress the Edit and/or Undefined options in the property 
editor combo. This had lots of consequences...
  * Had to move the control of correctness for keyed-in values to the itemStateChange 
event processing. Not easy, you'll see...
  Obvious TODO: support the case with no tags, noEdit and noUndefined.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.3   +3 -2      
jakarta-jmeter/src/core/org/apache/jmeter/testbeans/gui/Attic/FileEditor.java
  
  Index: FileEditor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/testbeans/gui/Attic/FileEditor.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- FileEditor.java   7 Jan 2004 19:54:55 -0000       1.1.2.2
  +++ FileEditor.java   8 Jan 2004 22:22:14 -0000       1.1.2.3
  @@ -96,7 +96,8 @@
   
       public FileEditor()
       {
  -     super(new SimpleFileEditor(), File.class, null);
  +     super(new SimpleFileEditor(), File.class,
  +             null, false, false, new File(""));
        
                // Create a button to trigger the file chooser:
                JButton button= new JButton("Browse...");
  
  
  
  1.1.2.9   +131 -20   
jakarta-jmeter/src/core/org/apache/jmeter/testbeans/gui/Attic/TestBeanGUI.java
  
  Index: TestBeanGUI.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/testbeans/gui/Attic/TestBeanGUI.java,v
  retrieving revision 1.1.2.8
  retrieving revision 1.1.2.9
  diff -u -r1.1.2.8 -r1.1.2.9
  --- TestBeanGUI.java  7 Jan 2004 18:20:19 -0000       1.1.2.8
  +++ TestBeanGUI.java  8 Jan 2004 22:22:14 -0000       1.1.2.9
  @@ -94,8 +94,15 @@
   import org.apache.jmeter.samplers.Sampler;
   import org.apache.jmeter.testbeans.TestBean;
   import org.apache.jmeter.testelement.TestElement;
  +import org.apache.jmeter.testelement.property.BooleanProperty;
  +import org.apache.jmeter.testelement.property.DoubleProperty;
  +import org.apache.jmeter.testelement.property.FloatProperty;
  +import org.apache.jmeter.testelement.property.IntegerProperty;
   import org.apache.jmeter.testelement.property.JMeterProperty;
  -import org.apache.jmeter.testelement.property.PropertyIterator;
  +import org.apache.jmeter.testelement.property.LongProperty;
  +import org.apache.jmeter.testelement.property.NullProperty;
  +import org.apache.jmeter.testelement.property.StringProperty;
  +import org.apache.jmeter.testelement.property.TestElementProperty;
   import org.apache.jmeter.timers.Timer;
   import org.apache.jmeter.util.JMeterUtils;
   import org.apache.jmeter.visualizers.Visualizer;
  @@ -122,6 +129,16 @@
    * <dt>tags: String[]</dt>
    * <dd>List of values to be offered for the property in addition to those
    * offered by its property editor.</dd>
  + * <dt>noUndefined: Boolean</dt>
  + * <dd>If true, the property should not be left undefined. A <b>default</b>
  + * attribute must be provided if this is set.</dd>
  + * <dd>noEdit: Boolean</dd>
  + * <dd>If true, the property content should not be edited manually, that is: it
  + * should always be one of the tags values.</dt>
  + * <dt>default: Object</dt>
  + * <dd>Initial value for the property's GUI. Must be provided and be non-null
  + * if <b>noUndefined</b> is set. Must be one of the provided tags (or null) if
  + * <b>noEdit</b> is set.
    * </dl>
    * <p>
    * The following BeanDescriptor attributes are also understood:
  @@ -288,8 +305,10 @@
                                        new WrapperEditor(propertyEditor, 
descriptors[i]);
               }
               
  -            propertyEditor.setValue(null);
  -            editors[i]= propertyEditor;
  +                     editors[i]= propertyEditor;
  +
  +                     // Initialize the editor with the provided default value or 
null:
  +            setEditorValue(i, descriptors[i].getValue("default"));
           }
   
                // Obtain message formats:
  @@ -302,6 +321,31 @@
           init();
       }
   
  +     /**
  +      * Set the value of the i-th property, properly reporting a possible failure.
  +      * 
  +      * @param i the index of the property in the descriptors and editors arrays
  +      * @param value the value to be stored in the editor
  +      * 
  +      * @throws IllegalArgumentException if the editor refuses the value
  +      */
  +     private void setEditorValue(int i, Object value)
  +             throws IllegalArgumentException
  +     {
  +             try
  +             {
  +                     editors[i].setValue(value);
  +             }
  +             catch (IllegalArgumentException e)
  +             {
  +                     log.error("Could not set value "
  +                             + ( value == null ? "NULL" : 
value.getClass().getName() )
  +                             + ":" + value
  +                             +" for property "+descriptors[i].getName());
  +                     throw e;
  +             }
  +     }
  +
       public String getStaticLabel() {
           if (beanInfo == null) return "null";
           return beanInfo.getBeanDescriptor().getDisplayName();
  @@ -313,20 +357,29 @@
       public void configure(TestElement element)
       {
           super.configure(element);
  -        
  -        for (PropertyIterator jprops= element.propertyIterator();
  -                     jprops.hasNext(); )
  -        {
  -             JMeterProperty jprop= jprops.next();
  -
  -                     String name= jprop.getName(); 
  -             int i= descriptorIndex(jprop.getName());
  -             
  -             if (i == -1) continue; // ignore auxiliary properties like gui_class 
  -            if (editors[i] == null) continue; // ignore non-editable properties
   
  -            editors[i].setValue(jprop.getObjectValue());
  -        }
  +             for (int i=0; i<editors.length; i++)
  +             {
  +                     if (editors[i] == null) continue;
  +                     JMeterProperty jprop= 
element.getProperty(descriptors[i].getName());
  +                     try
  +                     {
  +                             setEditorValue(i, jprop.getObjectValue());
  +                     }
  +                     catch (IllegalArgumentException e)
  +                     {
  +                             // I guess this can happen as a result of a bad
  +                             // file read? In this case, it would be better to 
replace the
  +                             // incorrect value with anything valid, e.g. the 
default value
  +                             // for the property.
  +                             // But for the time being, I just prefer to be aware 
of any
  +                             // problems occuring here, most likely programming 
errors,
  +                             // so I'll bail out.
  +                             throw new Error("Bad property value.", e);
  +                             // TODO: review this and possibly change to:
  +                             // setEditorValue(i, 
descriptors[i].getValue("default"); 
  +                     }
  +             }
       }
   
        /**
  @@ -384,13 +437,71 @@
                                element.removeProperty(descriptors[i].getName());
                        }
                        else {
  -                             JMeterProperty jprop= TestBean.wrapInProperty(value);
  +                             JMeterProperty jprop= wrapInProperty(value);
                                jprop.setName(descriptors[i].getName());
                                element.setProperty(jprop);
                        }
           }
       }
   
  +     /**
  +      * Utility method to wrap an object in a property of an appropriate type.
  +      * <p>
  +      * I plan to get rid of this sooner than later, so please don't use it much.
  +      * 
  +      * @param value Object to be wrapped.
  +      * @return an unnamed property holding the provided value.
  +      * @deprecated
  +      */
  +     private static JMeterProperty wrapInProperty(Object value)
  +     {
  +             // TODO: Awful, again...
  +        
  +             if (value instanceof JMeterProperty)
  +             {
  +                     return (JMeterProperty)value;
  +             }
  +        
  +             JMeterProperty property;
  +             if (value == null)
  +             {
  +                     property= new NullProperty();
  +             }
  +             else if (value instanceof Boolean)
  +             {
  +                     property= new BooleanProperty();
  +             }
  +             else if (value instanceof Double)
  +             {
  +                     property= new DoubleProperty();
  +             }
  +             else if (value instanceof Float)
  +             {
  +                     property= new FloatProperty();
  +             }
  +             else if (value instanceof Integer)
  +             {
  +                     property= new IntegerProperty();
  +             }
  +             else if (value instanceof Long)
  +             {
  +                     property= new LongProperty();
  +             }
  +             else if (value instanceof String)
  +             {
  +                     property= new StringProperty();
  +             }
  +             else if (value instanceof TestElement)
  +             {
  +                     property= new TestElementProperty();
  +             }
  +             else throw new Error("Ouch!");
  +
  +             property.setObjectValue(value);
  +
  +             return property;
  +     }
  +
       /* (non-Javadoc)
        * @see org.apache.jmeter.gui.JMeterGUIComponent#createPopupMenu()
        */
  @@ -449,12 +560,12 @@
        */
       private void init()
       {
  +             // TODO: add support for Bean Customizers
  +
           setLayout(new BorderLayout(0, 5));
   
           setBorder(makeBorder());
           add(makeTitlePanel(), BorderLayout.NORTH);
  -        // TODO: add support for beanInfo.getBeanDescriptor().getCustomizerClass()
  -        // via a tabbed pannel -- e.g. "Properties" vs. "Custom"
   
           JPanel mainPanel = new JPanel(new GridBagLayout());
           
  
  
  
  1.1.2.10  +152 -10   
jakarta-jmeter/src/core/org/apache/jmeter/testbeans/gui/Attic/WrapperEditor.java
  
  Index: WrapperEditor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/testbeans/gui/Attic/WrapperEditor.java,v
  retrieving revision 1.1.2.9
  retrieving revision 1.1.2.10
  diff -u -r1.1.2.9 -r1.1.2.10
  --- WrapperEditor.java        7 Jan 2004 19:54:55 -0000       1.1.2.9
  +++ WrapperEditor.java        8 Jan 2004 22:22:14 -0000       1.1.2.10
  @@ -71,6 +71,7 @@
   import java.util.Vector;
   
   import javax.swing.JComboBox;
  +import javax.swing.text.JTextComponent;
   
   import org.apache.jorphan.logging.LoggingManager;
   import org.apache.log.Logger;
  @@ -119,12 +120,28 @@
         */
        private String[] additionalTags;
   
  +     /**
  +      * True iif the editor should not accept (nor produce) a null value.
  +      */
  +     private boolean noUndefined;
  +     
  +     /**
  +      * True iif the editor should not accept (nor produce) any non-null
  +      * values different from the provided tags.
  +      */
  +     private boolean noEdit;
  +
       /**
        * The editor's combo box. 
        */
       private JComboBox combo= null;
   
        /**
  +      * The edited property's default value.
  +      */
  +     private Object defaultValue;
  +
  +     /**
         * Create an editor wrapping one which does not provide a custom editor.
         * 
         * @param editor A property editor which doesn't have a custom editor.
  @@ -135,7 +152,10 @@
                this(
                        editor,
                        objectType(descriptor.getPropertyType()),
  -                     (String[])descriptor.getValue("tags"));
  +                     (String[])descriptor.getValue("tags"),
  +                     Boolean.TRUE.equals(descriptor.getValue("noUndefined")),
  +                     Boolean.TRUE.equals(descriptor.getValue("noEdit")),
  +                     descriptor.getValue("default"));
       }
       
       private static Class objectType(Class type)
  @@ -165,17 +185,21 @@
        * @param strings
        */
       protected WrapperEditor(
  -     PropertyEditor editor, Class type, String[] additionalTags)
  +     PropertyEditor editor, Class type, String[] additionalTags,
  +     boolean noUndefined, boolean noEdit, Object defaultValue)
       {
                this.editor= editor;
                this.type= type;
                this.additionalTags= additionalTags;
  +             this.noUndefined= noUndefined;
  +             this.noEdit= noEdit;
  +             this.defaultValue= defaultValue;
   
                // Build the list of available values for this property:
                Vector options= new Vector();
   
                // The first available value is "undefined" (null).
  -             options.add(UNDEFINED);
  +             if (! noUndefined) options.add(UNDEFINED);
   
                // Add the list of property-specific values:
                String[] tags= getTags();
  @@ -185,7 +209,7 @@
                }
               
                // The last option is to edit a value manually:
  -             options.add(EDIT);
  +             if (! noEdit) options.add(EDIT);
                
                // Create the combo box we will use to edit this property:
                combo= new JComboBox(options);
  @@ -249,6 +273,7 @@
                                        // TODO: how to warn the user?
                                        // Maybe we should do this check earlier in 
the edit
                                        // process, maybe upon ItemChangeEvents?
  +                                     // URGENT: this can return null on noUndefined 
editors!!!!
                                        value= null;
                                }
                        }
  @@ -282,6 +307,7 @@
                combo.setEditable(true);
                if (value == null)
                {
  +                     if (noUndefined) throw new IllegalArgumentException();
                        value= UNDEFINED;
                }
                else if (type.isInstance(value))
  @@ -291,6 +317,7 @@
                }
                else
                {
  +                     if (noEdit) throw new IllegalArgumentException();
                        // Not a type specific to the property, so it is a String...
                        // ... but, just in case, I'll check:
                        if (! (value instanceof String))
  @@ -347,13 +374,17 @@
                combo.setEditable(true);
                if (text == null)
                {
  +                     if (noUndefined) throw new IllegalArgumentException();
                        combo.setSelectedItem(UNDEFINED);
                }
                else 
                {
                        combo.setSelectedItem(text);
                }
  +
                if (combo.getSelectedIndex() >= 0) combo.setEditable(false);
  +             else if (noEdit) throw new IllegalArgumentException();
  +             
                firePropertyChange();
        }
   
  @@ -381,20 +412,130 @@
           return true;
       }
       
  +    /**
  +     * Keep track of the item that was just unselected... we will need it:
  +     */
  +     private Object lastValidValue= null;
  +
  +     /**
  +      * True iif we're currently processing an itemStateChanged event.
  +      */
  +     private boolean processingItemEvent= false;
  +
        /* (non-Javadoc)
         * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
         */
        public void itemStateChanged(ItemEvent e)
        {
  -             if (e.getStateChange() == ItemEvent.SELECTED)
  +             if (log.isDebugEnabled())
  +             {
  +                     log.debug("itemStatChanged:"
  +                             +" processingItemEvent= "+processingItemEvent
  +                             +" event= "+e);
  +             }
  +
  +             // Avoid reentrancy, or things become really messy.
  +             if (processingItemEvent) return;
  +             processingItemEvent= true;
  +     
  +             if (e.getStateChange() == ItemEvent.DESELECTED)
  +             {
  +                     lastValidValue= e.getItem();
  +             }
  +             else if (e.getStateChange() == ItemEvent.SELECTED)
                {
                        if (e.getItem() == EDIT) {
                                combo.setEditable(true);
  -                             combo.setSelectedItem("");
                                combo.getEditor().getEditorComponent().requestFocus();
  +
  +                             // Obtain the editor so that we can properly 
initialize it for
  +                             // the editing (convenient selection & caret position):
  +                             JTextComponent textEditor= null;
  +                             Component c= combo.getEditor().getEditorComponent();
  +                             if (c instanceof JTextComponent) textEditor= 
(JTextComponent)c;
  +
  +                             // We need a *valid* value to start the editing....
  +
  +                             if (defaultValue != null)
  +                             {
  +                                     // The default value looks like the best 
choice to me.
  +                                     // At least it's something the property author 
can control:
  +                                     combo.setSelectedItem(defaultValue);
  +                                     if (textEditor != null) textEditor.selectAll();
  +                             }
  +                             else if (isValidValue(""))
  +                             {
  +                                     // The empty string is not a bad choice, 
either:
  +                                     combo.setSelectedItem("");
  +                             }
  +                             else if (lastValidValue != UNDEFINED)
  +                             {
  +                                     // The previously selected item may be 
useful...
  +
  +                                     combo.setSelectedItem(lastValidValue);
  +                                     if (textEditor != null) textEditor.selectAll();
  +                             }
  +                             else if (getTags() != null)
  +                             {
  +                                     // Close to last resort... the first tag:
  +                                     combo.setSelectedItem(getTags()[0]);
  +                                     if (textEditor != null) textEditor.selectAll();
  +                             }
  +                             else
  +                             {
  +                                     // Last resort: 'expressions' are always valid 
on
  +                                     // editable fields:
  +                                     combo.setSelectedItem("${}");
  +                                     // Position the cursor inside the brackets, if 
possible:
  +                                     if (textEditor != null) 
textEditor.setCaretPosition(2);
  +                             }
  +                             // TODO: I don't really like this solution. We could 
make a
  +                             // more convenient approach if we knew whether the 
property
  +                             // accepts expressions or not, and whether it accepts 
any 
  +                             // values beyond the provided tags or not. 
                        } 
  -                     else if (combo.getSelectedIndex() >= 0) 
combo.setEditable(false); 
  +                     else if (combo.getSelectedIndex() >= 0) 
  +                     {
  +                             combo.setEditable(false);
  +                     }
  +                     else if (! isValidValue((String)e.getItem()))
  +                     {
  +                             // TODO: warn the user. Maybe with a pop-up? A bell?
  +                             // Revert to the previously unselected (presumed 
valid!) value:
  +                             combo.setSelectedItem(lastValidValue);
  +                             if (combo.getSelectedIndex() >= 0) 
combo.setEditable(false);
  +                     }
                }
  +                     
  +             processingItemEvent= false;
  +     }
  +     
  +     /**
  +      * Determine whether a string is a valid value for the property.
  +      * 
  +      * @param text the value to be checked
  +      * @return true iif text is a valid value
  +      */
  +     private boolean isValidValue(String text)
  +     {
  +             if (text.indexOf("${") != -1 && ! noEdit)
  +             {
  +                     // JMeter 'expressions' are valid on editable fields.
  +                     return true;
  +             }
  +
  +             // if it's not a JMeter 'expression' ...
  +             try
  +             {
  +                     editor.setAsText(text);
  +             }
  +             catch (IllegalArgumentException e1)
  +             {
  +                     // setAsText failed: not valid
  +                     return false;
  +             }
  +             // setAsText succeeded: valid
  +             return true;
        }
   
        /**
  @@ -476,9 +617,10 @@
   
                        e.setAsText("True");
                        assertEquals(new Boolean(true), e.getValue());
  -                     
  +                     // don't separate these two sub-tests
                        e.setAsText("invalid");
  -                     assertEquals(null, e.getValue());
  +                     assertEquals(new Boolean(true), e.getValue());
  +                             // reverts to las known good, that's the "true" above
                }
                public void testSetGetAsTextOnString() throws Exception
                {
  
  
  
  No                   revision
  No                   revision
  1.1.2.10  +63 -94    
jakarta-jmeter/src/core/org/apache/jmeter/testbeans/Attic/TestBean.java
  
  Index: TestBean.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/testbeans/Attic/TestBean.java,v
  retrieving revision 1.1.2.9
  retrieving revision 1.1.2.10
  diff -u -r1.1.2.9 -r1.1.2.10
  --- TestBean.java     4 Jan 2004 20:50:54 -0000       1.1.2.9
  +++ TestBean.java     8 Jan 2004 22:22:14 -0000       1.1.2.10
  @@ -62,7 +62,9 @@
   import java.beans.Introspector;
   import java.beans.PropertyDescriptor;
   import java.lang.reflect.InvocationTargetException;
  +import java.lang.reflect.Method;
   import java.util.HashMap;
  +import java.util.Iterator;
   import java.util.Map;
   
   import org.apache.jmeter.control.NextIsNullException;
  @@ -70,18 +72,11 @@
   import org.apache.jmeter.testelement.AbstractTestElement;
   import org.apache.jmeter.testelement.TestElement;
   import org.apache.jmeter.testelement.TestElementTraverser;
  -import org.apache.jmeter.testelement.property.BooleanProperty;
   import org.apache.jmeter.testelement.property.CollectionProperty;
  -import org.apache.jmeter.testelement.property.DoubleProperty;
  -import org.apache.jmeter.testelement.property.FloatProperty;
  -import org.apache.jmeter.testelement.property.IntegerProperty;
   import org.apache.jmeter.testelement.property.JMeterProperty;
  -import org.apache.jmeter.testelement.property.LongProperty;
   import org.apache.jmeter.testelement.property.MapProperty;
   import org.apache.jmeter.testelement.property.NullProperty;
   import org.apache.jmeter.testelement.property.PropertyIterator;
  -import org.apache.jmeter.testelement.property.StringProperty;
  -import org.apache.jmeter.testelement.property.TestElementProperty;
   
   /**
    * This is an experimental class. An attempt to address the complexity of
  @@ -156,34 +151,47 @@
               Object value= unwrapProperty(jprop, type);
   
               // Set the bean's property to the value we just obtained:
  -            try
  -            {
  -                if (value != null || !type.isPrimitive())
  -                    // We can't assign null to primitive types.
  -                {
  -                    param[0]= value;
  -                    descriptor.getWriteMethod().invoke(this, param);
  -                }
  -            }
  -            catch (IllegalArgumentException e)
  -            {
  -                log.error("This should never happen.", e);
  -                throw new Error(e); // Programming error: bail out.
  -            }
  -            catch (IllegalAccessException e)
  -            {
  -                log.error("This should never happen.", e);
  -                throw new Error(e); // Programming error: bail out.
  -            }
  -            catch (InvocationTargetException e)
  -            {
  -                log.error("This should never happen.", e);
  -                throw new Error(e); // Programming error: bail out.
  -            }
  +                     if (value != null || !type.isPrimitive())
  +                             // We can't assign null to primitive types.
  +                     {
  +                             param[0]= value;
  +                             invokeOrBailOut(descriptor.getWriteMethod(), param);
  +                     }
           }
       }
       
       /**
  +     * Utility method that invokes a method and does the error handling
  +     * around the invocation.
  +     * 
  +     * @param method
  +     * @param params
  +     * @return the result of the method invocation.
  +     */
  +     private Object invokeOrBailOut(Method method, Object[] params)
  +     {
  +             try
  +             {
  +                              return method.invoke(this, params);
  +             }
  +             catch (IllegalArgumentException e)
  +             {
  +                     log.error("This should never happen.", e);
  +                     throw new Error(e); // Programming error: bail out.
  +             }
  +             catch (IllegalAccessException e)
  +             {
  +                     log.error("This should never happen.", e);
  +                     throw new Error(e); // Programming error: bail out.
  +             }
  +             catch (InvocationTargetException e)
  +             {
  +                     log.error("This should never happen.", e);
  +                     throw new Error(e); // Programming error: bail out.
  +             }
  +     }
  +
  +    /**
        * Utility method to obtain the value of a property in the given type.
        * <p>
        * I plan to get rid of this sooner than later, so please don't use it much.
  @@ -241,64 +249,6 @@
           return value;
       }
   
  -    /**
  -     * Utility method to wrap an object in a property of an appropriate type.
  -     * <p>
  -     * I plan to get rid of this sooner than later, so please don't use it much.
  -     * 
  -     * @param value Object to be wrapped.
  -     * @return an unnamed property holding the provided value.
  -     * @deprecated
  -     */
  -    public static JMeterProperty wrapInProperty(Object value)
  -    {
  -        // TODO: Awful, again...
  -        
  -        if (value instanceof JMeterProperty)
  -        {
  -            return (JMeterProperty)value;
  -        }
  -        
  -        JMeterProperty property;
  -        if (value == null)
  -        {
  -            property= new NullProperty();
  -        }
  -        else if (value instanceof Boolean)
  -        {
  -            property= new BooleanProperty();
  -        }
  -        else if (value instanceof Double)
  -        {
  -            property= new DoubleProperty();
  -        }
  -        else if (value instanceof Float)
  -        {
  -            property= new FloatProperty();
  -        }
  -        else if (value instanceof Integer)
  -        {
  -            property= new IntegerProperty();
  -        }
  -        else if (value instanceof Long)
  -        {
  -            property= new LongProperty();
  -        }
  -        else if (value instanceof String)
  -        {
  -            property= new StringProperty();
  -        }
  -        else if (value instanceof TestElement)
  -        {
  -             property= new TestElementProperty();
  -        }
  -        else throw new Error("Ouch!");
  -
  -        property.setObjectValue(value);
  -        
  -        return property;
  -    }
  -
       /*
        * ---------------------------------------------------------------------
        * All AbstractTestElement methods overriden just to mark them deprecate.
  @@ -318,10 +268,29 @@
        * @see 
org.apache.jmeter.testelement.TestElement#addTestElement(org.apache.jmeter.testelement.TestElement)
        * @deprecated
        */
  -    public void addTestElement(TestElement el)
  -    {
  -        super.addTestElement(el);
  -    }
  +     public void addTestElement(TestElement el)
  +     {
  +             // Scan all properties for a writable property of the appropriate type:
  +             for (Iterator descs= descriptors.values().iterator();
  +                     descs.hasNext(); )
  +             {
  +                     PropertyDescriptor desc= (PropertyDescriptor)descs.next();
  +                     if (desc.getPropertyType().isInstance(el)
  +                             && desc.getPropertyEditorClass() == null)
  +                                                     // Note we ignore those for 
which we have an editor,
  +                                                     // in assumption that they are 
already provided via
  +                                                     // the GUI. Not very nice, but 
it's a solution.
  +                                                     // TODO: find a nicer way to 
specify which TestElement
  +                                                     // properties should be in the 
GUI and which should come
  +                                                     // from the tree structure.
  +                     {
  +                             invokeOrBailOut(desc.getWriteMethod(), new Object[] { 
el });
  +                             return; // We're done
  +                     }
  +             }
  +             // If we found no property for this one...
  +             super.addTestElement(el);
  +     }
   
       /**
        * @see org.apache.jmeter.testelement.TestElement#clear()
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to