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.config.gui;
020:
021: import java.awt.BorderLayout;
022: import java.awt.event.ActionEvent;
023: import java.awt.event.ActionListener;
024: import java.io.File;
025:
026: import javax.swing.BorderFactory;
027: import javax.swing.BoxLayout;
028: import javax.swing.JButton;
029: import javax.swing.JFileChooser;
030: import javax.swing.JLabel;
031: import javax.swing.JPanel;
032: import javax.swing.JTextField;
033:
034: import org.apache.jmeter.gui.util.FileDialoger;
035: import org.apache.jmeter.gui.util.VerticalPanel;
036: import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
037: import org.apache.jmeter.testelement.TestElement;
038: import org.apache.jmeter.util.JMeterUtils;
039:
040: /**
041: * @author Michael Stover
042: */
043: public class MultipartUrlConfigGui extends UrlConfigGui implements
044: ActionListener {
045:
046: private JTextField filenameField;
047:
048: private JTextField paramNameField;
049:
050: private JTextField mimetypeField;
051:
052: // TODO these are used as names for the GUI elements - are they needed? are they NLS?
053: private static String FILENAME = "filename";
054:
055: private static String BROWSE = "browse"; // $NON-NLS-1$ used as an ActionName locally
056:
057: private static String PARAMNAME = "paramname";
058:
059: private static String MIMETYPE = "mimetype";
060:
061: public MultipartUrlConfigGui() {
062: super ();
063: }
064:
065: public TestElement createTestElement() {
066: TestElement ce = super .createTestElement();
067:
068: configureTestElement(ce);
069: ce.setProperty(HTTPSamplerBase.MIMETYPE, mimetypeField
070: .getText());
071: ce.setProperty(HTTPSamplerBase.FILE_NAME, filenameField
072: .getText());
073: ce.setProperty(HTTPSamplerBase.FILE_FIELD, paramNameField
074: .getText());
075: return ce;
076: }
077:
078: // does not appear to be used
079: // public void configureSampler(HTTPSamplerBase sampler)
080: // {
081: // sampler.setMimetype(mimetypeField.getText());
082: // sampler.setFileField(paramNameField.getText());
083: // sampler.setFilename(filenameField.getText());
084: // super.configureSampler(sampler);
085: // }
086:
087: public void configure(TestElement el) {
088: super .configure(el);
089: mimetypeField.setText(el
090: .getPropertyAsString(HTTPSamplerBase.MIMETYPE));
091: filenameField.setText(el
092: .getPropertyAsString(HTTPSamplerBase.FILE_NAME));
093: paramNameField.setText(el
094: .getPropertyAsString(HTTPSamplerBase.FILE_FIELD));
095: }
096:
097: public String getLabelResource() {
098: return "url_multipart_config_title"; // $NON-NLS-1$
099: }
100:
101: public void updateGui() {
102: }
103:
104: public void actionPerformed(ActionEvent e) {
105: String name = e.getActionCommand();
106:
107: if (name.equals(BROWSE)) {
108: JFileChooser chooser = FileDialoger.promptToOpenFile();
109:
110: if (chooser == null) {
111: return;
112: }
113: File file = chooser.getSelectedFile();
114:
115: if (file != null) {
116: filenameField.setText(file.getPath());
117: }
118: }
119: }
120:
121: protected void init() {
122: this .setLayout(new BorderLayout());
123:
124: // WEB SERVER PANEL
125: VerticalPanel webServerPanel = new VerticalPanel();
126: webServerPanel.setBorder(BorderFactory.createTitledBorder(
127: BorderFactory.createEtchedBorder(), JMeterUtils
128: .getResString("web_server"))); // $NON-NLS-1$
129: final JPanel domainPanel = getDomainPanel();
130: final JPanel portPanel = getPortPanel();
131: domainPanel.add(portPanel, BorderLayout.EAST);
132: webServerPanel.add(domainPanel);
133: //webServerPanel.add(getPortPanel());
134:
135: JPanel northPanel = new JPanel();
136: northPanel
137: .setLayout(new BoxLayout(northPanel, BoxLayout.Y_AXIS));
138: northPanel.add(getProtocolAndMethodPanel());
139: northPanel.add(getPathPanel());
140:
141: // WEB REQUEST PANEL
142: JPanel webRequestPanel = new JPanel();
143: webRequestPanel.setLayout(new BorderLayout());
144: webRequestPanel.setBorder(BorderFactory.createTitledBorder(
145: BorderFactory.createEtchedBorder(), JMeterUtils
146: .getResString("web_request"))); // $NON-NLS-1$
147:
148: webRequestPanel.add(northPanel, BorderLayout.NORTH);
149: webRequestPanel.add(getParameterPanel(), BorderLayout.CENTER);
150: webRequestPanel.add(getFilePanel(), BorderLayout.SOUTH);
151:
152: this .add(webServerPanel, BorderLayout.NORTH);
153: this .add(webRequestPanel, BorderLayout.CENTER);
154: }
155:
156: protected JPanel getFilePanel() {
157: JPanel filePanel = new VerticalPanel();
158: filePanel.setBorder(BorderFactory.createTitledBorder(
159: BorderFactory.createEtchedBorder(), JMeterUtils
160: .getResString("send_file"))); // $NON-NLS-1$
161:
162: filePanel.add(createFilenamePanel());
163: filePanel.add(createFileParamNamePanel());
164: filePanel.add(createFileMimeTypePanel());
165:
166: return filePanel;
167: }
168:
169: private JPanel createFileMimeTypePanel() {
170: mimetypeField = new JTextField(15);
171: mimetypeField.setName(MIMETYPE);
172:
173: JLabel mimetypeLabel = new JLabel(JMeterUtils
174: .getResString("send_file_mime_label")); // $NON-NLS-1$
175: mimetypeLabel.setLabelFor(mimetypeField);
176: JPanel mimePanel = new JPanel(new BorderLayout(5, 0));
177: mimePanel.add(mimetypeLabel, BorderLayout.WEST);
178: mimePanel.add(mimetypeField, BorderLayout.CENTER);
179: return mimePanel;
180: }
181:
182: private JPanel createFileParamNamePanel() {
183: paramNameField = new JTextField(15);
184: paramNameField.setName(PARAMNAME);
185:
186: JLabel paramNameLabel = new JLabel(JMeterUtils
187: .getResString("send_file_param_name_label")); // $NON-NLS-1$
188: paramNameLabel.setLabelFor(paramNameField);
189:
190: JPanel paramNamePanel = new JPanel(new BorderLayout(5, 0));
191: paramNamePanel.add(paramNameLabel, BorderLayout.WEST);
192: paramNamePanel.add(paramNameField, BorderLayout.CENTER);
193: return paramNamePanel;
194: }
195:
196: private JPanel createFilenamePanel() {
197: filenameField = new JTextField(15);
198: filenameField.setName(FILENAME);
199:
200: JLabel filenameLabel = new JLabel(JMeterUtils
201: .getResString("send_file_filename_label")); // $NON-NLS-1$
202: filenameLabel.setLabelFor(filenameField);
203:
204: JButton browseFileButton = new JButton(JMeterUtils
205: .getResString("send_file_browse")); // $NON-NLS-1$
206: browseFileButton.setActionCommand(BROWSE);
207: browseFileButton.addActionListener(this );
208:
209: JPanel filenamePanel = new JPanel(new BorderLayout(5, 0));
210: filenamePanel.add(filenameLabel, BorderLayout.WEST);
211: filenamePanel.add(filenameField, BorderLayout.CENTER);
212: filenamePanel.add(browseFileButton, BorderLayout.EAST);
213: return filenamePanel;
214: }
215:
216: /*
217: * (non-Javadoc)
218: *
219: * @see org.apache.jmeter.protocol.http.config.gui.UrlConfigGui#clear()
220: */
221: public void clear() {
222: // TODO Auto-generated method stub
223: super .clear();
224: filenameField.setText(""); // $NON-NLS-1$
225: mimetypeField.setText(""); // $NON-NLS-1$
226: paramNameField.setText(""); // $NON-NLS-1$
227: }
228: }
|