You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by ms...@apache.org on 2003/05/16 18:58:17 UTC

cvs commit: jakarta-jmeter/src/core/org/apache/jmeter/threads JMeterContext.java JMeterThread.java

mstover1    2003/05/16 09:58:17

  Modified:    src/components/org/apache/jmeter/assertions/gui
                        AssertionGui.java
               src/core/org/apache/jmeter/config/gui ArgumentsPanel.java
               src/core/org/apache/jmeter/engine/util ValueReplacer.java
               src/core/org/apache/jmeter/gui/util
                        TextAreaTableCellEditor.java
               src/core/org/apache/jmeter/testelement/property
                        FunctionProperty.java
               src/core/org/apache/jmeter/threads JMeterContext.java
                        JMeterThread.java
  Log:
  Fixing some table editing issues
  providing notification for when sampling is occurring in the JMeterContext
  
  Revision  Changes    Path
  1.12      +13 -40    jakarta-jmeter/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java
  
  Index: AssertionGui.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- AssertionGui.java	29 Apr 2003 13:40:37 -0000	1.11
  +++ AssertionGui.java	16 May 2003 16:58:16 -0000	1.12
  @@ -59,8 +59,6 @@
   import java.awt.Dimension;
   import java.awt.event.ActionEvent;
   import java.awt.event.ActionListener;
  -import java.awt.event.FocusEvent;
  -import java.awt.event.FocusListener;
   
   import javax.swing.BorderFactory;
   import javax.swing.Box;
  @@ -92,7 +90,7 @@
    *@version   $Revision$
    ***************************************/
   
  -public class AssertionGui extends AbstractAssertionGui implements FocusListener
  +public class AssertionGui extends AbstractAssertionGui
   {
       static final String COL_NAME = JMeterUtils.getResString("assertion_patterns_to_test");
   
  @@ -227,8 +225,8 @@
           box.add(makeTitlePanel());
           box.add(createFieldPanel());
           box.add(createTypePanel());
  -        box.add(createStringPanel());
           add(box,BorderLayout.NORTH);
  +        add(createStringPanel(),BorderLayout.CENTER);
       }
   
       private JPanel createFieldPanel()
  @@ -263,35 +261,10 @@
           return panel;
       }
   
  -    /****************************************
  -     * Description of the Method
  -     *
  -     *@param e  Description of Parameter
  -     ***************************************/
  -    public void focusLost(FocusEvent e)
  -    {
  -        try
  -        {
  -            stringTable.getCellEditor().stopCellEditing();
  -        }
  -        catch (NullPointerException err)
  -        {}
  -    }
  -
  -    /****************************************
  -     * Description of the Method
  -     *
  -     *@param e  Description of Parameter
  -     ***************************************/
  -    public void focusGained(FocusEvent e)
  -    {}
  -
       private JPanel createStringPanel()
       {
           tableModel = new PowerTableModel(new String[] { COL_NAME }, new Class[] { String.class });
           stringTable = new JTable(tableModel);
  -
  -        stringTable.addFocusListener(this);
           TextAreaCellRenderer renderer = new TextAreaCellRenderer();
           stringTable.setRowHeight(renderer.getPreferredHeight());
           stringTable.setDefaultRenderer(String.class, renderer);
  
  
  
  1.14      +4 -35     jakarta-jmeter/src/core/org/apache/jmeter/config/gui/ArgumentsPanel.java
  
  Index: ArgumentsPanel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/config/gui/ArgumentsPanel.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ArgumentsPanel.java	11 May 2003 13:02:30 -0000	1.13
  +++ ArgumentsPanel.java	16 May 2003 16:58:16 -0000	1.14
  @@ -59,8 +59,6 @@
   import java.awt.FlowLayout;
   import java.awt.event.ActionEvent;
   import java.awt.event.ActionListener;
  -import java.awt.event.FocusEvent;
  -import java.awt.event.FocusListener;
   import java.util.Collection;
   import java.util.Iterator;
   
  @@ -71,8 +69,6 @@
   import javax.swing.JPanel;
   import javax.swing.JTable;
   import javax.swing.ListSelectionModel;
  -import javax.swing.event.CellEditorListener;
  -import javax.swing.event.ChangeEvent;
   import javax.swing.table.TableCellEditor;
   
   import junit.framework.TestCase;
  @@ -96,7 +92,7 @@
    */
   public class ArgumentsPanel
       extends AbstractConfigGui
  -    implements FocusListener, ActionListener, CellEditorListener
  +    implements  ActionListener
   {
       /** Logging. */
       private static transient Logger log =
  @@ -174,6 +170,7 @@
       /* Implements JMeterGUIComponent.modifyTestElement(TestElement) */
       public void modifyTestElement(TestElement args)
       {
  +        stopTableEditing();
           Iterator modelData = tableModel.iterator();
           Arguments arguments = null;
           if (args instanceof Arguments)
  @@ -410,7 +407,7 @@
       {
           initializeTableModel();
           table = new JTable(tableModel);
  -        table.addFocusListener(this);
  +        //table.addFocusListener(this);
           // use default editor/renderer to fix bug #16058
           //    TextAreaTableCellEditor editor = new TextAreaTableCellEditor();
           //    table.setDefaultEditor(String.class, editor);
  @@ -474,34 +471,6 @@
   
           table.revalidate();
           sizeColumns(table);
  -    }
  -
  -
  -    // CellEditorListener implementation
  -    
  -    /* Implements CellEditorListener.editingCanceled(ChangeEvent) */
  -    public void editingCanceled(ChangeEvent e)
  -    {
  -    }
  -
  -    /* Implements CellEditorListener.editingStopped(ChangeEvent) */
  -    public void editingStopped(ChangeEvent e)
  -    {
  -    }
  -
  -
  -    // FocusListener implementation
  -
  -    /* Implements FocusListener.focusLost(FocusEvent) */
  -    public void focusLost(FocusEvent e)
  -    {
  -        log.debug("Focus lost on table");
  -        stopTableEditing();
  -    }
  -
  -    /* Implements FocusListener.focusGained(FocusEvent) */
  -    public void focusGained(FocusEvent e)
  -    {
       }
   
   
  
  
  
  1.7       +11 -0     jakarta-jmeter/src/core/org/apache/jmeter/engine/util/ValueReplacer.java
  
  Index: ValueReplacer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/engine/util/ValueReplacer.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ValueReplacer.java	5 May 2003 17:23:01 -0000	1.6
  +++ ValueReplacer.java	16 May 2003 16:58:16 -0000	1.7
  @@ -135,7 +135,10 @@
               JMeterVariables vars = new JMeterVariables();
               vars.put("server", "jakarta.apache.org");
               JMeterContextService.getContext().setVariables(vars);
  +            JMeterContextService.getContext().setSamplingStarted(true);
           }
  +        
  +        
   
           public void testReverseReplacement() throws Exception
           {
  @@ -165,5 +168,13 @@
               element.setRunningVersion(true);
               assertEquals("jakarta.apache.org", element.getPropertyAsString("domain"));
           }
  +        /* (non-Javadoc)
  +         * @see junit.framework.TestCase#tearDown()
  +         */
  +        protected void tearDown() throws Exception
  +        {
  +            JMeterContextService.getContext().setSamplingStarted(false);
  +        }
  +
       }
   }
  
  
  
  1.4       +267 -96   jakarta-jmeter/src/core/org/apache/jmeter/gui/util/TextAreaTableCellEditor.java
  
  Index: TextAreaTableCellEditor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/util/TextAreaTableCellEditor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TextAreaTableCellEditor.java	16 Apr 2003 20:38:59 -0000	1.3
  +++ TextAreaTableCellEditor.java	16 May 2003 16:58:17 -0000	1.4
  @@ -1,20 +1,21 @@
   package org.apache.jmeter.gui.util;
   
   import java.awt.Component;
  +import java.awt.event.ActionEvent;
   import java.awt.event.FocusEvent;
   import java.awt.event.FocusListener;
  +import java.awt.event.ItemEvent;
   import java.awt.event.MouseEvent;
  +import java.io.Serializable;
   import java.util.EventObject;
  -import java.util.Iterator;
  -import java.util.LinkedList;
  -import java.util.List;
   
  +import javax.swing.AbstractCellEditor;
   import javax.swing.JScrollPane;
   import javax.swing.JTable;
   import javax.swing.JTextArea;
  -import javax.swing.event.CellEditorListener;
  -import javax.swing.event.ChangeEvent;
  +import javax.swing.JTree;
   import javax.swing.table.TableCellEditor;
  +import javax.swing.tree.TreeCellEditor;
   
   /**
    * @author mstover
  @@ -22,118 +23,288 @@
    * To change this generated comment edit the template variable "typecomment":
    * Window>Preferences>Java>Templates.
    */
  -public class TextAreaTableCellEditor implements TableCellEditor,FocusListener {
  -	JScrollPane pane;
  -	JTextArea editor;
  -	String value = "";
  -	LinkedList listeners = new LinkedList();
  -	int row,col;
  -	
  -	public Component getTableCellEditorComponent(JTable table,
  -                                             Object value,
  -                                             boolean isSelected,
  -                                             int row,
  -                                             int column)
  -    {
  -    	editor = new JTextArea(value.toString());
  -    	editor.addFocusListener(this);
  -    	editor.setEnabled(true);
  -    	editor.setRows(editor.getRows());
  -    	editor.revalidate();
  -    	pane = new JScrollPane(editor,JScrollPane.VERTICAL_SCROLLBAR_NEVER,
  -    			JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
  -    	pane.validate();
  -    	this.row = row;
  -    	this.col = column;
  -    	return pane;
  -    }
  -    
  -    public int getColumn()
  -    {
  -    	return col;
  -    }
  -    
  -    public int getRow()
  -    {
  -    	return row;
  -    }
  -    
  -    public void focusLost(FocusEvent fe)
  +public class TextAreaTableCellEditor extends AbstractCellEditor implements TableCellEditor, TreeCellEditor
  +{
  +
  +    //
  +    //Instance Variables
  +    //
  +
  +    /** The Swing component being edited. */
  +    protected JTextArea editorComponent;
  +    /**
  +     * The delegate class which handles all methods sent from the
  +     * <code>CellEditor</code>.
  +     */
  +    protected EditorDelegate delegate;
  +    /**
  +     * An integer specifying the number of clicks needed to start editing.
  +     * Even if <code>clickCountToStart</code> is defined as zero, it
  +     * will not initiate until a click occurs.
  +     */
  +    protected int clickCountToStart = 1;
  +
  +    //
  +    //Constructors
  +    //
  +
  +    /**
  +     * Constructs a <code>DefaultCellEditor</code> that uses a text field.
  +     *
  +     * @param x  a <code>JTextField</code> object
  +     */
  +    public TextAreaTableCellEditor()
       {
  -    	stopCellEditing();
  +        editorComponent = new JTextArea();
  +        editorComponent.setRows(3);
  +        this.clickCountToStart = 2;
  +        delegate = new EditorDelegate()
  +        {
  +            public void setValue(Object value)
  +            {
  +                editorComponent.setText((value != null) ? value.toString() : "");
  +            }
  +
  +            public Object getCellEditorValue()
  +            {
  +                return editorComponent.getText();
  +            }
  +        };
  +        editorComponent.addFocusListener(delegate);
       }
  -    
  -    public void focusGained(FocusEvent fe)
  +
  +    /**
  +     * Returns a reference to the editor component.
  +     *
  +     * @return the editor <code>Component</code>
  +     */
  +    public Component getComponent()
       {
  +        return editorComponent;
       }
  -    
  -    public TextAreaTableCellEditor()
  +
  +    //
  +    //Modifying
  +    //
  +
  +    /**
  +     * Specifies the number of clicks needed to start editing.
  +     *
  +     * @param count  an int specifying the number of clicks needed to start editing
  +     * @see #getClickCountToStart
  +     */
  +    public void setClickCountToStart(int count)
       {
  -    	editor = new JTextArea();
  -    	editor.setRows(3);
  +        clickCountToStart = count;
       }
  -    
  -    public Component getComponent()
  +
  +    /**
  +     * Returns the number of clicks needed to start editing.
  +     * @returns the number of clicks needed to start editing
  +     */
  +    public int getClickCountToStart()
       {
  -    	return editor;
  +        return clickCountToStart;
       }
  -    
  +
  +    //
  +    //Override the implementations of the superclass, forwarding all methods 
  +    //from the CellEditor interface to our delegate. 
  +    //
  +
  +    /**
  +     * Forwards the message from the <code>CellEditor</code> to
  +     * the <code>delegate</code>.
  +     * @see EditorDelegate#getCellEditorValue
  +     */
       public Object getCellEditorValue()
       {
  -    	return editor.getText();
  +        return delegate.getCellEditorValue();
       }
  -    
  -    public void cancelCellEditing()
  +
  +    /**
  +     * Forwards the message from the <code>CellEditor</code> to
  +     * the <code>delegate</code>.
  +     * @see EditorDelegate#isCellEditable(EventObject)
  +     */
  +    public boolean isCellEditable(EventObject anEvent)
       {
  -    	Iterator iter = ((List)listeners.clone()).iterator();
  -    	while(iter.hasNext())
  -    	{
  -    		((CellEditorListener)iter.next()).editingCanceled(new ChangeEvent(this));
  -    	}
  +        return delegate.isCellEditable(anEvent);
       }
  -    
  -    public boolean stopCellEditing()
  +
  +    /**
  +     * Forwards the message from the <code>CellEditor</code> to
  +     * the <code>delegate</code>.
  +     * @see EditorDelegate#shouldSelectCell(EventObject)
  +     */
  +    public boolean shouldSelectCell(EventObject anEvent)
       {
  -    	Iterator iter = ((List)listeners.clone()).iterator();
  -    	while(iter.hasNext())
  -    	{
  -    		((CellEditorListener)iter.next()).editingStopped(new ChangeEvent(this));
  -    	}
  -    	return true;
  +        return delegate.shouldSelectCell(anEvent);
       }
  -    
  -    public void addCellEditorListener(CellEditorListener lis)
  +
  +    /**
  +     * Forwards the message from the <code>CellEditor</code> to
  +     * the <code>delegate</code>.
  +     * @see EditorDelegate#stopCellEditing
  +     */
  +    public boolean stopCellEditing()
       {
  -    	listeners.add(lis);
  +        return delegate.stopCellEditing();
       }
  -    
  -    public boolean isCellEditable(EventObject anEvent)
  +
  +    /**
  +     * Forwards the message from the <code>CellEditor</code> to
  +     * the <code>delegate</code>.
  +     * @see EditorDelegate#cancelCellEditing
  +     */
  +    public void cancelCellEditing()
       {
  -    	if (anEvent instanceof MouseEvent)
  -		{
  -			if (((MouseEvent)anEvent).getClickCount() > 0)
  -			{
  -				return true;
  -			}
  -		}
  -		else if(anEvent instanceof FocusEvent)
  -		{
  -			if(((FocusEvent)anEvent).getID() == FocusEvent.FOCUS_GAINED)
  -			{
  -				return true;
  -			}
  -		}
  -		return true;
  -    }
  -    
  -    public void removeCellEditorListener(CellEditorListener lis)
  +        delegate.cancelCellEditing();
  +    }
  +
  +    //
  +    //Implementing the TreeCellEditor Interface
  +    //
  +
  +    /** Implements the <code>TreeCellEditor</code> interface. */
  +    public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)
       {
  -    	listeners.remove(lis);
  +        String stringValue = tree.convertValueToText(value, isSelected, expanded, leaf, row, false);
  +
  +        delegate.setValue(stringValue);
  +        return new JScrollPane(editorComponent);
       }
  -    
  -    public boolean shouldSelectCell(EventObject eo)
  +
  +    //
  +    //Implementing the CellEditor Interface
  +    //
  +    /** Implements the <code>TableCellEditor</code> interface. */
  +    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
       {
  -    	return true;
  +        delegate.setValue(value);
  +        return new JScrollPane(editorComponent);
       }
   
  +    //
  +    //Protected EditorDelegate class
  +    //
  +
  +    /**
  +     * The protected <code>EditorDelegate</code> class.
  +     */
  +    protected class EditorDelegate implements FocusListener, Serializable
  +    {
  +
  +        /**  The value of this cell. */
  +        protected Object value;
  +
  +        /**
  +         * Returns the value of this cell. 
  +         * @return the value of this cell
  +         */
  +        public Object getCellEditorValue()
  +        {
  +            return value;
  +        }
  +
  +        /**
  +         * Sets the value of this cell. 
  +         * @param value the new value of this cell
  +         */
  +        public void setValue(Object value)
  +        {
  +            this.value = value;
  +        }
  +
  +        /**
  +         * Returns true if <code>anEvent</code> is <b>not</b> a
  +         * <code>MouseEvent</code>.  Otherwise, it returns true
  +         * if the necessary number of clicks have occurred, and
  +         * returns false otherwise.
  +         *
  +         * @param   anEvent         the event
  +         * @return  true  if cell is ready for editing, false otherwise
  +         * @see #setClickCountToStart
  +         * @see #shouldSelectCell
  +         */
  +        public boolean isCellEditable(EventObject anEvent)
  +        {
  +            if (anEvent instanceof MouseEvent)
  +            {
  +                return ((MouseEvent) anEvent).getClickCount() >= clickCountToStart;
  +            }
  +            return true;
  +        }
  +
  +        /**
  +         * Returns true to indicate that the editing cell may
  +         * be selected.
  +         *
  +         * @param   anEvent         the event
  +         * @return  true 
  +         * @see #isCellEditable
  +         */
  +        public boolean shouldSelectCell(EventObject anEvent)
  +        {
  +            return true;
  +        }
  +
  +        /**
  +         * Returns true to indicate that editing has begun.
  +         *
  +         * @param anEvent          the event
  +         */
  +        public boolean startCellEditing(EventObject anEvent)
  +        {
  +            return true;
  +        }
  +
  +        /**
  +         * Stops editing and
  +         * returns true to indicate that editing has stopped.
  +         * This method calls <code>fireEditingStopped</code>.
  +         *
  +         * @return  true 
  +         */
  +        public boolean stopCellEditing()
  +        {
  +            fireEditingStopped();
  +            return true;
  +        }
  +
  +        /**
  +         * Cancels editing.  This method calls <code>fireEditingCanceled</code>.
  +         */
  +        public void cancelCellEditing()
  +        {
  +            fireEditingCanceled();
  +        }
  +
  +        /**
  +         * When an action is performed, editing is ended.
  +         * @param e the action event
  +         * @see #stopCellEditing
  +         */
  +        public void actionPerformed(ActionEvent e)
  +        {
  +            TextAreaTableCellEditor.this.stopCellEditing();
  +        }
  +
  +        /**
  +         * When an item's state changes, editing is ended.
  +         * @param e the action event
  +         * @see #stopCellEditing
  +         */
  +        public void itemStateChanged(ItemEvent e)
  +        {
  +            TextAreaTableCellEditor.this.stopCellEditing();
  +        }
  +        public void focusLost(FocusEvent ev)
  +        {
  +            TextAreaTableCellEditor.this.stopCellEditing();
  +        }
  +
  +        public void focusGained(FocusEvent ev)
  +        {}
  +    }
   }
  
  
  
  1.8       +1 -1      jakarta-jmeter/src/core/org/apache/jmeter/testelement/property/FunctionProperty.java
  
  Index: FunctionProperty.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/testelement/property/FunctionProperty.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- FunctionProperty.java	29 Apr 2003 15:47:43 -0000	1.7
  +++ FunctionProperty.java	16 May 2003 16:58:17 -0000	1.8
  @@ -59,7 +59,7 @@
        */
       public String getStringValue()
       {
  -        if (!isRunningVersion())
  +        if (!isRunningVersion() || !JMeterContextService.getContext().isSamplingStarted())
           {
               log.debug("Not running version, return raw function string");
               return function.getRawParameters();
  
  
  
  1.6       +18 -0     jakarta-jmeter/src/core/org/apache/jmeter/threads/JMeterContext.java
  
  Index: JMeterContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/threads/JMeterContext.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JMeterContext.java	10 Apr 2003 18:31:18 -0000	1.5
  +++ JMeterContext.java	16 May 2003 16:58:17 -0000	1.6
  @@ -18,12 +18,14 @@
   	SampleResult previousResult;
   	Sampler currentSampler;
       Sampler previousSampler;
  +    boolean samplingStarted;
       private int threadNum;
   	
   	JMeterContext() {
   		variables = null;
   		previousResult = null;
   		currentSampler = null;
  +        samplingStarted = false;
   	}
   	
   	
  @@ -89,6 +91,22 @@
       public void setThreadNum(int threadNum)
       {
           this.threadNum = threadNum;
  +    }
  +
  +    /**
  +     * @return
  +     */
  +    public boolean isSamplingStarted()
  +    {
  +        return samplingStarted;
  +    }
  +
  +    /**
  +     * @param b
  +     */
  +    public void setSamplingStarted(boolean b)
  +    {
  +        samplingStarted = b;
       }
   
   }
  
  
  
  1.27      +5 -3      jakarta-jmeter/src/core/org/apache/jmeter/threads/JMeterThread.java
  
  Index: JMeterThread.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/threads/JMeterThread.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- JMeterThread.java	1 May 2003 18:51:05 -0000	1.26
  +++ JMeterThread.java	16 May 2003 16:58:17 -0000	1.27
  @@ -156,7 +156,9 @@
                           threadContext.setCurrentSampler(sam);
                           SamplePackage pack = compiler.configureSampler(sam);
                           delay(pack.getTimers());
  +                        threadContext.setSamplingStarted(true);                        
                           SampleResult result = pack.getSampler().sample(null);
  +                        threadContext.setSamplingStarted(false);
                           result.setThreadName(threadName);
                           result.setTimeStamp(System.currentTimeMillis());
                           threadContext.setPreviousResult(result);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org