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.ftp.config.gui;
020:
021: import java.awt.BorderLayout;
022:
023: import javax.swing.ButtonGroup;
024: import javax.swing.JCheckBox;
025: import javax.swing.JLabel;
026: import javax.swing.JPanel;
027: import javax.swing.JRadioButton;
028: import javax.swing.JTextField;
029:
030: import org.apache.jmeter.config.ConfigTestElement;
031: import org.apache.jmeter.config.gui.AbstractConfigGui;
032: import org.apache.jmeter.gui.util.HorizontalPanel;
033: import org.apache.jmeter.gui.util.VerticalPanel;
034: import org.apache.jmeter.protocol.ftp.sampler.FTPSampler;
035: import org.apache.jmeter.testelement.TestElement;
036: import org.apache.jmeter.util.JMeterUtils;
037:
038: public class FtpConfigGui extends AbstractConfigGui {
039:
040: private JTextField server;
041:
042: private JTextField remoteFile;
043:
044: private JTextField localFile;
045:
046: private JCheckBox binaryMode;
047:
048: private JCheckBox saveResponseData;
049:
050: private boolean displayName = true;
051:
052: private JRadioButton getBox;
053:
054: private JRadioButton putBox;
055:
056: public FtpConfigGui() {
057: this (true);
058: }
059:
060: public FtpConfigGui(boolean displayName) {
061: this .displayName = displayName;
062: init();
063: }
064:
065: public String getLabelResource() {
066: return "ftp_sample_title"; // $NON-NLS-1$
067: }
068:
069: public void configure(TestElement element) {
070: super .configure(element);
071: // Note: the element is a ConfigTestElement, so cannot use FTPSampler access methods
072: server.setText(element.getPropertyAsString(FTPSampler.SERVER));
073: remoteFile.setText(element
074: .getPropertyAsString(FTPSampler.REMOTE_FILENAME));
075: localFile.setText(element
076: .getPropertyAsString(FTPSampler.LOCAL_FILENAME));
077: binaryMode.setSelected(element.getPropertyAsBoolean(
078: FTPSampler.BINARY_MODE, false));
079: saveResponseData.setSelected(element.getPropertyAsBoolean(
080: FTPSampler.SAVE_RESPONSE, false));
081: putBox.setSelected(element.getPropertyAsBoolean(
082: FTPSampler.UPLOAD_FILE, false));
083: }
084:
085: public TestElement createTestElement() {
086: ConfigTestElement element = new ConfigTestElement();
087: modifyTestElement(element);
088: return element;
089: }
090:
091: /**
092: * Modifies a given TestElement to mirror the data in the gui components.
093: *
094: * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
095: */
096: public void modifyTestElement(TestElement element) {
097: configureTestElement(element);
098: // Note: the element is a ConfigTestElement, so cannot use FTPSampler access methods
099: element.setProperty(FTPSampler.SERVER, server.getText());
100: element.setProperty(FTPSampler.REMOTE_FILENAME, remoteFile
101: .getText());
102: element.setProperty(FTPSampler.LOCAL_FILENAME, localFile
103: .getText());
104: element.setProperty(FTPSampler.BINARY_MODE, binaryMode
105: .isSelected());
106: element.setProperty(FTPSampler.SAVE_RESPONSE, saveResponseData
107: .isSelected());
108: element
109: .setProperty(FTPSampler.UPLOAD_FILE, putBox
110: .isSelected());
111: }
112:
113: /**
114: * Implements JMeterGUIComponent.clearGui
115: */
116: public void clearGui() {
117: super .clearGui();
118:
119: server.setText(""); //$NON-NLS-1$
120: remoteFile.setText(""); //$NON-NLS-1$
121: localFile.setText(""); //$NON-NLS-1$
122: binaryMode.setSelected(false);
123: saveResponseData.setSelected(false);
124: getBox.setSelected(true);
125: putBox.setSelected(false);
126: }
127:
128: private JPanel createServerPanel() {
129: JLabel label = new JLabel(JMeterUtils.getResString("server")); //$NON-NLS-1$
130:
131: server = new JTextField(10);
132: label.setLabelFor(server);
133:
134: JPanel serverPanel = new JPanel(new BorderLayout(5, 0));
135: serverPanel.add(label, BorderLayout.WEST);
136: serverPanel.add(server, BorderLayout.CENTER);
137: return serverPanel;
138: }
139:
140: private JPanel createLocalFilenamePanel() {
141: JLabel label = new JLabel(JMeterUtils
142: .getResString("ftp_local_file")); //$NON-NLS-1$
143:
144: localFile = new JTextField(10);
145: label.setLabelFor(localFile);
146:
147: JPanel filenamePanel = new JPanel(new BorderLayout(5, 0));
148: filenamePanel.add(label, BorderLayout.WEST);
149: filenamePanel.add(localFile, BorderLayout.CENTER);
150: return filenamePanel;
151: }
152:
153: private JPanel createRemoteFilenamePanel() {
154: JLabel label = new JLabel(JMeterUtils
155: .getResString("ftp_remote_file")); //$NON-NLS-1$
156:
157: remoteFile = new JTextField(10);
158: label.setLabelFor(remoteFile);
159:
160: JPanel filenamePanel = new JPanel(new BorderLayout(5, 0));
161: filenamePanel.add(label, BorderLayout.WEST);
162: filenamePanel.add(remoteFile, BorderLayout.CENTER);
163: return filenamePanel;
164: }
165:
166: private JPanel createOptionsPanel() {
167:
168: ButtonGroup group = new ButtonGroup();
169:
170: getBox = new JRadioButton(JMeterUtils.getResString("ftp_get")); //$NON-NLS-1$
171: group.add(getBox);
172: getBox.setSelected(true);
173:
174: putBox = new JRadioButton(JMeterUtils.getResString("ftp_put")); //$NON-NLS-1$
175: group.add(putBox);
176:
177: binaryMode = new JCheckBox(JMeterUtils
178: .getResString("ftp_binary_mode")); //$NON-NLS-1$
179: saveResponseData = new JCheckBox(JMeterUtils
180: .getResString("ftp_save_response_data")); //$NON-NLS-1$
181:
182: JPanel optionsPanel = new HorizontalPanel();
183: optionsPanel.add(getBox);
184: optionsPanel.add(putBox);
185: optionsPanel.add(binaryMode);
186: optionsPanel.add(saveResponseData);
187: return optionsPanel;
188: }
189:
190: private void init() {
191: setLayout(new BorderLayout(0, 5));
192:
193: if (displayName) {
194: setBorder(makeBorder());
195: add(makeTitlePanel(), BorderLayout.NORTH);
196: }
197:
198: // MAIN PANEL
199: VerticalPanel mainPanel = new VerticalPanel();
200: mainPanel.add(createServerPanel());
201: mainPanel.add(createRemoteFilenamePanel());
202: mainPanel.add(createLocalFilenamePanel());
203: mainPanel.add(createOptionsPanel());
204:
205: add(mainPanel, BorderLayout.CENTER);
206: }
207: }
|