KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > protocol > http > gui > HTTPArgumentsPanel


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/gui/HTTPArgumentsPanel.java,v 1.14.2.2 2004/10/11 00:51:58 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * 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.http.gui;
20
21 import java.util.Iterator JavaDoc;
22
23 import javax.swing.JTable JavaDoc;
24 import javax.swing.table.TableColumn JavaDoc;
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     /* NOTUSED
37     private static final String ENCODED_VALUE =
38         JMeterUtils.getResString("encoded_value");
39         */

40     private static final String JavaDoc ENCODE_OR_NOT =
41         JMeterUtils.getResString("encode?");
42     private static final String JavaDoc INCLUDE_EQUALS =
43         JMeterUtils.getResString("include_equals");
44
45     protected void initializeTableModel()
46     {
47         tableModel =
48             new ObjectTableModel(
49                 new String JavaDoc[] {
50                     ArgumentsPanel.COLUMN_NAMES[0],
51                     ArgumentsPanel.COLUMN_NAMES[1],
52                     ENCODE_OR_NOT,
53                     INCLUDE_EQUALS },
54                 new String JavaDoc[] { "name", "value", "alwaysEncoded", "useEquals" },
55                 new Class JavaDoc[] {
56                     String JavaDoc.class,
57                     String JavaDoc.class,
58                     boolean.class,
59                     boolean.class },
60                 new Class JavaDoc[] {
61                     String JavaDoc.class,
62                     String JavaDoc.class,
63                     Boolean JavaDoc.class,
64                     Boolean JavaDoc.class },
65                 new HTTPArgument());
66     }
67
68     protected void sizeColumns(JTable JavaDoc 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 JavaDoc 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 JavaDoc column)
86     {
87         column.sizeWidthToFit();
88         //column.setMinWidth(column.getWidth());
89
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 JavaDoc 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