KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > protocol > jdbc > config > gui > SqlConfigGui


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/gui/SqlConfigGui.java,v 1.10 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 JavaDoc;
22 import java.awt.Dimension JavaDoc;
23
24 import javax.swing.Box JavaDoc;
25 import javax.swing.JLabel JavaDoc;
26 import javax.swing.JPanel JavaDoc;
27 import javax.swing.JScrollPane JavaDoc;
28 import javax.swing.JTextArea JavaDoc;
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.10 $ on $Date: 2004/03/05 01:38:42 $
38  */

39 public class SqlConfigGui extends AbstractConfigGui
40 {
41     private JTextArea JavaDoc sqlField;
42     private boolean displayName;
43
44     public SqlConfigGui()
45     {
46         this(true);
47     }
48
49     public SqlConfigGui(boolean displayName)
50     {
51         this.displayName = displayName;
52         init();
53     }
54
55     public String JavaDoc getLabelResource()
56     {
57         return "database_sql_query_title";
58     }
59
60     public void configure(TestElement element)
61     {
62         sqlField.setText(element.getPropertyAsString(JDBCSampler.QUERY));
63         super.configure(element);
64     }
65
66     public TestElement createTestElement()
67     {
68         ConfigTestElement element = new ConfigTestElement();
69         modifyTestElement(element);
70         return element;
71     }
72
73     /**
74      * Modifies a given TestElement to mirror the data in the gui components.
75      * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
76      */

77     public void modifyTestElement(TestElement element)
78     {
79         configureTestElement(element);
80
81         String JavaDoc text = sqlField.getText();
82         // Remove any line feeds from the text
83
text = text.replace('\n', ' ');
84         element.setProperty(JDBCSampler.QUERY, text);
85     }
86
87     private void init()
88     {
89         setLayout(new BorderLayout JavaDoc(0, 5));
90
91         if (displayName)
92         {
93             setBorder(makeBorder());
94             add(makeTitlePanel(), BorderLayout.NORTH);
95         }
96
97         JPanel JavaDoc panel = createSqlPanel();
98         add(panel, BorderLayout.CENTER);
99         // Don't let the SQL field shrink too much
100
add(
101             Box.createVerticalStrut(panel.getPreferredSize().height),
102             BorderLayout.WEST);
103     }
104
105     private JPanel JavaDoc createSqlPanel()
106     {
107         sqlField = new JTextArea JavaDoc();
108         sqlField.setRows(4);
109         sqlField.setLineWrap(true);
110         sqlField.setWrapStyleWord(true);
111
112         JLabel JavaDoc label =
113             new JLabel JavaDoc(JMeterUtils.getResString("database_sql_query_string"));
114         label.setLabelFor(sqlField);
115
116         JPanel JavaDoc panel = new JPanel JavaDoc(new BorderLayout JavaDoc());
117         panel.add(label, BorderLayout.NORTH);
118         panel.add(new JScrollPane JavaDoc(sqlField), BorderLayout.CENTER);
119         return panel;
120     }
121
122     public Dimension JavaDoc getPreferredSize()
123     {
124         return getMinimumSize();
125     }
126 }
127
Popular Tags