001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.protocol.java.control.gui;
020:
021: import java.awt.BorderLayout;
022:
023: import javax.swing.Box;
024: import javax.swing.JLabel;
025: import javax.swing.JPanel;
026: import javax.swing.JScrollPane;
027: import javax.swing.JTextArea;
028: import javax.swing.JTextField;
029:
030: import org.apache.jmeter.protocol.java.sampler.BeanShellSampler;
031: import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
032: import org.apache.jmeter.testelement.TestElement;
033: import org.apache.jmeter.util.JMeterUtils;
034:
035: public class BeanShellSamplerGui extends AbstractSamplerGui {
036:
037: private JTextField filename;// script file name (if present)
038:
039: private JTextField parameters;// parameters to pass to script file (or script)
040:
041: private JTextArea scriptField;// script area
042:
043: public BeanShellSamplerGui() {
044: init();
045: }
046:
047: public void configure(TestElement element) {
048: scriptField.setText(element
049: .getPropertyAsString(BeanShellSampler.SCRIPT));
050: filename.setText(element
051: .getPropertyAsString(BeanShellSampler.FILENAME));
052: parameters.setText(element
053: .getPropertyAsString(BeanShellSampler.PARAMETERS));
054: super .configure(element);
055: }
056:
057: public TestElement createTestElement() {
058: BeanShellSampler sampler = new BeanShellSampler();
059: modifyTestElement(sampler);
060: return sampler;
061: }
062:
063: /**
064: * Modifies a given TestElement to mirror the data in the gui components.
065: *
066: * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
067: */
068: public void modifyTestElement(TestElement te) {
069: te.clear();
070: this .configureTestElement(te);
071: te.setProperty(BeanShellSampler.SCRIPT, scriptField.getText());
072: te.setProperty(BeanShellSampler.FILENAME, filename.getText());
073: te.setProperty(BeanShellSampler.PARAMETERS, parameters
074: .getText());
075: }
076:
077: /**
078: * Implements JMeterGUIComponent.clearGui
079: */
080: public void clearGui() {
081: super .clearGui();
082:
083: filename.setText(""); //$NON-NLS-1$
084: parameters.setText(""); //$NON-NLS-1$
085: scriptField.setText(""); //$NON-NLS-1$
086: }
087:
088: public String getLabelResource() {
089: return "bsh_sampler_title"; // $NON-NLS-1$
090: }
091:
092: private JPanel createFilenamePanel()// TODO ought to be a FileChooser ...
093: {
094: JLabel label = new JLabel(JMeterUtils
095: .getResString("bsh_script_file")); // $NON-NLS-1$
096:
097: filename = new JTextField(10);
098: filename.setName(BeanShellSampler.FILENAME);
099: label.setLabelFor(filename);
100:
101: JPanel filenamePanel = new JPanel(new BorderLayout(5, 0));
102: filenamePanel.add(label, BorderLayout.WEST);
103: filenamePanel.add(filename, BorderLayout.CENTER);
104: return filenamePanel;
105: }
106:
107: private JPanel createParameterPanel() {
108: JLabel label = new JLabel(JMeterUtils
109: .getResString("bsh_script_parameters")); // $NON-NLS-1$
110:
111: parameters = new JTextField(10);
112: parameters.setName(BeanShellSampler.PARAMETERS);
113: label.setLabelFor(parameters);
114:
115: JPanel parameterPanel = new JPanel(new BorderLayout(5, 0));
116: parameterPanel.add(label, BorderLayout.WEST);
117: parameterPanel.add(parameters, BorderLayout.CENTER);
118: return parameterPanel;
119: }
120:
121: private void init() {
122: setLayout(new BorderLayout(0, 5));
123: setBorder(makeBorder());
124:
125: Box box = Box.createVerticalBox();
126: box.add(makeTitlePanel());
127: box.add(createParameterPanel());
128: box.add(createFilenamePanel());
129: add(box, BorderLayout.NORTH);
130:
131: JPanel panel = createScriptPanel();
132: add(panel, BorderLayout.CENTER);
133: // Don't let the input field shrink too much
134: add(Box.createVerticalStrut(panel.getPreferredSize().height),
135: BorderLayout.WEST);
136: }
137:
138: private JPanel createScriptPanel() {
139: scriptField = new JTextArea();
140: scriptField.setRows(4);
141: scriptField.setLineWrap(true);
142: scriptField.setWrapStyleWord(true);
143:
144: JLabel label = new JLabel(JMeterUtils
145: .getResString("bsh_script")); // $NON-NLS-1$
146: label.setLabelFor(scriptField);
147:
148: JPanel panel = new JPanel(new BorderLayout());
149: panel.add(label, BorderLayout.NORTH);
150: panel.add(new JScrollPane(scriptField), BorderLayout.CENTER);
151:
152: JTextArea explain = new JTextArea(JMeterUtils
153: .getResString("bsh_script_variables")); //$NON-NLS-1$
154: explain.setLineWrap(true);
155: explain.setEditable(false);
156: explain.setBackground(this.getBackground());
157: panel.add(explain, BorderLayout.SOUTH);
158:
159: return panel;
160: }
161: }
|