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/SqlConfigGui.java,v 1.11 2005/07/12 20:51:09 mstover1 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.Dimension;
   23   
   24   import javax.swing.Box;
   25   import javax.swing.JLabel;
   26   import javax.swing.JPanel;
   27   import javax.swing.JScrollPane;
   28   import javax.swing.JTextArea;
   29   
   30   import org.apache.jmeter.config.ConfigTestElement;
   31   import org.apache.jmeter.config.gui.AbstractConfigGui;
   32   import org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler;
   33   import org.apache.jmeter.testelement.TestElement;
   34   import org.apache.jmeter.util.JMeterUtils;
   35   
   36   /**
   37    * @version $Revision: 1.11 $ on $Date: 2005/07/12 20:51:09 $
   38    */
   39   public class SqlConfigGui extends AbstractConfigGui {
   40   	private JTextArea sqlField;
   41   
   42   	private boolean displayName;
   43   
   44   	public SqlConfigGui() {
   45   		this(true);
   46   	}
   47   
   48   	public SqlConfigGui(boolean displayName) {
   49   		this.displayName = displayName;
   50   		init();
   51   	}
   52   
   53   	public String getLabelResource() {
   54   		return "database_sql_query_title";
   55   	}
   56   
   57   	public void configure(TestElement element) {
   58   		sqlField.setText(element.getPropertyAsString(JDBCSampler.QUERY));
   59   		super.configure(element);
   60   	}
   61   
   62   	public TestElement createTestElement() {
   63   		ConfigTestElement element = new ConfigTestElement();
   64   		modifyTestElement(element);
   65   		return element;
   66   	}
   67   
   68   	/**
   69   	 * Modifies a given TestElement to mirror the data in the gui components.
   70   	 * 
   71   	 * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
   72   	 */
   73   	public void modifyTestElement(TestElement element) {
   74   		configureTestElement(element);
   75   
   76   		String text = sqlField.getText();
   77   		// Remove any line feeds from the text
   78   		text = text.replace('\n', ' ');
   79   		element.setProperty(JDBCSampler.QUERY, text);
   80   	}
   81   
   82   	private void init() {
   83   		setLayout(new BorderLayout(0, 5));
   84   
   85   		if (displayName) {
   86   			setBorder(makeBorder());
   87   			add(makeTitlePanel(), BorderLayout.NORTH);
   88   		}
   89   
   90   		JPanel panel = createSqlPanel();
   91   		add(panel, BorderLayout.CENTER);
   92   		// Don't let the SQL field shrink too much
   93   		add(Box.createVerticalStrut(panel.getPreferredSize().height), BorderLayout.WEST);
   94   	}
   95   
   96   	private JPanel createSqlPanel() {
   97   		sqlField = new JTextArea();
   98   		sqlField.setRows(4);
   99   		sqlField.setLineWrap(true);
  100   		sqlField.setWrapStyleWord(true);
  101   
  102   		JLabel label = new JLabel(JMeterUtils.getResString("database_sql_query_string"));
  103   		label.setLabelFor(sqlField);
  104   
  105   		JPanel panel = new JPanel(new BorderLayout());
  106   		panel.add(label, BorderLayout.NORTH);
  107   		panel.add(new JScrollPane(sqlField), BorderLayout.CENTER);
  108   		return panel;
  109   	}
  110   
  111   	public Dimension getPreferredSize() {
  112   		return getMinimumSize();
  113   	}
  114   }

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