001: //$Header$
002: /*
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: */
019:
020: package org.apache.jmeter.control.gui;
021:
022: import java.awt.Color;
023: import java.awt.BorderLayout;
024: import java.awt.Container;
025: import java.util.Collection;
026:
027: import javax.swing.JCheckBox;
028: import javax.swing.JLabel;
029: import javax.swing.JMenu;
030: import javax.swing.JPanel;
031: import javax.swing.JPopupMenu;
032: import javax.swing.JTextField;
033:
034: import org.apache.jmeter.config.Arguments;
035: import org.apache.jmeter.config.gui.ArgumentsPanel;
036: import org.apache.jmeter.gui.util.DirectoryPanel;
037: import org.apache.jmeter.gui.util.ReportMenuFactory;
038: import org.apache.jmeter.report.gui.AbstractReportGui;
039: import org.apache.jmeter.report.gui.ReportPageGui;
040: import org.apache.jmeter.report.writers.gui.HTMLReportWriterGui;
041: import org.apache.jmeter.testelement.TestElement;
042: import org.apache.jmeter.testelement.ReportPlan;
043: import org.apache.jmeter.util.JMeterUtils;
044:
045: /**
046: * JMeter GUI component representing the test plan which will be executed when
047: * the test is run.
048: *
049: * @version $Revision: 493793 $ Last Updated: $Date: 2007-01-07 18:19:27 +0000 (Sun, 07 Jan 2007) $
050: */
051: public class ReportGui extends AbstractReportGui {
052:
053: private JCheckBox serializedMode;
054:
055: /** A panel to contain comments on the test plan. */
056: private JTextField commentPanel;
057:
058: private DirectoryPanel baseDir = new DirectoryPanel(JMeterUtils
059: .getResString("report_base_directory"), "", Color.white);
060:
061: /** A panel allowing the user to define variables. */
062: private ArgumentsPanel argsPanel;
063:
064: /**
065: * Create a new TestPlanGui.
066: */
067: public ReportGui() {
068: init();
069: }
070:
071: /**
072: * Need to update this to make the context popupmenu correct
073: * @return a JPopupMenu appropriate for the component.
074: */
075: public JPopupMenu createPopupMenu() {
076: JPopupMenu pop = new JPopupMenu();
077: JMenu addMenu = new JMenu(JMeterUtils.getResString("Add"));
078: addMenu.add(ReportMenuFactory
079: .makeMenuItem(new ReportPageGui().getStaticLabel(),
080: ReportPageGui.class.getName(), "Add"));
081: addMenu.add(ReportMenuFactory.makeMenuItem(
082: new HTMLReportWriterGui().getStaticLabel(),
083: HTMLReportWriterGui.class.getName(), "Add"));
084: addMenu.add(ReportMenuFactory.makeMenu(
085: ReportMenuFactory.CONFIG_ELEMENTS, "Add"));
086: pop.add(addMenu);
087: ReportMenuFactory.addFileMenu(pop);
088: ReportMenuFactory.addEditMenu(pop, true);
089: return pop;
090: }
091:
092: /* Implements JMeterGUIComponent.createTestElement() */
093: public TestElement createTestElement() {
094: ReportPlan tp = new ReportPlan();
095: modifyTestElement(tp);
096: return tp;
097: }
098:
099: /* Implements JMeterGUIComponent.modifyTestElement(TestElement) */
100: public void modifyTestElement(TestElement plan) {
101: super .configureTestElement(plan);
102: if (plan instanceof ReportPlan) {
103: ReportPlan rp = (ReportPlan) plan;
104: rp.setUserDefinedVariables((Arguments) argsPanel
105: .createTestElement());
106: rp.setProperty(ReportPlan.COMMENTS, commentPanel.getText());
107: rp.setBasedir(baseDir.getFilename());
108: }
109: }
110:
111: public String getLabelResource() {
112: return "report_plan";
113: }
114:
115: /**
116: * This is the list of menu categories this gui component will be available
117: * under. This implementation returns null, since the TestPlan appears at
118: * the top level of the tree and cannot be added elsewhere.
119: *
120: * @return a Collection of Strings, where each element is one of the
121: * constants defined in MenuFactory
122: */
123: public Collection getMenuCategories() {
124: return null;
125: }
126:
127: /**
128: * A newly created component can be initialized with the contents of a Test
129: * Element object by calling this method. The component is responsible for
130: * querying the Test Element object for the relevant information to display
131: * in its GUI.
132: *
133: * @param el
134: * the TestElement to configure
135: */
136: public void configure(TestElement el) {
137: super .configure(el);
138:
139: if (el.getProperty(ReportPlan.USER_DEFINED_VARIABLES) != null) {
140: argsPanel
141: .configure((Arguments) el.getProperty(
142: ReportPlan.USER_DEFINED_VARIABLES)
143: .getObjectValue());
144: }
145: commentPanel.setText(el
146: .getPropertyAsString(ReportPlan.COMMENTS));
147: baseDir.setFilename(el.getPropertyAsString(ReportPlan.BASEDIR));
148: }
149:
150: /**
151: * Create a panel allowing the user to define variables for the test.
152: *
153: * @return a panel for user-defined variables
154: */
155: private JPanel createVariablePanel() {
156: argsPanel = new ArgumentsPanel(JMeterUtils
157: .getResString("user_defined_variables"), Color.white);
158: return argsPanel;
159: }
160:
161: private Container createCommentPanel() {
162: JPanel panel = new JPanel();
163: panel.setBackground(Color.white);
164: panel.setLayout(new BorderLayout(10, 10));
165: Container title = makeTitlePanel();
166: commentPanel = new JTextField();
167: commentPanel.setBackground(Color.white);
168: JLabel label = new JLabel(JMeterUtils
169: .getResString("testplan_comments"));
170: label.setBackground(Color.white);
171: label.setLabelFor(commentPanel);
172: title.add(label);
173: title.add(commentPanel);
174: panel.add(title, BorderLayout.NORTH);
175: panel.add(baseDir, BorderLayout.CENTER);
176: return panel;
177: }
178:
179: /**
180: * Initialize the components and layout of this component.
181: */
182: protected void init() {
183: setLayout(new BorderLayout(10, 10));
184: setBorder(makeBorder());
185: setBackground(Color.white);
186: add(createCommentPanel(), BorderLayout.NORTH);
187: add(createVariablePanel(), BorderLayout.CENTER);
188: }
189: }
|