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/DbConfigGui.java,v 1.11 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   import java.awt.BorderLayout;
   21   
   22   import javax.swing.BorderFactory;
   23   import javax.swing.JLabel;
   24   import javax.swing.JPanel;
   25   import javax.swing.JTextField;
   26   
   27   import org.apache.jmeter.config.ConfigTestElement;
   28   import org.apache.jmeter.config.gui.AbstractConfigGui;
   29   import org.apache.jmeter.config.gui.LoginConfigGui;
   30   import org.apache.jmeter.gui.util.VerticalPanel;
   31   import org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler;
   32   import org.apache.jmeter.testelement.TestElement;
   33   import org.apache.jmeter.util.JMeterUtils;
   34   
   35   /**
   36    * @version   $Revision: 1.11 $ on $Date: 2004/03/05 01:38:42 $
   37    */
   38   public class DbConfigGui extends AbstractConfigGui
   39   {
   40       private static String URL = "url";
   41       private static String DRIVER = "driver";
   42       private JTextField urlField = new JTextField(20);
   43       private JTextField driverField = new JTextField(20);
   44   
   45       private boolean displayName;
   46       private LoginConfigGui loginGui;
   47   
   48       public DbConfigGui()
   49       {
   50           this(true);
   51       }
   52   
   53       public DbConfigGui(boolean displayName)
   54       {
   55           this.displayName = displayName;
   56           init();
   57       }
   58   
   59       public String getLabelResource()
   60       {
   61           return "database_login_title";
   62       }
   63   
   64       public TestElement createTestElement()
   65       {
   66           ConfigTestElement element = new ConfigTestElement();
   67           modifyTestElement(element);
   68           return element;
   69       }
   70   
   71       /**
   72        * Modifies a given TestElement to mirror the data in the gui components.
   73        * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
   74        */
   75       public void modifyTestElement(TestElement element)
   76       {
   77           element.clear();
   78           configureTestElement(element);
   79           element.setProperty(JDBCSampler.URL, urlField.getText());
   80           element.setProperty(JDBCSampler.DRIVER, driverField.getText());
   81           element.addTestElement(loginGui.createTestElement());
   82       }
   83   
   84       public void configure(TestElement element)
   85       {
   86           super.configure(element);
   87           urlField.setText(element.getPropertyAsString(JDBCSampler.URL));
   88           driverField.setText(element.getPropertyAsString(JDBCSampler.DRIVER));
   89           loginGui.configure(element);
   90       }
   91   
   92       private void init()
   93       {
   94           setLayout(new BorderLayout(0, 5));
   95   
   96           if (displayName)
   97           {
   98               setBorder(makeBorder());
   99   
  100               add(makeTitlePanel(), BorderLayout.NORTH);
  101           }
  102   
  103           VerticalPanel mainPanel = new VerticalPanel();
  104   
  105           // URL and JDBC PROPS
  106           VerticalPanel urlJDBCPanel = new VerticalPanel();
  107           urlJDBCPanel.setBorder(
  108               BorderFactory.createTitledBorder(
  109                   JMeterUtils.getResString("database_url_jdbc_props")));
  110   
  111           urlJDBCPanel.add(getUrlPanel());
  112           urlJDBCPanel.add(getDriverPanel());
  113   
  114           mainPanel.add(urlJDBCPanel);
  115   
  116           // LOGIN
  117           JPanel loginPanel = new JPanel(new BorderLayout());
  118           loginPanel.setBorder(
  119               BorderFactory.createTitledBorder(
  120                   JMeterUtils.getResString("login_config")));
  121   
  122           loginGui = new LoginConfigGui(false);
  123           loginPanel.add(loginGui, BorderLayout.NORTH);
  124   
  125           mainPanel.add(loginPanel);
  126   
  127           add(mainPanel, BorderLayout.CENTER);
  128       }
  129   
  130       private JPanel getDriverPanel()
  131       {
  132           JPanel panel = new JPanel(new BorderLayout(5, 0));
  133           JLabel label =
  134               new JLabel(JMeterUtils.getResString("database_driver_class"));
  135           label.setLabelFor(driverField);
  136           driverField.setName(DRIVER);
  137           panel.add(label, BorderLayout.WEST);
  138           panel.add(driverField, BorderLayout.CENTER);
  139           return panel;
  140       }
  141   
  142       private JPanel getUrlPanel()
  143       {
  144           JPanel panel = new JPanel(new BorderLayout(5, 0));
  145           JLabel label = new JLabel(JMeterUtils.getResString("database_url"));
  146           label.setLabelFor(urlField);
  147           urlField.setName(URL);
  148           panel.add(label, BorderLayout.WEST);
  149           panel.add(urlField, BorderLayout.CENTER);
  150           return panel;
  151       }
  152   }

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