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.http.control.gui;
020:
021: import java.awt.BorderLayout;
022: import java.awt.Dimension;
023: import java.awt.GridBagLayout;
024: import java.awt.GridBagConstraints;
025: import java.awt.event.ActionEvent;
026: import java.awt.event.ActionListener;
027:
028: import javax.swing.JCheckBox;
029: import javax.swing.JPanel;
030:
031: import org.apache.jmeter.protocol.http.sampler.SoapSampler;
032: import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
033: import org.apache.jmeter.testelement.TestElement;
034: import org.apache.jmeter.util.JMeterUtils;
035: import org.apache.jmeter.gui.util.FilePanel;
036: import org.apache.jorphan.gui.JLabeledTextArea;
037: import org.apache.jorphan.gui.JLabeledTextField;
038:
039: public class SoapSamplerGui extends AbstractSamplerGui {
040: private JLabeledTextField urlField;
041: private JLabeledTextField soapAction;
042: private JCheckBox sendSoapAction;
043: private JCheckBox useKeepAlive;
044: private JLabeledTextArea soapXml;
045:
046: private FilePanel soapXmlFile = new FilePanel();
047:
048: public SoapSamplerGui() {
049: init();
050: }
051:
052: public String getLabelResource() {
053: return "soap_sampler_title"; //$NON-NLS-1$
054: }
055:
056: /*
057: * (non-Javadoc)
058: *
059: * @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
060: */
061: public TestElement createTestElement() {
062: SoapSampler sampler = new SoapSampler();
063: modifyTestElement(sampler);
064: return sampler;
065: }
066:
067: /**
068: * Modifies a given TestElement to mirror the data in the gui components.
069: *
070: * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
071: */
072: public void modifyTestElement(TestElement s) {
073: this .configureTestElement(s);
074: if (s instanceof SoapSampler) {
075: SoapSampler sampler = (SoapSampler) s;
076: sampler.setURLData(urlField.getText());
077: sampler.setXmlData(soapXml.getText());
078: sampler.setXmlFile(soapXmlFile.getFilename());
079: sampler.setSOAPAction(soapAction.getText());
080: sampler.setSendSOAPAction(sendSoapAction.isSelected());
081: sampler.setUseKeepAlive(useKeepAlive.isSelected());
082: }
083: }
084:
085: /**
086: * Implements JMeterGUIComponent.clearGui
087: */
088: public void clearGui() {
089: super .clearGui();
090:
091: urlField.setText(""); //$NON-NLS-1$
092: soapAction.setText(""); //$NON-NLS-1$
093: soapXml.setText(""); //$NON-NLS-1$
094: sendSoapAction.setSelected(true);
095: soapXmlFile.setFilename(""); //$NON-NLS-1$
096: useKeepAlive.setSelected(false);
097: }
098:
099: private void init() {
100: setLayout(new BorderLayout());
101: setBorder(makeBorder());
102:
103: add(makeTitlePanel(), BorderLayout.NORTH);
104:
105: urlField = new JLabeledTextField(JMeterUtils
106: .getResString("url"), 10); //$NON-NLS-1$
107: soapXml = new JLabeledTextArea(JMeterUtils
108: .getResString("soap_data_title")); //$NON-NLS-1$
109: soapAction = new JLabeledTextField("", 10); //$NON-NLS-1$
110: sendSoapAction = new JCheckBox(JMeterUtils
111: .getResString("soap_send_action"), true); //$NON-NLS-1$
112: useKeepAlive = new JCheckBox(JMeterUtils
113: .getResString("use_keepalive")); // $NON-NLS-1$
114:
115: JPanel mainPanel = new JPanel(new BorderLayout());
116: JPanel soapActionPanel = new JPanel();
117: soapActionPanel.setLayout(new GridBagLayout());
118: GridBagConstraints c = new GridBagConstraints();
119: c.fill = GridBagConstraints.HORIZONTAL;
120: c.gridwidth = 2;
121: c.gridx = 0;
122: c.gridy = 0;
123: c.weightx = 1;
124: soapActionPanel.add(urlField, c);
125: c.fill = GridBagConstraints.NONE;
126: c.gridwidth = 1;
127: c.gridy = 1;
128: c.weightx = 0;
129: soapActionPanel.add(sendSoapAction, c);
130: c.gridx = 1;
131: c.fill = GridBagConstraints.HORIZONTAL;
132: c.weightx = 1;
133: soapActionPanel.add(soapAction, c);
134:
135: c.fill = GridBagConstraints.HORIZONTAL;
136: c.gridwidth = 2;
137: c.gridy = 2;
138: c.gridx = 0;
139: soapActionPanel.add(useKeepAlive, c);
140:
141: mainPanel.add(soapActionPanel, BorderLayout.NORTH);
142: mainPanel.add(soapXml, BorderLayout.CENTER);
143: mainPanel.add(soapXmlFile, BorderLayout.SOUTH);
144:
145: sendSoapAction.addActionListener(new ActionListener() {
146: public void actionPerformed(ActionEvent e) {
147: soapAction.setEnabled(sendSoapAction.isSelected());
148: }
149: });
150:
151: add(mainPanel, BorderLayout.CENTER);
152: }
153:
154: public void configure(TestElement el) {
155: super .configure(el);
156: SoapSampler sampler = (SoapSampler) el;
157: urlField.setText(sampler.getURLData());
158: sendSoapAction.setSelected(sampler.getSendSOAPAction());
159: soapAction.setText(sampler.getSOAPAction());
160: soapXml.setText(sampler.getXmlData());
161: soapXmlFile.setFilename(sampler.getXmlFile());
162: useKeepAlive.setSelected(sampler.getUseKeepAlive());
163: }
164:
165: public Dimension getPreferredSize() {
166: return getMinimumSize();
167: }
168: }
|