0001: /*
0002: * soapUI, copyright (C) 2004-2007 eviware.com
0003: *
0004: * soapUI is free software; you can redistribute it and/or modify it under the
0005: * terms of version 2.1 of the GNU Lesser General Public License as published by
0006: * the Free Software Foundation.
0007: *
0008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
0009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0010: * See the GNU Lesser General Public License for more details at gnu.org.
0011: */
0012:
0013: package com.eviware.soapui.impl.wsdl.panels.teststeps;
0014:
0015: import java.awt.BorderLayout;
0016: import java.awt.Dimension;
0017: import java.awt.GridLayout;
0018: import java.awt.event.ActionEvent;
0019: import java.awt.event.ItemEvent;
0020: import java.awt.event.ItemListener;
0021: import java.beans.PropertyChangeEvent;
0022: import java.beans.PropertyChangeListener;
0023: import java.util.ArrayList;
0024: import java.util.List;
0025:
0026: import javax.swing.AbstractAction;
0027: import javax.swing.Action;
0028: import javax.swing.BorderFactory;
0029: import javax.swing.DefaultComboBoxModel;
0030: import javax.swing.DefaultListModel;
0031: import javax.swing.Icon;
0032: import javax.swing.JButton;
0033: import javax.swing.JCheckBox;
0034: import javax.swing.JComboBox;
0035: import javax.swing.JComponent;
0036: import javax.swing.JLabel;
0037: import javax.swing.JList;
0038: import javax.swing.JPanel;
0039: import javax.swing.JScrollPane;
0040: import javax.swing.JSplitPane;
0041: import javax.swing.JTextArea;
0042: import javax.swing.ListSelectionModel;
0043: import javax.swing.event.ChangeEvent;
0044: import javax.swing.event.ChangeListener;
0045: import javax.swing.event.ListSelectionEvent;
0046: import javax.swing.event.ListSelectionListener;
0047: import javax.swing.text.Document;
0048:
0049: import com.eviware.soapui.SoapUI;
0050: import com.eviware.soapui.impl.wsdl.actions.support.ShowOnlineHelpAction;
0051: import com.eviware.soapui.impl.wsdl.panels.support.TestRunComponentEnabler;
0052: import com.eviware.soapui.impl.wsdl.support.HelpUrls;
0053: import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext;
0054: import com.eviware.soapui.impl.wsdl.teststeps.PropertyTransfer;
0055: import com.eviware.soapui.impl.wsdl.teststeps.TransferResponseValuesTestStep;
0056: import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest;
0057: import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep;
0058: import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
0059: import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStepListener;
0060: import com.eviware.soapui.impl.wsdl.teststeps.TransferResponseValuesTestStep.ValueTransferResult;
0061: import com.eviware.soapui.impl.wsdl.teststeps.actions.ShowTransferValuesResultsAction;
0062: import com.eviware.soapui.model.ModelItem;
0063: import com.eviware.soapui.model.support.TestSuiteListenerAdapter;
0064: import com.eviware.soapui.model.testsuite.TestStep;
0065: import com.eviware.soapui.model.testsuite.TestStepProperty;
0066: import com.eviware.soapui.support.DocumentListenerAdapter;
0067: import com.eviware.soapui.support.UISupport;
0068: import com.eviware.soapui.support.components.JUndoableTextArea;
0069: import com.eviware.soapui.support.components.JXToolBar;
0070: import com.eviware.soapui.support.xml.XmlUtils;
0071: import com.eviware.soapui.ui.desktop.DesktopPanel;
0072:
0073: /**
0074: * DesktopPanel for TransferResponseValuesTestStep
0075: *
0076: * @author Ole.Matzura
0077: */
0078:
0079: public class TransferResponseValuesDesktopPanel extends JPanel
0080: implements DesktopPanel {
0081: private final TransferResponseValuesTestStep transferStep;
0082: private DefaultListModel listModel;
0083: private JList transferList;
0084: private JTextArea sourceArea;
0085: private JTextArea targetArea;
0086: private JButton copyButton;
0087: private JButton deleteButton;
0088: private JButton declareButton;
0089: private JComboBox sourcePropertyCombo;
0090: private JComboBox targetPropertyCombo;
0091: private JComboBox sourceStepCombo;
0092: private JComboBox targetStepCombo;
0093: private DefaultComboBoxModel sourceStepModel;
0094: private DefaultComboBoxModel targetStepModel;
0095: private TestStepNameListener sourceTestStepNameListener;
0096: private TestStepNameListener targetStepNameListener;
0097: private TestStepPropertiesListener sourceStepPropertiesListener;
0098: private TestStepPropertiesListener targetStepPropertiesListener;
0099: private TransferPropertyChangeListener transferPropertyChangeListener = new TransferPropertyChangeListener();
0100: private boolean selecting;
0101: private InternalTestSuiteListener testSuiteListener;
0102: private TestRunComponentEnabler componentEnabler;
0103: private JCheckBox failTransferCheckBox;
0104: private JButton runButton;
0105: private JButton renameButton;
0106: private JCheckBox setNullCheckBox;
0107: private JCheckBox transferTextContentCheckBox;
0108: private JCheckBox ignoreEmptyCheckBox;
0109: private JCheckBox transferAllCheckBox;
0110: private DesktopPanel resultDesktopPanel;
0111:
0112: public TransferResponseValuesDesktopPanel(
0113: TransferResponseValuesTestStep testStep) {
0114: super (new BorderLayout());
0115: this .transferStep = testStep;
0116: componentEnabler = new TestRunComponentEnabler(testStep
0117: .getTestCase());
0118:
0119: buildUI();
0120:
0121: testSuiteListener = new InternalTestSuiteListener();
0122: transferStep.getTestCase().getTestSuite().addTestSuiteListener(
0123: testSuiteListener);
0124: }
0125:
0126: protected void buildUI() {
0127: JSplitPane splitPane = UISupport.createHorizontalSplit();
0128:
0129: listModel = new DefaultListModel();
0130:
0131: for (int c = 0; c < transferStep.getTransferCount(); c++) {
0132: listModel.addElement(transferStep.getTransferAt(c)
0133: .getName());
0134: }
0135:
0136: transferList = new JList(listModel);
0137: transferList
0138: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
0139: transferList
0140: .addListSelectionListener(new TransferListSelectionListener());
0141: componentEnabler.add(transferList);
0142:
0143: JScrollPane listScrollPane = new JScrollPane(transferList);
0144: listScrollPane.setBorder(BorderFactory.createCompoundBorder(
0145: BorderFactory.createTitledBorder(BorderFactory
0146: .createEmptyBorder(), "Transfers"),
0147: BorderFactory.createEmptyBorder()));
0148:
0149: splitPane.setLeftComponent(listScrollPane);
0150:
0151: JSplitPane innerSplit = UISupport.createVerticalSplit();
0152: innerSplit.setBorder(null);
0153: sourceArea = new JUndoableTextArea();
0154: sourceArea
0155: .setToolTipText("XPath selection from source property");
0156: sourceArea.setEnabled(false);
0157: sourceArea.getDocument().addDocumentListener(
0158: new SourceAreaDocumentListener());
0159: componentEnabler.add(sourceArea);
0160:
0161: targetArea = new JUndoableTextArea();
0162: targetArea.setToolTipText("XPath target in target property");
0163: targetArea.setEnabled(false);
0164: targetArea.getDocument().addDocumentListener(
0165: new TargetAreaDocumentListener());
0166: componentEnabler.add(targetArea);
0167:
0168: JPanel sourcePanel = new JPanel(new BorderLayout());
0169: sourcePanel.add(new JScrollPane(sourceArea),
0170: BorderLayout.CENTER);
0171: JXToolBar toolbar = createSourceToolbar();
0172: sourcePanel.add(toolbar, BorderLayout.NORTH);
0173: sourcePanel.setBorder(BorderFactory.createEmptyBorder(0, 3, 3,
0174: 3));
0175:
0176: innerSplit.setTopComponent(sourcePanel);
0177:
0178: JPanel targetPanel = new JPanel(new BorderLayout());
0179: targetPanel.add(new JScrollPane(targetArea),
0180: BorderLayout.CENTER);
0181: toolbar = createTargetToolbar();
0182: targetPanel.add(toolbar, BorderLayout.NORTH);
0183: targetPanel.setBorder(BorderFactory.createEmptyBorder(0, 3, 3,
0184: 3));
0185:
0186: innerSplit.setBottomComponent(targetPanel);
0187:
0188: innerSplit.setResizeWeight(0.5);
0189: innerSplit.setDividerLocation(0.5);
0190:
0191: JPanel panel = createTransferOptions();
0192:
0193: JPanel innerPanel = new JPanel(new BorderLayout());
0194: innerPanel.add(innerSplit, BorderLayout.CENTER);
0195: innerPanel.add(panel, BorderLayout.SOUTH);
0196:
0197: splitPane.setRightComponent(innerPanel);
0198: splitPane.setResizeWeight(0.1);
0199: splitPane.setDividerLocation(120);
0200:
0201: add(splitPane, BorderLayout.CENTER);
0202: add(createButtonBar(), BorderLayout.NORTH);
0203:
0204: setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
0205: setPreferredSize(new Dimension(550, 400));
0206:
0207: if (listModel.getSize() > 0)
0208: transferList.setSelectedIndex(0);
0209:
0210: componentEnabler.add(deleteButton);
0211: componentEnabler.add(declareButton);
0212: componentEnabler.add(runButton);
0213: componentEnabler.add(copyButton);
0214: componentEnabler.add(renameButton);
0215: componentEnabler.add(failTransferCheckBox);
0216: componentEnabler.add(setNullCheckBox);
0217: componentEnabler.add(transferTextContentCheckBox);
0218: componentEnabler.add(ignoreEmptyCheckBox);
0219: componentEnabler.add(transferAllCheckBox);
0220: }
0221:
0222: protected JXToolBar createButtonBar() {
0223: JXToolBar builder = UISupport.createToolbar();
0224: builder.addFixed(new JButton(new AddAction()));
0225: builder.addRelatedGap();
0226: copyButton = new JButton(new CopyAction());
0227: copyButton.setEnabled(false);
0228: builder.addFixed(copyButton);
0229: builder.addRelatedGap();
0230: renameButton = new JButton(new RenameAction());
0231: renameButton.setEnabled(false);
0232: builder.addFixed(renameButton);
0233: builder.addRelatedGap();
0234: deleteButton = new JButton(new DeleteAction());
0235: deleteButton.setEnabled(false);
0236: builder.addFixed(deleteButton);
0237: builder.addRelatedGap();
0238: declareButton = new JButton(new DeclareNamespacesAction());
0239: declareButton.setEnabled(false);
0240: builder.addFixed(declareButton);
0241: builder.addRelatedGap();
0242: runButton = new JButton(new RunAction());
0243: runButton.setEnabled(transferStep.getTransferCount() > 0);
0244: builder.addFixed(runButton);
0245: builder.addGlue();
0246: // JButton closeButton = new JButton( new CloseAction() );
0247: // builder.addFixed( closeButton);
0248: // builder.addRelatedGap();
0249: builder.addFixed(UISupport
0250: .createToolbarButton(new ShowOnlineHelpAction(
0251: HelpUrls.TRANSFERSTEPEDITOR_HELP_URL)));
0252: return builder;
0253: }
0254:
0255: protected JPanel createTransferOptions() {
0256: JPanel panel = new JPanel(new GridLayout(3, 2));
0257: failTransferCheckBox = new JCheckBox("Fail transfer on error",
0258: false);
0259: failTransferCheckBox
0260: .setToolTipText("Fails the Property Transfer Step if an error occurs");
0261: failTransferCheckBox.addChangeListener(new ChangeListener() {
0262:
0263: public void stateChanged(ChangeEvent e) {
0264: PropertyTransfer currentTransfer = getCurrentTransfer();
0265: if (currentTransfer != null) {
0266: currentTransfer.setFailOnError(failTransferCheckBox
0267: .isSelected());
0268: }
0269: }
0270: });
0271:
0272: setNullCheckBox = new JCheckBox("Set null on missing source",
0273: false);
0274: setNullCheckBox
0275: .setToolTipText("Will set target to null if source is missing or null");
0276: setNullCheckBox.addChangeListener(new ChangeListener() {
0277:
0278: public void stateChanged(ChangeEvent e) {
0279: PropertyTransfer currentTransfer = getCurrentTransfer();
0280: if (currentTransfer != null) {
0281: currentTransfer
0282: .setSetNullOnMissingSource(setNullCheckBox
0283: .isSelected());
0284: }
0285: }
0286: });
0287:
0288: transferTextContentCheckBox = new JCheckBox(
0289: "Transfer text content", false);
0290: transferTextContentCheckBox
0291: .setToolTipText("Will only transfer text content of source/target elements");
0292: transferTextContentCheckBox
0293: .addChangeListener(new ChangeListener() {
0294:
0295: public void stateChanged(ChangeEvent e) {
0296: PropertyTransfer currentTransfer = getCurrentTransfer();
0297: if (currentTransfer != null) {
0298: currentTransfer
0299: .setTransferTextContent(transferTextContentCheckBox
0300: .isSelected());
0301: }
0302: }
0303: });
0304:
0305: ignoreEmptyCheckBox = new JCheckBox(
0306: "Ignore empty/missing values", false);
0307: ignoreEmptyCheckBox
0308: .setToolTipText("Will not transfer empty or missing values");
0309: ignoreEmptyCheckBox.addChangeListener(new ChangeListener() {
0310:
0311: public void stateChanged(ChangeEvent e) {
0312: PropertyTransfer currentTransfer = getCurrentTransfer();
0313: if (currentTransfer != null) {
0314: currentTransfer.setIgnoreEmpty(ignoreEmptyCheckBox
0315: .isSelected());
0316: }
0317: }
0318: });
0319:
0320: transferAllCheckBox = new JCheckBox("Transfer to all", false);
0321: transferAllCheckBox
0322: .setToolTipText("Will transfer to all matching target selections");
0323: transferAllCheckBox.addChangeListener(new ChangeListener() {
0324:
0325: public void stateChanged(ChangeEvent e) {
0326: PropertyTransfer currentTransfer = getCurrentTransfer();
0327: if (currentTransfer != null) {
0328: currentTransfer
0329: .setTransferToAll(transferAllCheckBox
0330: .isSelected());
0331: }
0332: }
0333: });
0334:
0335: panel.add(failTransferCheckBox);
0336: panel.add(setNullCheckBox);
0337: panel.add(transferTextContentCheckBox);
0338: panel.add(ignoreEmptyCheckBox);
0339: panel.add(transferAllCheckBox);
0340: panel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
0341: return panel;
0342: }
0343:
0344: protected JXToolBar createTargetToolbar() {
0345: JXToolBar toolbar;
0346: toolbar = UISupport.createToolbar();
0347: toolbar.addSpace(3);
0348: toolbar.addFixed(new JLabel("<html><b>Target:</b></html>"));
0349: toolbar.addGlue();
0350:
0351: targetStepCombo.setSelectedItem(null);
0352: targetStepCombo
0353: .setToolTipText("The step the value will be transferred to");
0354: targetStepCombo.setEnabled(false);
0355: targetStepCombo.addItemListener(new StepComboItemListener(
0356: targetPropertyCombo, targetStepPropertiesListener));
0357: targetStepCombo.addItemListener(new ItemListener() {
0358:
0359: public void itemStateChanged(ItemEvent e) {
0360: if (e.getStateChange() == ItemEvent.SELECTED
0361: && !selecting) {
0362: String targetStep = (String) targetStepCombo
0363: .getSelectedItem();
0364: PropertyTransfer valueTransfer = getCurrentTransfer();
0365:
0366: if (valueTransfer != null) {
0367: valueTransfer.setTargetStepName(targetStep);
0368: }
0369: }
0370: }
0371: });
0372:
0373: toolbar.addFixed(new JLabel("Step:"));
0374: toolbar.addRelatedGap();
0375: toolbar.add(targetStepCombo);
0376: toolbar.addRelatedGap();
0377:
0378: toolbar.addFixed(new JLabel("Property:"));
0379: toolbar.addRelatedGap();
0380:
0381: targetPropertyCombo
0382: .setToolTipText("The property the value will be transferred to");
0383: targetPropertyCombo.setEnabled(false);
0384: targetPropertyCombo.addItemListener(new ItemListener() {
0385:
0386: public void itemStateChanged(ItemEvent e) {
0387: if (e.getStateChange() == ItemEvent.SELECTED
0388: && !selecting) {
0389: String targetProperty = (String) targetPropertyCombo
0390: .getSelectedItem();
0391: PropertyTransfer valueTransfer = getCurrentTransfer();
0392:
0393: if (valueTransfer != null) {
0394: valueTransfer
0395: .setTargetPropertyName(targetProperty);
0396: }
0397: }
0398: }
0399: });
0400:
0401: toolbar.add(targetPropertyCombo);
0402: return toolbar;
0403: }
0404:
0405: protected JXToolBar createSourceToolbar() {
0406: JXToolBar toolbar = UISupport.createToolbar();
0407: toolbar.addSpace(3);
0408: toolbar.addFixed(new JLabel("<html><b>Source:</b></html>"));
0409: toolbar.addGlue();
0410:
0411: sourcePropertyCombo = new JComboBox();
0412: sourceStepModel = new DefaultComboBoxModel();
0413: sourceStepCombo = new JComboBox(sourceStepModel);
0414: sourceTestStepNameListener = new TestStepNameListener(
0415: sourceStepModel);
0416:
0417: componentEnabler.add(sourcePropertyCombo);
0418: componentEnabler.add(sourceStepCombo);
0419:
0420: targetPropertyCombo = new JComboBox();
0421: targetStepModel = new DefaultComboBoxModel();
0422: targetStepCombo = new JComboBox(targetStepModel);
0423: targetStepNameListener = new TestStepNameListener(
0424: targetStepModel);
0425:
0426: componentEnabler.add(targetPropertyCombo);
0427: componentEnabler.add(targetStepCombo);
0428:
0429: sourceStepPropertiesListener = new TestStepPropertiesListener(
0430: sourcePropertyCombo);
0431: targetStepPropertiesListener = new TestStepPropertiesListener(
0432: targetPropertyCombo);
0433:
0434: for (int c = 0; c < transferStep.getTestCase()
0435: .getTestStepCount(); c++) {
0436: WsdlTestStep testStep = (WsdlTestStep) transferStep
0437: .getTestCase().getTestStepAt(c);
0438: if (testStep == transferStep)
0439: continue;
0440:
0441: testStep.addPropertyChangeListener(TestStep.NAME_PROPERTY,
0442: sourceTestStepNameListener);
0443: testStep.addPropertyChangeListener(TestStep.NAME_PROPERTY,
0444: targetStepNameListener);
0445:
0446: String nm = testStep.getName();
0447: sourceStepModel.addElement(nm);
0448: targetStepModel.addElement(nm);
0449: }
0450:
0451: sourceStepCombo.setSelectedItem(null);
0452: sourceStepCombo
0453: .setToolTipText("The step the value will be transferred from");
0454: sourceStepCombo.setEnabled(false);
0455: sourceStepCombo.addItemListener(new StepComboItemListener(
0456: sourcePropertyCombo, sourceStepPropertiesListener));
0457: sourceStepCombo.addItemListener(new ItemListener() {
0458:
0459: public void itemStateChanged(ItemEvent e) {
0460: if (e.getStateChange() == ItemEvent.SELECTED
0461: && !selecting) {
0462: String sourceStep = (String) sourceStepCombo
0463: .getSelectedItem();
0464: PropertyTransfer valueTransfer = getCurrentTransfer();
0465:
0466: if (valueTransfer != null) {
0467: valueTransfer.setSourceStepName(sourceStep);
0468: }
0469: }
0470: }
0471: });
0472:
0473: toolbar.addFixed(new JLabel("Step:"));
0474: toolbar.addRelatedGap();
0475: toolbar.add(sourceStepCombo);
0476: toolbar.addRelatedGap();
0477:
0478: toolbar.addFixed(new JLabel("Property:"));
0479: toolbar.addRelatedGap();
0480:
0481: sourcePropertyCombo
0482: .setToolTipText("The property the value will be transferred from");
0483: sourcePropertyCombo.setEnabled(false);
0484: sourcePropertyCombo.addItemListener(new ItemListener() {
0485:
0486: public void itemStateChanged(ItemEvent e) {
0487: if (e.getStateChange() == ItemEvent.SELECTED
0488: && !selecting) {
0489: String sourceProperty = (String) sourcePropertyCombo
0490: .getSelectedItem();
0491: PropertyTransfer valueTransfer = getCurrentTransfer();
0492:
0493: if (valueTransfer != null) {
0494: valueTransfer
0495: .setSourcePropertyName(sourceProperty);
0496: }
0497: }
0498: }
0499: });
0500:
0501: toolbar.add(sourcePropertyCombo);
0502: return toolbar;
0503: }
0504:
0505: public PropertyTransfer getCurrentTransfer() {
0506: int ix = transferList.getSelectedIndex();
0507: return ix == -1 ? null : transferStep.getTransferAt(ix);
0508: }
0509:
0510: /**
0511: * Listen for testStep property changes and update properties combo accordingly
0512: */
0513:
0514: private static final class TestStepPropertiesListener implements
0515: WsdlTestStepListener {
0516: private final JComboBox combo;
0517:
0518: public TestStepPropertiesListener(JComboBox combo) {
0519: this .combo = combo;
0520: }
0521:
0522: public void propertyAdded(String name) {
0523: combo.addItem(name);
0524: combo.setEnabled(true);
0525: }
0526:
0527: public void propertyRemoved(String name) {
0528: if (combo.getSelectedItem().equals(name))
0529: combo.setSelectedItem(null);
0530:
0531: combo.removeItem(name);
0532: combo.setEnabled(combo.getItemCount() > 0);
0533: }
0534:
0535: public void propertyRenamed(String oldName, String newName) {
0536: DefaultComboBoxModel model = (DefaultComboBoxModel) combo
0537: .getModel();
0538:
0539: int stepIndex = model.getIndexOf(oldName);
0540: if (stepIndex != -1) {
0541: Object selectedItem = model.getSelectedItem();
0542:
0543: model.removeElementAt(stepIndex);
0544: model.insertElementAt(newName, stepIndex);
0545:
0546: // ensure selection
0547: if (selectedItem.equals(oldName))
0548: model.setSelectedItem(newName);
0549: }
0550: }
0551:
0552: public void propertyValueChanged(String name, String oldValue,
0553: String newValue) {
0554: }
0555: }
0556:
0557: /**
0558: * Listen for teststep changes and update source/target step combos accordingly
0559: */
0560:
0561: private final class InternalTestSuiteListener extends
0562: TestSuiteListenerAdapter {
0563: public void testStepAdded(TestStep testStep, int index) {
0564: if (testStep.getTestCase() == transferStep.getTestCase()) {
0565: sourceStepModel.addElement(testStep.getName());
0566: targetStepModel.addElement(testStep.getName());
0567:
0568: testStep.addPropertyChangeListener(
0569: TestStep.NAME_PROPERTY,
0570: sourceTestStepNameListener);
0571: testStep.addPropertyChangeListener(
0572: TestStep.NAME_PROPERTY, targetStepNameListener);
0573: }
0574: }
0575:
0576: public void testStepMoved(TestStep testStep, int fromIndex,
0577: int offset) {
0578: if (testStep.getTestCase() == transferStep.getTestCase()) {
0579: String testStepName = testStep.getName();
0580: if (sourceStepModel.getIndexOf(testStepName) == fromIndex) {
0581: String sourceStep = (String) sourceStepCombo
0582: .getSelectedItem();
0583: String sourceProperty = (String) sourcePropertyCombo
0584: .getSelectedItem();
0585:
0586: sourceStepModel.removeElementAt(fromIndex);
0587: if (fromIndex + offset > sourceStepModel.getSize())
0588: sourceStepModel.addElement(testStepName);
0589: else
0590: sourceStepModel.insertElementAt(testStepName,
0591: fromIndex + offset);
0592:
0593: sourceStepCombo.setSelectedItem(sourceStep);
0594: sourcePropertyCombo.setSelectedItem(sourceProperty);
0595: }
0596:
0597: if (targetStepModel.getIndexOf(testStepName) == fromIndex) {
0598: String targetStep = (String) targetStepCombo
0599: .getSelectedItem();
0600: String targetProperty = (String) targetPropertyCombo
0601: .getSelectedItem();
0602:
0603: targetStepModel.removeElementAt(fromIndex);
0604: if (fromIndex + offset > targetStepModel.getSize())
0605: targetStepModel.addElement(testStepName);
0606: else
0607: targetStepModel.insertElementAt(testStepName,
0608: fromIndex + offset);
0609:
0610: targetStepCombo.setSelectedItem(targetStep);
0611: targetPropertyCombo.setSelectedItem(targetProperty);
0612: }
0613: }
0614: }
0615:
0616: public void testStepRemoved(TestStep testStep, int index) {
0617: if (testStep.getTestCase() == transferStep.getTestCase()) {
0618: sourceStepModel.removeElement(testStep.getName());
0619: targetStepModel.removeElement(testStep.getName());
0620:
0621: testStep.removePropertyChangeListener(
0622: TestStep.NAME_PROPERTY,
0623: sourceTestStepNameListener);
0624: testStep.removePropertyChangeListener(
0625: TestStep.NAME_PROPERTY, targetStepNameListener);
0626: }
0627: }
0628: }
0629:
0630: /**
0631: * Listen for testStep name changes and modify comboBox model accordingly
0632: */
0633:
0634: private final class TestStepNameListener implements
0635: PropertyChangeListener {
0636: private final DefaultComboBoxModel model;
0637:
0638: public TestStepNameListener(DefaultComboBoxModel model) {
0639: this .model = model;
0640: }
0641:
0642: public void propertyChange(PropertyChangeEvent evt) {
0643: Object oldItem = evt.getOldValue();
0644: int stepIndex = model.getIndexOf(oldItem);
0645: if (stepIndex != -1) {
0646: Object selectedItem = model.getSelectedItem();
0647: Object newItem = evt.getNewValue();
0648:
0649: selecting = true;
0650: model.removeElementAt(stepIndex);
0651: model.insertElementAt(newItem, stepIndex);
0652: selecting = false;
0653:
0654: // ensure selection
0655: if (selectedItem.equals(oldItem))
0656: model.setSelectedItem(newItem);
0657: }
0658: }
0659: }
0660:
0661: /**
0662: * Listen to step selections and update properties combo accordingly
0663: */
0664:
0665: private final class StepComboItemListener implements ItemListener {
0666: private final JComboBox propertyCombo;
0667: private final TestStepPropertiesListener testStepPropertiesListener;
0668:
0669: public StepComboItemListener(final JComboBox propertyCombo,
0670: TestStepPropertiesListener testStepPropertiesListener) {
0671: this .propertyCombo = propertyCombo;
0672: this .testStepPropertiesListener = testStepPropertiesListener;
0673: }
0674:
0675: public void itemStateChanged(ItemEvent e) {
0676: if (e.getStateChange() == ItemEvent.DESELECTED) {
0677: WsdlTestStep step = (WsdlTestStep) transferStep
0678: .getTestCase().getTestStepByName(
0679: (String) e.getItem());
0680: if (step != null)
0681: step
0682: .removeTestStepListener(testStepPropertiesListener);
0683: }
0684:
0685: if (e.getStateChange() == ItemEvent.SELECTED) {
0686: String selectedItem = (String) e.getItem();
0687: WsdlTestStep step = (WsdlTestStep) transferStep
0688: .getTestCase().getTestStepByName(selectedItem);
0689:
0690: String[] propertyNames = step == null ? new String[0]
0691: : step.getPropertyNames();
0692:
0693: // remove read-only properties from target property
0694: if (propertyCombo == targetPropertyCombo) {
0695: List<String> names = new ArrayList<String>();
0696: for (String name : propertyNames) {
0697: TestStepProperty property = step
0698: .getProperty(name);
0699: if (!property.isReadOnly())
0700: names.add(property.getName());
0701: }
0702:
0703: propertyNames = names.toArray(new String[names
0704: .size()]);
0705: }
0706:
0707: propertyCombo.setModel(new DefaultComboBoxModel(
0708: propertyNames));
0709: propertyCombo.setEnabled(propertyNames.length > 0);
0710:
0711: if (propertyCombo == targetPropertyCombo)
0712: propertyCombo.setSelectedItem(getCurrentTransfer()
0713: .getTargetPropertyName());
0714: else
0715: propertyCombo.setSelectedItem(getCurrentTransfer()
0716: .getSourcePropertyName());
0717:
0718: step.addTestStepListener(testStepPropertiesListener);
0719: } else {
0720: propertyCombo.removeAllItems();
0721: propertyCombo.setEnabled(false);
0722: }
0723: }
0724: }
0725:
0726: /**
0727: * Handle updates to source path
0728: */
0729:
0730: private final class SourceAreaDocumentListener extends
0731: DocumentListenerAdapter {
0732: public void update(Document document) {
0733: int ix = transferList.getSelectedIndex();
0734: if (ix != -1) {
0735: transferStep.getTransferAt(ix).setSourcePath(
0736: sourceArea.getText());
0737: }
0738: }
0739: }
0740:
0741: /**
0742: * Handle updates to target path
0743: */
0744:
0745: private final class TargetAreaDocumentListener extends
0746: DocumentListenerAdapter {
0747: public void update(Document document) {
0748: int ix = transferList.getSelectedIndex();
0749: if (ix != -1) {
0750: transferStep.getTransferAt(ix).setTargetPath(
0751: targetArea.getText());
0752: }
0753: }
0754: }
0755:
0756: /**
0757: * Listen to selection changes in transfer list and update controls accordingly
0758: */
0759:
0760: private final class TransferListSelectionListener implements
0761: ListSelectionListener {
0762: private PropertyTransfer transfer;
0763:
0764: public void valueChanged(ListSelectionEvent e) {
0765: selecting = true;
0766:
0767: if (transfer != null) {
0768: transfer
0769: .removePropertyChangeListener(transferPropertyChangeListener);
0770: }
0771:
0772: transfer = getCurrentTransfer();
0773:
0774: if (transfer == null) {
0775: sourceArea.setText("");
0776: targetArea.setText("");
0777:
0778: sourcePropertyCombo.removeAllItems();
0779: targetPropertyCombo.removeAllItems();
0780:
0781: sourceStepCombo.setSelectedIndex(-1);
0782: targetStepCombo.setSelectedIndex(-1);
0783: } else {
0784: transfer
0785: .addPropertyChangeListener(transferPropertyChangeListener);
0786:
0787: sourceArea.setText(transfer.getSourcePath());
0788: targetArea.setText(transfer.getTargetPath());
0789:
0790: sourceStepCombo.setSelectedItem(transfer
0791: .getSourceStepName());
0792: sourcePropertyCombo.setSelectedItem(transfer
0793: .getSourcePropertyName());
0794:
0795: targetStepCombo.setSelectedItem(transfer
0796: .getTargetStepName());
0797: targetPropertyCombo.setSelectedItem(transfer
0798: .getTargetPropertyName());
0799:
0800: failTransferCheckBox.setSelected(transfer
0801: .getFailOnError());
0802: setNullCheckBox.setSelected(transfer
0803: .getSetNullOnMissingSource());
0804: transferTextContentCheckBox.setSelected(transfer
0805: .getTransferTextContent());
0806: ignoreEmptyCheckBox.setSelected(transfer
0807: .getIgnoreEmpty());
0808: transferAllCheckBox.setSelected(transfer
0809: .getTransferToAll());
0810: }
0811:
0812: copyButton.setEnabled(transfer != null);
0813: renameButton.setEnabled(transfer != null);
0814: deleteButton.setEnabled(transfer != null);
0815: declareButton.setEnabled(transfer != null);
0816: sourceStepCombo.setEnabled(transfer != null);
0817: targetStepCombo.setEnabled(transfer != null);
0818: sourceArea.setEnabled(transfer != null);
0819: targetArea.setEnabled(transfer != null);
0820: failTransferCheckBox.setEnabled(transfer != null);
0821: setNullCheckBox.setEnabled(transfer != null);
0822: transferTextContentCheckBox.setEnabled(transfer != null);
0823: ignoreEmptyCheckBox.setEnabled(transfer != null);
0824: transferAllCheckBox.setEnabled(transfer != null);
0825:
0826: runButton.setEnabled(transferList.getModel().getSize() > 0);
0827:
0828: sourcePropertyCombo.setEnabled(transfer != null);
0829: targetPropertyCombo.setEnabled(transfer != null);
0830:
0831: selecting = false;
0832: }
0833: }
0834:
0835: /**
0836: * Listen to property changes and update UI objects. These may have been triggered by UI so first check
0837: * for actual difference so we dont end up in loop.
0838: */
0839:
0840: private class TransferPropertyChangeListener implements
0841: PropertyChangeListener {
0842: public void propertyChange(PropertyChangeEvent evt) {
0843: Object newValue = evt.getNewValue();
0844:
0845: if (evt.getPropertyName().equals(
0846: PropertyTransfer.SOURCE_PATH_PROPERTY)) {
0847: if (!sourceArea.getText().equals(newValue))
0848: sourceArea.setText((String) newValue);
0849: } else if (evt.getPropertyName().equals(
0850: PropertyTransfer.TARGET_PATH_PROPERTY)) {
0851: if (!targetArea.getText().equals(newValue))
0852: targetArea.setText((String) newValue);
0853: } else if (evt.getPropertyName().equals(
0854: PropertyTransfer.SOURCE_STEP_PROPERTY)) {
0855: Object selectedItem = sourceStepCombo.getSelectedItem();
0856: if (newValue == null || selectedItem == null
0857: || !selectedItem.equals(newValue)) {
0858: selecting = true;
0859: sourceStepCombo.setSelectedItem(newValue);
0860: selecting = false;
0861: }
0862: } else if (evt.getPropertyName().equals(
0863: PropertyTransfer.TARGET_STEP_PROPERTY)) {
0864: Object selectedItem = targetStepCombo.getSelectedItem();
0865: if (newValue == null || selectedItem == null
0866: || !selectedItem.equals(newValue)) {
0867: selecting = true;
0868: targetStepCombo.setSelectedItem(newValue);
0869: selecting = false;
0870: }
0871: } else if (evt.getPropertyName().equals(
0872: PropertyTransfer.SOURCE_TYPE_PROPERTY)) {
0873: Object selectedItem = sourcePropertyCombo
0874: .getSelectedItem();
0875: if (selectedItem == null
0876: || !selectedItem.equals(newValue))
0877: sourcePropertyCombo.setSelectedItem(newValue);
0878: } else if (evt.getPropertyName().equals(
0879: PropertyTransfer.TARGET_TYPE_PROPERTY)) {
0880: Object selectedItem = targetPropertyCombo
0881: .getSelectedItem();
0882: if (selectedItem == null
0883: || !selectedItem.equals(newValue))
0884: targetPropertyCombo.setSelectedItem(newValue);
0885: }
0886: }
0887: }
0888:
0889: private final class AddAction extends AbstractAction {
0890: public AddAction() {
0891: super ("Add");
0892: putValue(Action.SHORT_DESCRIPTION,
0893: "Adds a new Property Transfer");
0894: }
0895:
0896: public void actionPerformed(ActionEvent e) {
0897: String name = UISupport.prompt(
0898: "Specify name for value transfer", "Add Transfer",
0899: "");
0900: if (name == null || name.trim().length() == 0)
0901: return;
0902:
0903: transferStep.addTransfer(name);
0904:
0905: listModel.addElement(name);
0906: transferList.setSelectedIndex(listModel.getSize() - 1);
0907: }
0908: }
0909:
0910: private final class CopyAction extends AbstractAction {
0911: public CopyAction() {
0912: super ("Copy");
0913: putValue(Action.SHORT_DESCRIPTION,
0914: "Copies the selected Property Transfer");
0915: }
0916:
0917: public void actionPerformed(ActionEvent e) {
0918: int ix = transferList.getSelectedIndex();
0919: PropertyTransfer config = transferStep.getTransferAt(ix);
0920:
0921: String name = UISupport.prompt(
0922: "Specify name for value transfer", "Copy Transfer",
0923: config.getName());
0924: if (name == null || name.trim().length() == 0)
0925: return;
0926:
0927: PropertyTransfer transfer = transferStep.addTransfer(name);
0928: transfer.setSourceStepName(config.getSourceStepName());
0929: transfer.setSourcePropertyName(config
0930: .getSourcePropertyName());
0931: transfer.setSourcePath(config.getSourcePath());
0932: transfer.setTargetStepName(config.getTargetStepName());
0933: transfer.setTargetPropertyName(config
0934: .getTargetPropertyName());
0935: transfer.setTargetPath(config.getTargetPath());
0936:
0937: listModel.addElement(name);
0938: transferList.setSelectedIndex(listModel.getSize() - 1);
0939: }
0940: }
0941:
0942: private final class DeleteAction extends AbstractAction {
0943: public DeleteAction() {
0944: super ("Delete");
0945: putValue(Action.SHORT_DESCRIPTION,
0946: "Deletes the selected Property Transfer");
0947: }
0948:
0949: public void actionPerformed(ActionEvent e) {
0950: if (UISupport.confirm("Delete selected transfer",
0951: "Delete Transfer")) {
0952: transferList.setSelectedIndex(-1);
0953:
0954: int ix = transferList.getSelectedIndex();
0955: transferStep.removeTransferAt(ix);
0956: listModel.remove(ix);
0957:
0958: if (listModel.getSize() > 0) {
0959: transferList.setSelectedIndex(ix > listModel
0960: .getSize() - 1 ? listModel.getSize() - 1
0961: : ix);
0962: }
0963: }
0964: }
0965: }
0966:
0967: private final class RenameAction extends AbstractAction {
0968: public RenameAction() {
0969: super ("Rename");
0970: putValue(Action.SHORT_DESCRIPTION,
0971: "Renames the selected Property Transfer");
0972: }
0973:
0974: public void actionPerformed(ActionEvent e) {
0975: PropertyTransfer transfer = getCurrentTransfer();
0976:
0977: String newName = UISupport.prompt(
0978: "Specify new name for transfer", "Rename Transfer",
0979: transfer.getName());
0980:
0981: if (newName != null && !transfer.getName().equals(newName)) {
0982: listModel.setElementAt(newName, transferList
0983: .getSelectedIndex());
0984: transfer.setName(newName);
0985: }
0986: }
0987: }
0988:
0989: private final class DeclareNamespacesAction extends AbstractAction {
0990: public DeclareNamespacesAction() {
0991: super ("Declare");
0992: putValue(Action.SHORT_DESCRIPTION,
0993: "Declare available response/request namespaces in source/target expressions");
0994: }
0995:
0996: public void actionPerformed(ActionEvent e) {
0997: try {
0998: TestStep previousStep = getCurrentTransfer()
0999: .getSourceStep();
1000:
1001: if (previousStep instanceof WsdlTestRequestStep) {
1002: WsdlTestRequest testRequest = ((WsdlTestRequestStep) previousStep)
1003: .getTestRequest();
1004: sourceArea.setText(XmlUtils
1005: .declareXPathNamespaces(testRequest
1006: .getOperation().getInterface())
1007: + sourceArea.getText());
1008: } else
1009: UISupport
1010: .showErrorMessage("Source step is not a request");
1011:
1012: TestStep nextStep = getCurrentTransfer()
1013: .getTargetStep();
1014:
1015: if (nextStep instanceof WsdlTestRequestStep) {
1016: WsdlTestRequest testRequest = ((WsdlTestRequestStep) nextStep)
1017: .getTestRequest();
1018: targetArea.setText(XmlUtils
1019: .declareXPathNamespaces(testRequest
1020: .getOperation().getInterface())
1021: + targetArea.getText());
1022: } else
1023: UISupport
1024: .showErrorMessage("Target step is not a request");
1025: } catch (Exception e1) {
1026: UISupport.showErrorMessage(e1);
1027: }
1028: }
1029: }
1030:
1031: private final class RunAction extends AbstractAction {
1032: public RunAction() {
1033: super ("Run");
1034: putValue(Action.SHORT_DESCRIPTION,
1035: "Runs all Property Transfers");
1036: }
1037:
1038: public void actionPerformed(ActionEvent e) {
1039: if (listModel.getSize() == 0) {
1040: UISupport.showErrorMessage("Missing transfers!");
1041: return;
1042: }
1043:
1044: WsdlTestRunContext context = new WsdlTestRunContext(
1045: transferStep);
1046: ValueTransferResult result = (ValueTransferResult) transferStep
1047: .run(null, context);
1048:
1049: if (resultDesktopPanel != null)
1050: SoapUI.getDesktop().closeDesktopPanel(
1051: resultDesktopPanel);
1052:
1053: ShowTransferValuesResultsAction action = new ShowTransferValuesResultsAction(
1054: result);
1055: resultDesktopPanel = action.showDesktopPanel();
1056: }
1057: }
1058:
1059: public ModelItem getModelItem() {
1060: return transferStep;
1061: }
1062:
1063: public boolean onClose(boolean canCancel) {
1064: transferStep.getTestCase().getTestSuite()
1065: .removeTestSuiteListener(testSuiteListener);
1066:
1067: PropertyTransfer transfer = getCurrentTransfer();
1068:
1069: if (transfer != null) {
1070: transfer
1071: .removePropertyChangeListener(transferPropertyChangeListener);
1072: }
1073:
1074: for (int c = 0; c < transferStep.getTestCase()
1075: .getTestStepCount(); c++) {
1076: WsdlTestStep testStep = (WsdlTestStep) transferStep
1077: .getTestCase().getTestStepAt(c);
1078:
1079: testStep.removePropertyChangeListener(
1080: TestStep.NAME_PROPERTY, sourceTestStepNameListener);
1081: testStep.removePropertyChangeListener(
1082: TestStep.NAME_PROPERTY, targetStepNameListener);
1083: }
1084:
1085: Object item = sourceStepCombo.getSelectedItem();
1086: if (item != null) {
1087: WsdlTestStep step = (WsdlTestStep) transferStep
1088: .getTestCase().getTestStepByName((String) item);
1089: if (step != null)
1090: step
1091: .removeTestStepListener(sourceStepPropertiesListener);
1092: }
1093:
1094: item = targetStepCombo.getSelectedItem();
1095: if (item != null) {
1096: WsdlTestStep step = (WsdlTestStep) transferStep
1097: .getTestCase().getTestStepByName((String) item);
1098: if (step != null)
1099: step
1100: .removeTestStepListener(targetStepPropertiesListener);
1101: }
1102:
1103: componentEnabler.release();
1104: if (resultDesktopPanel != null)
1105: SoapUI.getDesktop().closeDesktopPanel(resultDesktopPanel);
1106:
1107: return true;
1108: }
1109:
1110: public JComponent getComponent() {
1111: return this ;
1112: }
1113:
1114: public boolean dependsOn(ModelItem modelItem) {
1115: return modelItem == transferStep
1116: || modelItem == transferStep.getTestCase()
1117: || modelItem == transferStep.getTestCase()
1118: .getTestSuite()
1119: || modelItem == transferStep.getTestCase()
1120: .getTestSuite().getProject();
1121: }
1122:
1123: public String getTitle() {
1124: return transferStep.getTestCase().getName() + " - "
1125: + transferStep.getName();
1126: }
1127:
1128: public String getDescription() {
1129: return "Property Transfer: [" + transferStep.getName() + "] - "
1130: + transferStep.getTestStepTitle();
1131: }
1132:
1133: public Icon getIcon() {
1134: return getModelItem().getIcon();
1135: }
1136:
1137: public boolean selectTransfer(PropertyTransfer transfer) {
1138: for (int c = 0; c < transferStep.getTransferCount(); c++) {
1139: if (transferStep.getTransferAt(c) == transfer) {
1140: transferList.setSelectedIndex(c);
1141: return true;
1142: }
1143: }
1144:
1145: return false;
1146: }
1147: }
|