|
JMeter example source code file (HTTPFileArgsPanel.java)
The JMeter HTTPFileArgsPanel.java source code
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.jmeter.protocol.http.gui;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Iterator;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.TableCellEditor;
import org.apache.jmeter.gui.util.FileDialoger;
import org.apache.jmeter.gui.util.HeaderAsPropertyRenderer;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
import org.apache.jmeter.protocol.http.util.HTTPFileArg;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.gui.GuiUtils;
import org.apache.jorphan.gui.ObjectTableModel;
import org.apache.jorphan.reflect.Functor;
/*
* Note: this class is currently only suitable for use with HTTSamplerBase.
* If it is required for other classes, then the appropriate configure() and modifyTestElement()
* method code needs to be written.
*/
/**
* A GUI panel allowing the user to enter file information for http upload.
* Used by MultipartUrlConfigGui for use in HTTP Samplers.
*/
public class HTTPFileArgsPanel extends JPanel implements ActionListener {
private static final long serialVersionUID = 240L;
/** The title label for this component. */
private JLabel tableLabel;
/** The table containing the list of files. */
private transient JTable table;
/** The model for the files table. */
private transient ObjectTableModel tableModel; // only contains HTTPFileArg elements
/** A button for adding new files to the table. */
private JButton add;
/** A button for browsing file system to set path of selected row in table. */
private JButton browse;
/** A button for removing files from the table. */
private JButton delete;
/** Command for adding a row to the table. */
private static final String ADD = "add"; // $NON-NLS-1$
/** Command for browsing filesystem to set path of selected row in table. */
private static final String BROWSE = "browse"; // $NON-NLS-1$
/** Command for removing a row from the table. */
private static final String DELETE = "delete"; // $NON-NLS-1$
private static final String FILEPATH = "send_file_filename_label"; // $NON-NLS-1$
/** The parameter name column title of file table. */
private static final String PARAMNAME = "send_file_param_name_label"; //$NON-NLS-1$
/** The mime type column title of file table. */
private static final String MIMETYPE = "send_file_mime_label"; //$NON-NLS-1$
public HTTPFileArgsPanel() {
this(""); // required for unit tests
}
/**
* Create a new HTTPFileArgsPanel as an embedded component, using the
* specified title.
*
* @param label
* the title for the component.
*/
public HTTPFileArgsPanel(String label) {
tableLabel = new JLabel(label);
init();
}
/**
* Initialize the table model used for the http files table.
*/
private void initializeTableModel() {
tableModel = new ObjectTableModel(new String[] {
FILEPATH, PARAMNAME, MIMETYPE},
HTTPFileArg.class,
new Functor[] {
new Functor("getPath"), //$NON-NLS-1$
new Functor("getParamName"), //$NON-NLS-1$
new Functor("getMimeType")}, //$NON-NLS-1$
new Functor[] {
new Functor("setPath"), //$NON-NLS-1$
new Functor("setParamName"), //$NON-NLS-1$
new Functor("setMimeType")}, //$NON-NLS-1$
new Class[] {String.class, String.class, String.class});
}
public static boolean testFunctors(){
HTTPFileArgsPanel instance = new HTTPFileArgsPanel(""); //$NON-NLS-1$
instance.initializeTableModel();
return instance.tableModel.checkFunctors(null,instance.getClass());
}
/**
* Resize the table columns to appropriate widths.
*
* @param table
* the table to resize columns for
*/
private void sizeColumns(JTable table) {
GuiUtils.fixSize(table.getColumn(PARAMNAME), table);
GuiUtils.fixSize(table.getColumn(MIMETYPE), table);
}
/**
* Save the GUI data in the HTTPSamplerBase element.
*
* @param testElement
*/
public void modifyTestElement(TestElement testElement) {
stopTableEditing();
if (testElement instanceof HTTPSamplerBase) {
HTTPSamplerBase base = (HTTPSamplerBase) testElement;
int rows = tableModel.getRowCount();
@SuppressWarnings("unchecked") // we only put HTTPFileArgs in it
Iterator<HTTPFileArg> modelData = (Iterator
Other JMeter examples (source code examples)Here is a short list of links related to this JMeter HTTPFileArgsPanel.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.