KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > control > gui > TestPlanGui


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/control/gui/TestPlanGui.java,v 1.18 2004/03/05 01:34:05 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.control.gui;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.Container JavaDoc;
23 import java.util.Collection JavaDoc;
24
25 import javax.swing.JCheckBox JavaDoc;
26 import javax.swing.JLabel JavaDoc;
27 import javax.swing.JMenu JavaDoc;
28 import javax.swing.JPanel JavaDoc;
29 import javax.swing.JPopupMenu JavaDoc;
30 import javax.swing.JTextArea JavaDoc;
31
32 import org.apache.jmeter.config.Arguments;
33 import org.apache.jmeter.config.gui.ArgumentsPanel;
34 import org.apache.jmeter.gui.AbstractJMeterGuiComponent;
35 import org.apache.jmeter.gui.util.MenuFactory;
36 import org.apache.jmeter.gui.util.VerticalPanel;
37 import org.apache.jmeter.testelement.AbstractTestElement;
38 import org.apache.jmeter.testelement.TestElement;
39 import org.apache.jmeter.testelement.TestPlan;
40 import org.apache.jmeter.threads.gui.ThreadGroupGui;
41 import org.apache.jmeter.util.JMeterUtils;
42
43 /**
44  * JMeter GUI component representing the test plan which will be executed when
45  * the test is run.
46  *
47  * @version $Revision: 1.18 $ Last Updated: $Date: 2004/03/05 01:34:05 $
48  */

