1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 package org.apache.jmeter.protocol.ftp.config.gui; 20 21 import java.awt.BorderLayout; 22 23 import javax.swing.BorderFactory; 24 import javax.swing.ButtonGroup; 25 import javax.swing.JCheckBox; 26 import javax.swing.JLabel; 27 import javax.swing.JPanel; 28 import javax.swing.JRadioButton; 29 import javax.swing.JTextArea; 30 import javax.swing.JTextField; 31 32 import org.apache.jmeter.config.ConfigTestElement; 33 import org.apache.jmeter.config.gui.AbstractConfigGui; 34 import org.apache.jmeter.gui.util.HorizontalPanel; 35 import org.apache.jmeter.gui.util.VerticalPanel; 36 import org.apache.jmeter.protocol.ftp.sampler.FTPSampler; 37 import org.apache.jmeter.testelement.TestElement; 38 import org.apache.jmeter.util.JMeterUtils; 39 40 public class FtpConfigGui extends AbstractConfigGui { 41 42 private JTextField server; 43 44 private JTextField port; 45 46 private JTextField remoteFile; 47 48 private JTextField localFile; 49 50 private JTextArea inputData; 51 52 private JCheckBox binaryMode; 53 54 private JCheckBox saveResponseData; 55 56 private boolean displayName = true; 57 58 private JRadioButton getBox; 59 60 private JRadioButton putBox; 61 62 public FtpConfigGui() { 63 this(true); 64 } 65 66 public FtpConfigGui(boolean displayName) { 67 this.displayName = displayName; 68 init(); 69 } 70 71 public String getLabelResource() { 72 return "ftp_sample_title"; // $NON-NLS-1$ 73 } 74 75 public void configure(TestElement element) { 76 super.configure(element); // TODO - should this be done for embedded usage? 77 // Note: the element is a ConfigTestElement when used standalone, so we cannot use FTPSampler access methods 78 server.setText(element.getPropertyAsString(FTPSampler.SERVER)); 79 port.setText(element.getPropertyAsString(FTPSampler.PORT)); 80 remoteFile.setText(element.getPropertyAsString(FTPSampler.REMOTE_FILENAME)); 81 localFile.setText(element.getPropertyAsString(FTPSampler.LOCAL_FILENAME)); 82 inputData.setText(element.getPropertyAsString(FTPSampler.INPUT_DATA)); 83 binaryMode.setSelected(element.getPropertyAsBoolean(FTPSampler.BINARY_MODE, false)); 84 saveResponseData.setSelected(element.getPropertyAsBoolean(FTPSampler.SAVE_RESPONSE, false)); 85 final boolean uploading = element.getPropertyAsBoolean(FTPSampler.UPLOAD_FILE,false); 86 if (uploading){ 87 putBox.setSelected(true); 88 } else { 89 getBox.setSelected(true); 90 } 91 } 92 93 public TestElement createTestElement() { 94 ConfigTestElement element = new ConfigTestElement(); 95 modifyTestElement(element); 96 return element; 97 } 98 99 /** 100 * Modifies a given TestElement to mirror the data in the gui components. 101 * 102 * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement) 103 */ 104 public void modifyTestElement(TestElement element) { 105 configureTestElement(element); 106 // Note: the element is a ConfigTestElement, so cannot use FTPSampler access methods 107 element.setProperty(FTPSampler.SERVER,server.getText()); 108 element.setProperty(FTPSampler.PORT,port.getText()); 109 element.setProperty(FTPSampler.REMOTE_FILENAME,remoteFile.getText()); 110 element.setProperty(FTPSampler.LOCAL_FILENAME,localFile.getText()); 111 element.setProperty(FTPSampler.INPUT_DATA,inputData.getText()); 112 element.setProperty(FTPSampler.BINARY_MODE,binaryMode.isSelected()); 113 element.setProperty(FTPSampler.SAVE_RESPONSE, saveResponseData.isSelected()); 114 element.setProperty(FTPSampler.UPLOAD_FILE,putBox.isSelected()); 115 } 116 117 /** 118 * Implements JMeterGUIComponent.clearGui 119 */ 120 public void clearGui() { 121 super.clearGui(); 122 123 server.setText(""); //$NON-NLS-1$ 124 port.setText(""); //$NON-NLS-1$ 125 remoteFile.setText(""); //$NON-NLS-1$ 126 localFile.setText(""); //$NON-NLS-1$ 127 inputData.setText(""); //$NON-NLS-1$ 128 binaryMode.setSelected(false); 129 saveResponseData.setSelected(false); 130 getBox.setSelected(true); 131 putBox.setSelected(false); 132 } 133 134 private JPanel createServerPanel() { 135 JLabel label = new JLabel(JMeterUtils.getResString("server")); //$NON-NLS-1$ 136 137 server = new JTextField(10); 138 label.setLabelFor(server); 139 140 JPanel serverPanel = new JPanel(new BorderLayout(5, 0)); 141 serverPanel.add(label, BorderLayout.WEST); 142 serverPanel.add(server, BorderLayout.CENTER); 143 return serverPanel; 144 } 145 146 private JPanel getPortPanel() { 147 port = new JTextField(4); 148 149 JLabel label = new JLabel(JMeterUtils.getResString("web_server_port")); // $NON-NLS-1$ 150 label.setLabelFor(port); 151 152 JPanel panel = new JPanel(new BorderLayout(5, 0)); 153 panel.add(label, BorderLayout.WEST); 154 panel.add(port, BorderLayout.CENTER); 155 156 return panel; 157 } 158 159 private JPanel createLocalFilenamePanel() { 160 JLabel label = new JLabel(JMeterUtils.getResString("ftp_local_file")); //$NON-NLS-1$ 161 162 localFile = new JTextField(10); 163 label.setLabelFor(localFile); 164 165 JPanel filenamePanel = new JPanel(new BorderLayout(5, 0)); 166 filenamePanel.add(label, BorderLayout.WEST); 167 filenamePanel.add(localFile, BorderLayout.CENTER); 168 return filenamePanel; 169 } 170 171 private JPanel createLocalFileContentsPanel() { 172 JLabel label = new JLabel(JMeterUtils.getResString("ftp_local_file_contents")); //$NON-NLS-1$ 173 174 inputData = new JTextArea(); 175 label.setLabelFor(inputData); 176 177 JPanel contentsPanel = new JPanel(new BorderLayout(5, 0)); 178 contentsPanel.add(label, BorderLayout.WEST); 179 contentsPanel.add(inputData, BorderLayout.CENTER); 180 return contentsPanel; 181 } 182 183 private JPanel createRemoteFilenamePanel() { 184 JLabel label = new JLabel(JMeterUtils.getResString("ftp_remote_file")); //$NON-NLS-1$ 185 186 remoteFile = new JTextField(10); 187 label.setLabelFor(remoteFile); 188 189 JPanel filenamePanel = new JPanel(new BorderLayout(5, 0)); 190 filenamePanel.add(label, BorderLayout.WEST); 191 filenamePanel.add(remoteFile, BorderLayout.CENTER); 192 return filenamePanel; 193 } 194 195 private JPanel createOptionsPanel(){ 196 197 ButtonGroup group = new ButtonGroup(); 198 199 getBox = new JRadioButton(JMeterUtils.getResString("ftp_get")); //$NON-NLS-1$ 200 group.add(getBox); 201 getBox.setSelected(true); 202 203 putBox = new JRadioButton(JMeterUtils.getResString("ftp_put")); //$NON-NLS-1$ 204 group.add(putBox); 205 206 binaryMode = new JCheckBox(JMeterUtils.getResString("ftp_binary_mode")); //$NON-NLS-1$ 207 saveResponseData = new JCheckBox(JMeterUtils.getResString("ftp_save_response_data")); //$NON-NLS-1$ 208 209 210 JPanel optionsPanel = new HorizontalPanel(); 211 optionsPanel.add(getBox); 212 optionsPanel.add(putBox); 213 optionsPanel.add(binaryMode); 214 optionsPanel.add(saveResponseData); 215 return optionsPanel; 216 } 217 private void init() { 218 setLayout(new BorderLayout(0, 5)); 219 220 if (displayName) { 221 setBorder(makeBorder()); 222 add(makeTitlePanel(), BorderLayout.NORTH); 223 } 224 225 // MAIN PANEL 226 VerticalPanel mainPanel = new VerticalPanel(); 227 JPanel serverPanel = new HorizontalPanel(); 228 serverPanel.add(createServerPanel(), BorderLayout.CENTER); 229 serverPanel.add(getPortPanel(), BorderLayout.EAST); 230 mainPanel.add(serverPanel); 231 mainPanel.add(createRemoteFilenamePanel()); 232 mainPanel.add(createLocalFilenamePanel()); 233 mainPanel.add(createLocalFileContentsPanel()); 234 mainPanel.add(createOptionsPanel()); 235 236 add(mainPanel, BorderLayout.CENTER); 237 } 238 }