1 18 19 package org.apache.jmeter.protocol.http.gui; 20 21 import java.util.Iterator ; 22 23 import javax.swing.JTable ; 24 import javax.swing.table.TableColumn ; 25 26 import org.apache.jmeter.config.Arguments; 27 import org.apache.jmeter.config.gui.ArgumentsPanel; 28 import org.apache.jmeter.protocol.http.util.HTTPArgument; 29 import org.apache.jmeter.testelement.TestElement; 30 import org.apache.jmeter.testelement.property.PropertyIterator; 31 import org.apache.jmeter.util.JMeterUtils; 32 import org.apache.jorphan.gui.ObjectTableModel; 33 34 public class HTTPArgumentsPanel extends ArgumentsPanel 35 { 36 40 private static final String ENCODE_OR_NOT = 41 JMeterUtils.getResString("encode?"); 42 private static final String INCLUDE_EQUALS = 43 JMeterUtils.getResString("include_equals"); 44 45 protected void initializeTableModel() 46 { 47 tableModel = 48 new ObjectTableModel( 49 new String [] { 50 ArgumentsPanel.COLUMN_NAMES[0], 51 ArgumentsPanel.COLUMN_NAMES[1], 52 ENCODE_OR_NOT, 53 INCLUDE_EQUALS }, 54 new String [] { "name", "value", "alwaysEncoded", "useEquals" }, 55 new Class [] { 56 String .class, 57 String .class, 58 boolean.class, 59 boolean.class }, 60 new Class [] { 61 String .class, 62 String .class, 63 Boolean .class, 64 Boolean .class }, 65 new HTTPArgument()); 66 } 67 68 protected void sizeColumns(JTable table) 69 { 70 int resizeMode = table.getAutoResizeMode(); 71 table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 72 fixSize(table.getColumn(INCLUDE_EQUALS)); 73 fixSize(table.getColumn(ENCODE_OR_NOT)); 74 table.setAutoResizeMode(resizeMode); 75 } 76 77 protected Object makeNewArgument() 78 { 79 HTTPArgument arg = new HTTPArgument("", ""); 80 arg.setAlwaysEncoded(false); 81 arg.setUseEquals(true); 82 return arg; 83 } 84 85 private void fixSize(TableColumn column) 86 { 87 column.sizeWidthToFit(); 88 column.setMaxWidth((int) (column.getWidth() * 1.5)); 90 column.setWidth(column.getMaxWidth()); 91 column.setResizable(false); 92 } 93 94 public HTTPArgumentsPanel() 95 { 96 super(JMeterUtils.getResString("paramtable")); 97 } 98 99 public TestElement createTestElement() 100 { 101 stopTableEditing(); 102 Iterator modelData = tableModel.iterator(); 103 Arguments args = new Arguments(); 104 while (modelData.hasNext()) 105 { 106 HTTPArgument arg = (HTTPArgument) modelData.next(); 107 args.addArgument(arg); 108 } 109 this.configureTestElement(args); 110 return (TestElement) args.clone(); 111 } 112 113 public void configure(TestElement el) 114 { 115 super.configure(el); 116 if (el instanceof Arguments) 117 { 118 tableModel.clearData(); 119 HTTPArgument.convertArgumentsToHTTP((Arguments) el); 120 PropertyIterator iter = ((Arguments) el).getArguments().iterator(); 121 while (iter.hasNext()) 122 { 123 HTTPArgument arg = (HTTPArgument) iter.next().getObjectValue(); 124 tableModel.addRow(arg); 125 } 126 } 127 checkDeleteStatus(); 128 } 129 130 protected boolean isMetaDataNormal(HTTPArgument arg) 131 { 132 return arg.getMetaData() == null 133 || arg.getMetaData().equals("=") 134 || (arg.getValue() != null && 135 arg.getValue().length() > 0); 136 } 137 } 138 | Popular Tags |