49 public class TestPlanGui extends AbstractJMeterGuiComponent
50 {
51
52     /**
53      * A checkbox allowing the user to specify whether or not JMeter should
54      * do functional testing.
55      */

56     private JCheckBox JavaDoc functionalMode;
57     
58     private JCheckBox JavaDoc serializedMode;
59     
60     /** A panel allowing the user to define variables. */
61     private ArgumentsPanel argsPanel;
62
63     /** A panel to contain comments on the test plan. */
64     private JTextArea JavaDoc commentPanel;
65
66     /**
67      * Create a new TestPlanGui.
68      */

69     public TestPlanGui()
70     {
71         init();
72     }
73
74     /**
75      * When a user right-clicks on the component in the test tree, or
76      * selects the edit menu when the component is selected, the
77      * component will be asked to return a JPopupMenu that provides
78      * all the options available to the user from this component.
79      * <p>
80      * The TestPlan will return a popup menu allowing you to add ThreadGroups,
81      * Listeners, Configuration Elements, Assertions, PreProcessors,
82      * PostProcessors, and Timers.
83      *
84      * @return a JPopupMenu appropriate for the component.
85      */

86     public JPopupMenu JavaDoc createPopupMenu()
87     {
88         JPopupMenu JavaDoc pop = new JPopupMenu JavaDoc();
89         JMenu JavaDoc addMenu = new JMenu JavaDoc(JMeterUtils.getResString("Add"));
90         addMenu.add(MenuFactory.makeMenuItem(
91                 new ThreadGroupGui().getStaticLabel(),
92                 ThreadGroupGui.class.getName(),
93                 "Add"));
94         addMenu.add(MenuFactory.makeMenu(MenuFactory.LISTENERS, "Add"));
95         addMenu.add(MenuFactory.makeMenu(MenuFactory.CONFIG_ELEMENTS, "Add"));
96         addMenu.add(MenuFactory.makeMenu(MenuFactory.ASSERTIONS, "Add"));
97         addMenu.add(MenuFactory.makeMenu(MenuFactory.PRE_PROCESSORS, "Add"));
98         addMenu.add(MenuFactory.makeMenu(MenuFactory.POST_PROCESSORS, "Add"));
99         addMenu.add(MenuFactory.makeMenu(MenuFactory.TIMERS, "Add"));
100         pop.add(addMenu);
101         MenuFactory.addFileMenu(pop);
102         return pop;
103     }
104
105     /* Implements JMeterGUIComponent.createTestElement() */
106     public TestElement createTestElement()
107     {
108         TestPlan tp = new TestPlan();
109         modifyTestElement(tp);
110         return tp;
111     }
112
113     /* Implements JMeterGUIComponent.modifyTestElement(TestElement) */
114     public void modifyTestElement(TestElement plan)
115     {
116         super.configureTestElement(plan);
117         if (plan instanceof TestPlan)
118         {
119             TestPlan tp = (TestPlan) plan;
120             tp.setFunctionalMode(functionalMode.isSelected());
121             tp.setSerialized(serializedMode.isSelected());
122             tp.setUserDefinedVariables(
123                 (Arguments) argsPanel.createTestElement());
124             tp.setProperty(TestPlan.COMMENTS,commentPanel.getText());
125         }
126     }
127
128     public String JavaDoc getLabelResource()
129     {
130         return "test_plan";
131     }
132
133     /**
134      * This is the list of menu categories this gui component will be available
135      * under. This implementation returns null, since the TestPlan appears at
136      * the top level of the tree and cannot be added elsewhere.
137      *
138      * @return a Collection of Strings, where each element is one of the
139      * constants defined in MenuFactory
140      */

141     public Collection JavaDoc getMenuCategories()
142     {
143         return null;
144     }
145
146     /**
147      * A newly created component can be initialized with the contents of
148      * a Test Element object by calling this method. The component is
149      * responsible for querying the Test Element object for the
150      * relevant information to display in its GUI.
151      *
152      * @param el the TestElement to configure
153      */

154     public void configure(TestElement el)
155     {
156         super.configure(el);
157         functionalMode.setSelected(
158             ((AbstractTestElement) el).getPropertyAsBoolean(
159                 TestPlan.FUNCTIONAL_MODE));
160         
161         serializedMode.setSelected(
162             ((AbstractTestElement) el).getPropertyAsBoolean(
163                 TestPlan.SERIALIZE_THREADGROUPS));
164
165         if (el.getProperty(TestPlan.USER_DEFINED_VARIABLES) != null)
166         {
167             argsPanel.configure(
168                 (Arguments) el
169                     .getProperty(TestPlan.USER_DEFINED_VARIABLES)
170                     .getObjectValue());
171         }
172         commentPanel.setText(el.getPropertyAsString(TestPlan.COMMENTS));
173     }
174
175     /**
176      * Create a panel allowing the user to define variables for the test.
177      *
178      * @return a panel for user-defined variables
179      */

180     private JPanel JavaDoc createVariablePanel()
181     {
182         argsPanel =
183             new ArgumentsPanel(
184                 JMeterUtils.getResString("user_defined_variables"));
185
186         return argsPanel;
187     }
188
189     private Container JavaDoc createCommentPanel(){
190         Container JavaDoc panel = makeTitlePanel();
191         commentPanel = new JTextArea JavaDoc();
192         JLabel JavaDoc label = new JLabel JavaDoc(JMeterUtils.getResString("testplan_comments"));
193         label.setLabelFor(commentPanel);
194         panel.add(label);
195         panel.add(commentPanel);
196         return panel;
197     }
198     /**
199      * Initialize the components and layout of this component.
200      */

201     private void init()
202     {
203         setLayout(new BorderLayout JavaDoc(10, 10));
204         setBorder(makeBorder());
205         
206         add(createCommentPanel(), BorderLayout.NORTH);
207
208         add(createVariablePanel(), BorderLayout.CENTER);
209
210         VerticalPanel southPanel = new VerticalPanel();
211         serializedMode =
212             new JCheckBox JavaDoc(JMeterUtils.getResString("testplan.serialized"));
213         southPanel.add(serializedMode);
214         functionalMode =
215             new JCheckBox JavaDoc(JMeterUtils.getResString("functional_mode"));
216         southPanel.add(functionalMode);
217         JTextArea JavaDoc explain =
218             new JTextArea JavaDoc(
219                 JMeterUtils.getResString("functional_mode_explanation"));
220         explain.setEditable(false);
221         explain.setBackground(this.getBackground());
222         southPanel.add(explain);
223
224         add(southPanel, BorderLayout.SOUTH);
225     }
226 }
227
Popular Tags