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.gui;
020:
021: import java.util.Iterator;
022:
023: import javax.swing.JTable;
024: import javax.swing.table.TableColumn;
025:
026: import org.apache.jmeter.config.Arguments;
027: import org.apache.jmeter.config.gui.ArgumentsPanel;
028: import org.apache.jmeter.protocol.http.util.HTTPArgument;
029: import org.apache.jmeter.testelement.TestElement;
030: import org.apache.jmeter.testelement.property.PropertyIterator;
031: import org.apache.jmeter.util.JMeterUtils;
032: import org.apache.jorphan.gui.ObjectTableModel;
033: import org.apache.jorphan.reflect.Functor;
034:
035: public class HTTPArgumentsPanel extends ArgumentsPanel {
036:
037: private static final String ENCODE_OR_NOT = JMeterUtils
038: .getResString("encode?"); //$NON-NLS-1$
039:
040: private static final String INCLUDE_EQUALS = JMeterUtils
041: .getResString("include_equals"); //$NON-NLS-1$
042:
043: protected void initializeTableModel() {
044: tableModel = new ObjectTableModel(new String[] {
045: ArgumentsPanel.COLUMN_NAMES_0,
046: ArgumentsPanel.COLUMN_NAMES_1, ENCODE_OR_NOT,
047: INCLUDE_EQUALS }, HTTPArgument.class, new Functor[] {
048: new Functor("getName"), //$NON-NLS-1$
049: new Functor("getValue"), //$NON-NLS-1$
050: new Functor("isAlwaysEncoded"), //$NON-NLS-1$
051: new Functor("isUseEquals") }, //$NON-NLS-1$
052: new Functor[] { new Functor("setName"), //$NON-NLS-1$
053: new Functor("setValue"), //$NON-NLS-1$
054: new Functor("setAlwaysEncoded"), //$NON-NLS-1$
055: new Functor("setUseEquals") }, //$NON-NLS-1$
056: new Class[] { String.class, String.class,
057: Boolean.class, Boolean.class });
058: }
059:
060: public static boolean testFunctors() {
061: HTTPArgumentsPanel instance = new HTTPArgumentsPanel();
062: instance.initializeTableModel();
063: return instance.tableModel.checkFunctors(null, instance
064: .getClass());
065: }
066:
067: protected void sizeColumns(JTable table) {
068: int resizeMode = table.getAutoResizeMode();
069: table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
070: fixSize(table.getColumn(INCLUDE_EQUALS));
071: fixSize(table.getColumn(ENCODE_OR_NOT));
072: table.setAutoResizeMode(resizeMode);
073: }
074:
075: protected Object makeNewArgument() {
076: HTTPArgument arg = new HTTPArgument("", "");
077: arg.setAlwaysEncoded(false);
078: arg.setUseEquals(true);
079: return arg;
080: }
081:
082: private void fixSize(TableColumn column) {
083: column.sizeWidthToFit();
084: // column.setMinWidth(column.getWidth());
085: column.setMaxWidth((int) (column.getWidth() * 1.5));
086: column.setWidth(column.getMaxWidth());
087: column.setResizable(false);
088: }
089:
090: public HTTPArgumentsPanel() {
091: super (JMeterUtils.getResString("paramtable")); //$NON-NLS-1$
092: }
093:
094: public TestElement createTestElement() {
095: stopTableEditing();
096: Iterator modelData = tableModel.iterator();
097: Arguments args = new Arguments();
098: while (modelData.hasNext()) {
099: HTTPArgument arg = (HTTPArgument) modelData.next();
100: args.addArgument(arg);
101: }
102: this .configureTestElement(args);
103: return (TestElement) args.clone();
104: }
105:
106: public void configure(TestElement el) {
107: super .configure(el);
108: if (el instanceof Arguments) {
109: tableModel.clearData();
110: HTTPArgument.convertArgumentsToHTTP((Arguments) el);
111: PropertyIterator iter = ((Arguments) el).getArguments()
112: .iterator();
113: while (iter.hasNext()) {
114: HTTPArgument arg = (HTTPArgument) iter.next()
115: .getObjectValue();
116: tableModel.addRow(arg);
117: }
118: }
119: checkDeleteStatus();
120: }
121:
122: protected boolean isMetaDataNormal(HTTPArgument arg) {
123: return arg.getMetaData() == null
124: || arg.getMetaData().equals("=")
125: || (arg.getValue() != null && arg.getValue().length() > 0);
126: }
127: }
|