001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl.teststeps.actions;
014:
015: import java.awt.BorderLayout;
016: import java.awt.Component;
017: import java.awt.Dimension;
018: import java.awt.event.ActionEvent;
019: import java.util.Arrays;
020:
021: import javax.swing.AbstractAction;
022: import javax.swing.BorderFactory;
023: import javax.swing.JComponent;
024: import javax.swing.JPanel;
025: import javax.swing.JScrollPane;
026: import javax.swing.table.AbstractTableModel;
027:
028: import org.jdesktop.swingx.JXTable;
029:
030: import com.eviware.soapui.SoapUI;
031: import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStepResult;
032: import com.eviware.soapui.impl.wsdl.teststeps.TransferResponseValuesTestStep.ValueTransferResult;
033: import com.eviware.soapui.support.UISupport;
034: import com.eviware.soapui.ui.desktop.DesktopPanel;
035: import com.eviware.soapui.ui.support.DefaultDesktopPanel;
036:
037: /**
038: * Shows a desktop-panel with the TestStepResult for a ValueTransferResult
039: *
040: * @author Ole.Matzura
041: */
042:
043: public class ShowTransferValuesResultsAction extends AbstractAction {
044: private final ValueTransferResult result;
045: private DefaultDesktopPanel desktopPanel;
046:
047: public ShowTransferValuesResultsAction(WsdlTestStepResult result) {
048: this .result = (ValueTransferResult) result;
049: }
050:
051: public void actionPerformed(ActionEvent e) {
052: try {
053: if (result.isDiscarded())
054: UISupport
055: .showInfoMessage("Request has been discarded..");
056: else
057: showDesktopPanel();
058: } catch (Exception ex) {
059: SoapUI.logError(ex);
060: }
061: }
062:
063: public DesktopPanel showDesktopPanel() {
064: return UISupport.showDesktopPanel(buildFrame());
065: }
066:
067: private DesktopPanel buildFrame() {
068: if (desktopPanel == null) {
069: desktopPanel = new DefaultDesktopPanel("TestStep Result",
070: "TestStep result for "
071: + result.getTestStep().getName(),
072: buildContent());
073: }
074:
075: return desktopPanel;
076: }
077:
078: private JComponent buildContent() {
079: JPanel panel = new JPanel(new BorderLayout());
080: JXTable table = new JXTable(new TransfersTableModel());
081:
082: // table.setColumnControlVisible( true );
083: table.setHorizontalScrollEnabled(true);
084: table.packAll();
085:
086: Component descriptionPanel = UISupport
087: .buildDescription(
088: "PropertyTransfer Results",
089: "See the result of each performed transfer below",
090: null);
091: panel.add(descriptionPanel, BorderLayout.NORTH);
092:
093: JScrollPane scrollPane = new JScrollPane(table);
094: scrollPane.setBorder(BorderFactory.createCompoundBorder(
095: BorderFactory.createEmptyBorder(3, 3, 3, 3), scrollPane
096: .getBorder()));
097:
098: panel.add(scrollPane, BorderLayout.CENTER);
099: panel.setPreferredSize(new Dimension(550, 300));
100:
101: return panel;
102: }
103:
104: private class TransfersTableModel extends AbstractTableModel {
105: public int getRowCount() {
106: return result.getTransferCount();
107: }
108:
109: public int getColumnCount() {
110: return 2;
111: }
112:
113: public String getColumnName(int column) {
114: switch (column) {
115: case 0:
116: return "Transfer Name";
117: case 1:
118: return "Transferred Values";
119: }
120:
121: return null;
122: }
123:
124: public Object getValueAt(int rowIndex, int columnIndex) {
125: switch (columnIndex) {
126: case 0:
127: return result.getTransferAt(rowIndex).getName();
128: case 1:
129: return Arrays.toString(result
130: .getTransferredValuesAt(rowIndex));
131: }
132:
133: return null;
134: }
135:
136: }
137:
138: }
|