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.assertions.gui;
020:
021: import java.awt.BorderLayout;
022:
023: import javax.swing.BorderFactory;
024: import javax.swing.JPanel;
025:
026: import org.apache.jmeter.assertions.XPathAssertion;
027: import org.apache.jmeter.testelement.TestElement;
028: import org.apache.jmeter.util.JMeterUtils;
029: import org.apache.jorphan.gui.layout.VerticalLayout;
030:
031: public class XPathAssertionGui extends AbstractAssertionGui {
032:
033: private XPathPanel xpath;
034:
035: private XMLConfPanel xml;
036:
037: public XPathAssertionGui() {
038: init();
039: }
040:
041: /**
042: * Returns the label to be shown within the JTree-Component.
043: */
044: public String getLabelResource() {
045: return "xpath_assertion_title"; //$NON-NLS-1$
046: }
047:
048: /**
049: * Create test element
050: */
051: public TestElement createTestElement() {
052: XPathAssertion el = new XPathAssertion();
053: modifyTestElement(el);
054: return el;
055: }
056:
057: public String getXPathAttributesTitle() {
058: return JMeterUtils.getResString("xpath_assertion_test"); //$NON-NLS-1$
059: }
060:
061: public void configure(TestElement el) {
062: super .configure(el);
063: XPathAssertion assertion = (XPathAssertion) el;
064: xpath.setXPath(assertion.getXPathString());
065: xpath.setNegated(assertion.isNegated());
066:
067: xml.setWhitespace(assertion.isWhitespace());
068: xml.setValidate(assertion.isValidating());
069: xml.setTolerant(assertion.isTolerant());
070: xml.setNamespace(assertion.isNamespace());
071:
072: }
073:
074: private void init() {
075: setLayout(new VerticalLayout(5, VerticalLayout.BOTH,
076: VerticalLayout.TOP));
077: setBorder(makeBorder());
078:
079: add(makeTitlePanel());
080:
081: // USER_INPUT
082: JPanel sizePanel = new JPanel(new BorderLayout());
083: sizePanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10,
084: 10));
085: sizePanel.setBorder(BorderFactory.createTitledBorder(
086: BorderFactory.createEtchedBorder(),
087: getXPathAttributesTitle()));
088: xpath = new XPathPanel();
089: sizePanel.add(xpath);
090:
091: xml = new XMLConfPanel();
092: xml.setBorder(BorderFactory.createTitledBorder(BorderFactory
093: .createEtchedBorder(), JMeterUtils
094: .getResString("xpath_assertion_option"))); //$NON-NLS-1$
095: add(xml);
096:
097: add(sizePanel);
098: }
099:
100: /**
101: * Modifies a given TestElement to mirror the data in the gui components.
102: *
103: * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
104: */
105: public void modifyTestElement(TestElement el) {
106: super .configureTestElement(el);
107: if (el instanceof XPathAssertion) {
108: XPathAssertion assertion = (XPathAssertion) el;
109: assertion.setValidating(xml.isValidate());
110: assertion.setWhitespace(xml.isWhitespace());
111: assertion.setTolerant(xml.isTolerant());
112: assertion.setNamespace(xml.isNamespace());
113: assertion.setNegated(xpath.isNegated());
114: assertion.setXPathString(xpath.getXPath());
115: }
116: }
117:
118: /**
119: * Implements JMeterGUIComponent.clearGui
120: */
121: public void clearGui() {
122: super .clearGui();
123:
124: xpath.setXPath("/"); //$NON-NLS-1$
125: xpath.setNegated(false);
126:
127: xml.setDefaultValues();
128: }
129: }
|