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.control.gui;
020:
021: import java.awt.BorderLayout;
022: import java.awt.Dimension;
023:
024: import javax.swing.BorderFactory;
025: import javax.swing.JCheckBox;
026: import javax.swing.JPanel;
027: import org.apache.jmeter.gui.util.HorizontalPanel;
028: import org.apache.jmeter.gui.util.VerticalPanel;
029: import org.apache.jmeter.protocol.http.config.gui.MultipartUrlConfigGui;
030: import org.apache.jmeter.protocol.http.config.gui.UrlConfigGui;
031: import org.apache.jmeter.protocol.http.sampler.HTTPSamplerFactory;
032: import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
033: import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
034: import org.apache.jmeter.testelement.TestElement;
035: import org.apache.jmeter.util.JMeterUtils;
036: import org.apache.jorphan.gui.JLabeledTextField;
037:
038: //For unit tests, @see TestHttpTestSampleGui
039:
040: /**
041: * HTTP Sampler GUI
042: *
043: */
044: public class HttpTestSampleGui extends AbstractSamplerGui {
045: private UrlConfigGui urlConfigGui;
046:
047: private JCheckBox getImages;
048:
049: private JCheckBox isMon;
050:
051: private JLabeledTextField embeddedRE; // regular expression used to match against embedded resource URLs
052:
053: public HttpTestSampleGui() {
054: init();
055: }
056:
057: public void configure(TestElement element) {
058: super .configure(element);
059: urlConfigGui.configure(element);
060: final HTTPSamplerBase samplerBase = (HTTPSamplerBase) element;
061: getImages.setSelected(samplerBase.isImageParser());
062: isMon.setSelected(samplerBase.isMonitor());
063: embeddedRE.setText(samplerBase.getEmbeddedUrlRE());
064: }
065:
066: public TestElement createTestElement() {
067: HTTPSamplerBase sampler = HTTPSamplerFactory.newInstance();// create default sampler
068: modifyTestElement(sampler);
069: return sampler;
070: }
071:
072: /**
073: * Modifies a given TestElement to mirror the data in the gui components.
074: *
075: * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
076: */
077: public void modifyTestElement(TestElement sampler) {
078: TestElement el = urlConfigGui.createTestElement();
079: sampler.clear();
080: sampler.addTestElement(el);
081: final HTTPSamplerBase samplerBase = (HTTPSamplerBase) sampler;
082: if (getImages.isSelected()) {
083: samplerBase.setImageParser(true);
084: } else {
085: // The default is false, so we can remove the property to simplify JMX files
086: // This also allows HTTPDefaults to work for this checkbox
087: sampler.removeProperty(HTTPSamplerBase.IMAGE_PARSER);
088: }
089: samplerBase.setMonitor(isMon.isSelected());
090: samplerBase.setEmbeddedUrlRE(embeddedRE.getText());
091: this .configureTestElement(sampler);
092: }
093:
094: public String getLabelResource() {
095: return "web_testing_title"; // $NON-NLS-1$
096: }
097:
098: protected void init() {
099: setLayout(new BorderLayout(0, 5));
100: setBorder(makeBorder());
101:
102: add(makeTitlePanel(), BorderLayout.NORTH);
103:
104: // URL CONFIG
105: urlConfigGui = new MultipartUrlConfigGui();
106: add(urlConfigGui, BorderLayout.CENTER);
107:
108: // OPTIONAL TASKS
109: add(createOptionalTasksPanel(), BorderLayout.SOUTH);
110: }
111:
112: private JPanel createOptionalTasksPanel() {
113: // OPTIONAL TASKS
114: JPanel optionalTasksPanel = new VerticalPanel();
115: optionalTasksPanel.setBorder(BorderFactory.createTitledBorder(
116: BorderFactory.createEtchedBorder(), JMeterUtils
117: .getResString("optional_tasks"))); // $NON-NLS-1$
118:
119: JPanel checkBoxPanel = new HorizontalPanel();
120: // RETRIEVE IMAGES
121: getImages = new JCheckBox(JMeterUtils
122: .getResString("web_testing_retrieve_images")); // $NON-NLS-1$
123: // Is monitor
124: isMon = new JCheckBox(JMeterUtils
125: .getResString("monitor_is_title")); // $NON-NLS-1$
126: checkBoxPanel.add(getImages);
127: checkBoxPanel.add(isMon);
128: optionalTasksPanel.add(checkBoxPanel);
129: // Embedded URL match regex
130: embeddedRE = new JLabeledTextField(JMeterUtils
131: .getResString("web_testing_embedded_url_pattern"), 30); // $NON-NLS-1$
132: optionalTasksPanel.add(embeddedRE);
133: return optionalTasksPanel;
134: }
135:
136: public Dimension getPreferredSize() {
137: return getMinimumSize();
138: }
139:
140: /*
141: * (non-Javadoc)
142: *
143: * @see org.apache.jmeter.gui.JMeterGUIComponent#clearGui()
144: */
145: public void clearGui() {
146: super .clearGui();
147: getImages.setSelected(false);
148: isMon.setSelected(false);
149: urlConfigGui.clear();
150: embeddedRE.setText(""); // $NON-NLS-1$
151: }
152: }
|