Home » jakarta-jmeter-2.3.4_src » org.apache.jmeter.protocol.jdbc.config.gui » [javadoc | source]

    1   // $Header: /home/cvs/jakarta-jmeter/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/gui/Attic/PoolConfigGui.java,v 1.12 2004/03/05 01:38:42 sebb Exp $
    2   /*
    3    * Copyright 2001-2004 The Apache Software Foundation.
    4    *
    5    * Licensed under the Apache License, Version 2.0 (the "License");
    6    * you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    *   http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    * 
   17   */
   18   
   19   package org.apache.jmeter.protocol.jdbc.config.gui;
   20   
   21   import java.awt.BorderLayout;
   22   import java.awt.event.FocusEvent;
   23   import java.awt.event.FocusListener;
   24   
   25   import javax.swing.BorderFactory;
   26   import javax.swing.JLabel;
   27   import javax.swing.JOptionPane;
   28   import javax.swing.JPanel;
   29   import javax.swing.JTextField;
   30   
   31   import org.apache.jmeter.config.ConfigTestElement;
   32   import org.apache.jmeter.config.gui.AbstractConfigGui;
   33   import org.apache.jmeter.gui.util.VerticalPanel;
   34   import org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler;
   35   import org.apache.jmeter.protocol.jdbc.util.JMeter19ConnectionPool;
   36   import org.apache.jmeter.testelement.TestElement;
   37   import org.apache.jmeter.util.JMeterUtils;
   38   
   39   /**
   40    * @version   $Revision: 1.12 $ on $Date: 2004/03/05 01:38:42 $
   41    */
   42   public class PoolConfigGui extends AbstractConfigGui implements FocusListener
   43   {
   44       private static String CONNECTIONS = "connections";
   45       private static String MAXUSE = "maxuse";
   46       private static String DEFAULT_MAX_USE = "50";
   47       private static String DEFAULT_NUM_CONNECTIONS = "1";
   48       private JTextField connField;
   49       private JTextField maxUseField;
   50   
   51       private boolean displayName;
   52   
   53       public PoolConfigGui()
   54       {
   55           this(true);
   56       }
   57   
   58       public PoolConfigGui(boolean displayName)
   59       {
   60           this.displayName = displayName;
   61           init();
   62       }
   63   
   64       public void configure(TestElement element)
   65       {
   66           super.configure(element);
   67           connField.setText(
   68               element.getPropertyAsString(JMeter19ConnectionPool.CONNECTIONS));
   69           maxUseField.setText(
   70               element.getPropertyAsString(JMeter19ConnectionPool.MAXUSE));
   71       }
   72   
   73       public TestElement createTestElement()
   74       {
   75           ConfigTestElement element = new ConfigTestElement();
   76           modifyTestElement(element);
   77           return element;
   78       }
   79   
   80       /**
   81        * Modifies a given TestElement to mirror the data in the gui components.
   82        * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
   83        */
   84       public void modifyTestElement(TestElement element)
   85       {
   86           configureTestElement(element);
   87           element.setProperty(
   88               JDBCSampler.CONNECTION_POOL_IMPL,
   89               JMeter19ConnectionPool.class.getName());
   90           element.setProperty(
   91               JMeter19ConnectionPool.CONNECTIONS,
   92               connField.getText());
   93           element.setProperty(
   94               JMeter19ConnectionPool.MAXUSE,
   95               maxUseField.getText());
   96       }
   97   
   98       public String getLabelResource()
   99       {
  100           return "database_conn_pool_title";
  101       }
  102   
  103       public void focusGained(FocusEvent e)
  104       {
  105       }
  106   
  107       public void focusLost(FocusEvent e)
  108       {
  109           String name = e.getComponent().getName();
  110   
  111           if (name.equals(CONNECTIONS))
  112           {
  113               try
  114               {
  115                   Integer.parseInt(connField.getText());
  116               }
  117               catch (NumberFormatException nfe)
  118               {
  119                   if (connField.getText().length() > 0)
  120                   {
  121                       JOptionPane.showMessageDialog(
  122                           this,
  123                           "You must enter a valid number",
  124                           "Invalid data",
  125                           JOptionPane.WARNING_MESSAGE);
  126                   }
  127                   connField.setText(DEFAULT_NUM_CONNECTIONS);
  128               }
  129           }
  130           else if (name.equals(MAXUSE))
  131           {
  132               try
  133               {
  134                   Integer.parseInt(maxUseField.getText());
  135               }
  136               catch (NumberFormatException nfe)
  137               {
  138                   if (maxUseField.getText().length() > 0)
  139                   {
  140                       JOptionPane.showMessageDialog(
  141                           this,
  142                           "You must enter a valid number",
  143                           "Invalid data",
  144                           JOptionPane.WARNING_MESSAGE);
  145                   }
  146                   maxUseField.setText(DEFAULT_NUM_CONNECTIONS);
  147               }
  148           }
  149       }
  150   
  151       private void init()
  152       {
  153           setLayout(new BorderLayout(0, 5));
  154   
  155           if (displayName)
  156           {
  157               setBorder(makeBorder());
  158               add(makeTitlePanel(), BorderLayout.NORTH);
  159           }
  160   
  161           VerticalPanel poolPanel = new VerticalPanel();
  162           poolPanel.setBorder(
  163               BorderFactory.createTitledBorder(
  164                   JMeterUtils.getResString("database_conn_pool_props")));
  165   
  166           poolPanel.add(createConnPanel());
  167           poolPanel.add(createMaxUsePanel());
  168   
  169           // The Center component will fill all available space.  Since poolPanel
  170           // has a titled border, this means that the border would extend to the
  171           // bottom of the frame, which is ugly.  So put the poolPanel in a
  172           // second panel to fix this.
  173           VerticalPanel mainPanel = new VerticalPanel();
  174           mainPanel.add(poolPanel);
  175   
  176           add(mainPanel, BorderLayout.CENTER);
  177       }
  178   
  179       private JPanel createConnPanel()
  180       {
  181           connField = new JTextField(DEFAULT_NUM_CONNECTIONS, 5);
  182           connField.setName(CONNECTIONS);
  183           connField.addFocusListener(this);
  184   
  185           JLabel label =
  186               new JLabel(JMeterUtils.getResString("database_conn_pool_size"));
  187           label.setLabelFor(connField);
  188   
  189           JPanel panel = new JPanel(new BorderLayout(5, 0));
  190           panel.add(label, BorderLayout.WEST);
  191           panel.add(connField, BorderLayout.CENTER);
  192           return panel;
  193       }
  194   
  195       private JPanel createMaxUsePanel()
  196       {
  197           maxUseField = new JTextField(DEFAULT_MAX_USE, 5);
  198           maxUseField.setName(MAXUSE);
  199           maxUseField.addFocusListener(this);
  200   
  201           JLabel label =
  202               new JLabel(
  203                   JMeterUtils.getResString("database_conn_pool_max_usage"));
  204           label.setLabelFor(maxUseField);
  205   
  206           JPanel panel = new JPanel(new BorderLayout(5, 0));
  207           panel.add(label, BorderLayout.WEST);
  208           panel.add(maxUseField, BorderLayout.CENTER);
  209           return panel;
  210       }
  211   }

Home » jakarta-jmeter-2.3.4_src » org.apache.jmeter.protocol.jdbc.config.gui » [javadoc | source]