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.assertions.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.assertions.BeanShellAssertion;
031: import org.apache.jmeter.testelement.TestElement;
032: import org.apache.jmeter.util.JMeterUtils;
033:
034: public class BeanShellAssertionGui extends AbstractAssertionGui {
035:
036: private JTextField filename;// script file name (if present)
037:
038: private JTextField parameters;// parameters to pass to script file (or script)
039:
040: private JTextArea scriptField;// script area
041:
042: public BeanShellAssertionGui() {
043: init();
044: }
045:
046: public void configure(TestElement element) {
047: scriptField.setText(element
048: .getPropertyAsString(BeanShellAssertion.SCRIPT));
049: filename.setText(element
050: .getPropertyAsString(BeanShellAssertion.FILENAME));
051: parameters.setText(element
052: .getPropertyAsString(BeanShellAssertion.PARAMETERS));
053: super .configure(element);
054: }
055:
056: public TestElement createTestElement() {
057: BeanShellAssertion sampler = new BeanShellAssertion();
058: modifyTestElement(sampler);
059: return sampler;
060: }
061:
062: /**
063: * Modifies a given TestElement to mirror the data in the gui components.
064: *
065: * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
066: */
067: public void modifyTestElement(TestElement te) {
068: te.clear();
069: this .configureTestElement(te);
070: te
071: .setProperty(BeanShellAssertion.SCRIPT, scriptField
072: .getText());
073: te.setProperty(BeanShellAssertion.FILENAME, filename.getText());
074: te.setProperty(BeanShellAssertion.PARAMETERS, parameters
075: .getText());
076: }
077:
078: public String getLabelResource() {
079: return "bsh_assertion_title"; // $NON-NLS-1$
080: }
081:
082: private JPanel createFilenamePanel()// TODO ought to be a FileChooser ...
083: {
084: JLabel label = new JLabel(JMeterUtils
085: .getResString("bsh_script_file")); //$NON-NLS-1$
086:
087: filename = new JTextField(10);
088: filename.setName(BeanShellAssertion.FILENAME);
089: label.setLabelFor(filename);
090:
091: JPanel filenamePanel = new JPanel(new BorderLayout(5, 0));
092: filenamePanel.add(label, BorderLayout.WEST);
093: filenamePanel.add(filename, BorderLayout.CENTER);
094: return filenamePanel;
095: }
096:
097: private JPanel createParameterPanel() {
098: JLabel label = new JLabel(JMeterUtils
099: .getResString("bsh_script_parameters")); //$NON-NLS-1$
100:
101: parameters = new JTextField(10);
102: parameters.setName(BeanShellAssertion.PARAMETERS);
103: label.setLabelFor(parameters);
104:
105: JPanel parameterPanel = new JPanel(new BorderLayout(5, 0));
106: parameterPanel.add(label, BorderLayout.WEST);
107: parameterPanel.add(parameters, BorderLayout.CENTER);
108: return parameterPanel;
109: }
110:
111: private void init() {
112: setLayout(new BorderLayout(0, 5));
113: setBorder(makeBorder());
114:
115: Box box = Box.createVerticalBox();
116: box.add(makeTitlePanel());
117: box.add(createParameterPanel());
118: box.add(createFilenamePanel());
119: add(box, BorderLayout.NORTH);
120:
121: JPanel panel = createScriptPanel();
122: add(panel, BorderLayout.CENTER);
123: // Don't let the input field shrink too much
124: add(Box.createVerticalStrut(panel.getPreferredSize().height),
125: BorderLayout.WEST);
126: }
127:
128: private JPanel createScriptPanel() {
129: scriptField = new JTextArea();
130: scriptField.setRows(4);
131: scriptField.setLineWrap(true);
132: scriptField.setWrapStyleWord(true);
133:
134: JLabel label = new JLabel(JMeterUtils
135: .getResString("bsh_assertion_script")); //$NON-NLS-1$
136: label.setLabelFor(scriptField);
137:
138: JPanel panel = new JPanel(new BorderLayout());
139: panel.add(label, BorderLayout.NORTH);
140: panel.add(new JScrollPane(scriptField), BorderLayout.CENTER);
141:
142: JTextArea explain = new JTextArea(JMeterUtils
143: .getResString("bsh_assertion_script_variables")); //$NON-NLS-1$
144: explain.setLineWrap(true);
145: explain.setEditable(false);
146: explain.setBackground(this .getBackground());
147: panel.add(explain, BorderLayout.SOUTH);
148:
149: return panel;
150: }
151:
152: public void clearGui() {
153: super .clearGui();
154: filename.setText(""); // $NON-NLS-1$
155: parameters.setText(""); // $NON-NLS-1$
156: scriptField.setText(""); // $NON-NLS-1$
157: }
158: }
|