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.Date;
020:
021: import javax.swing.AbstractAction;
022: import javax.swing.JComponent;
023: import javax.swing.JLabel;
024: import javax.swing.JList;
025: import javax.swing.JPanel;
026: import javax.swing.JScrollPane;
027: import javax.swing.JSplitPane;
028: import javax.swing.JTabbedPane;
029: import javax.swing.JTable;
030:
031: import com.eviware.soapui.SoapUI;
032: import com.eviware.soapui.impl.wsdl.panels.request.StringToStringMapTableModel;
033: import com.eviware.soapui.model.iface.MessageExchange;
034: import com.eviware.soapui.support.UISupport;
035: import com.eviware.soapui.support.types.StringToStringMap;
036: import com.eviware.soapui.support.xml.JXEditTextArea;
037: import com.eviware.soapui.support.xml.XmlUtils;
038: import com.eviware.soapui.ui.desktop.DesktopPanel;
039: import com.eviware.soapui.ui.support.DefaultDesktopPanel;
040:
041: /**
042: * Shows a desktop-panel with the TestStepResult for a WsdlTestRequestStepResult
043: *
044: * @author Ole.Matzura
045: */
046:
047: public class ShowMessageExchangeAction extends AbstractAction {
048: private DefaultDesktopPanel desktopPanel;
049: private final MessageExchange messageExchange;
050: private final String ownerName;
051:
052: public ShowMessageExchangeAction(MessageExchange messageExchange,
053: String ownerName) {
054: super ("Show Results");
055: this .ownerName = ownerName;
056: this .messageExchange = messageExchange;
057: }
058:
059: public void actionPerformed(ActionEvent e) {
060: try {
061: UISupport.showDesktopPanel(buildFrame());
062: } catch (Exception ex) {
063: SoapUI.logError(ex);
064: }
065: }
066:
067: private DesktopPanel buildFrame() {
068: if (desktopPanel == null) {
069: desktopPanel = new DefaultDesktopPanel("Message Viewer",
070: "Message for " + ownerName, buildContent());
071: }
072:
073: return desktopPanel;
074: }
075:
076: private JComponent buildContent() {
077: JTabbedPane messageTabs = new JTabbedPane();
078: messageTabs.addTab("Request Message", buildRequestTab());
079: messageTabs.addTab("Response Message", buildResponseTab());
080: messageTabs.addTab("Properties", buildPropertiesTab());
081: messageTabs.addTab("Messages", buildMessagesTab());
082:
083: messageTabs.setPreferredSize(new Dimension(500, 400));
084:
085: JPanel tabPanel = UISupport.createTabPanel(messageTabs, true);
086:
087: Component descriptionPanel = UISupport.buildDescription(
088: "MessageExchange Results",
089: "See the request/response message below", null);
090: tabPanel.add(descriptionPanel, BorderLayout.NORTH);
091:
092: return tabPanel;
093: }
094:
095: private Component buildPropertiesTab() {
096: StringToStringMap properties = new StringToStringMap();
097: if (messageExchange != null
098: && messageExchange.getProperties() != null) {
099: properties.putAll(messageExchange.getProperties());
100:
101: properties.put("Timestamp", new Date(messageExchange
102: .getTimestamp()).toString());
103: properties.put("Time Taken", String.valueOf(messageExchange
104: .getTimeTaken()));
105: }
106: JTable table = new JTable(new StringToStringMapTableModel(
107: properties, "Name", "Value", false));
108: return new JScrollPane(table);
109: }
110:
111: private Component buildMessagesTab() {
112: String[] messages = messageExchange.getMessages();
113: return messages == null || messages.length == 0 ? new JLabel(
114: "No messages to display") : new JScrollPane(new JList(
115: messages));
116: }
117:
118: private Component buildResponseTab() {
119: JXEditTextArea resultArea = JXEditTextArea.createXmlEditor();
120: if (messageExchange != null)
121: resultArea.setText(XmlUtils.prettyPrintXml(messageExchange
122: .getResponseContent()));
123: else
124: resultArea.setText("- null -");
125: resultArea.setEditable(false);
126: resultArea.setToolTipText("Response Content");
127: JScrollPane scrollPane = new JScrollPane(resultArea);
128:
129: if (messageExchange != null) {
130: JSplitPane split = UISupport.createVerticalSplit(
131: new JScrollPane(new JTable(
132: new StringToStringMapTableModel(
133: messageExchange
134: .getResponseHeaders(),
135: "Header", "Value", false))),
136: scrollPane);
137: split.setDividerLocation(150);
138: return split;
139: }
140:
141: return scrollPane;
142: }
143:
144: private Component buildRequestTab() {
145: JXEditTextArea resultArea = JXEditTextArea.createXmlEditor();
146: if (messageExchange != null)
147: resultArea.setText(XmlUtils.prettyPrintXml(messageExchange
148: .getRequestContent()));
149: else
150: resultArea.setText("- null -");
151: resultArea.setEditable(false);
152: resultArea.setToolTipText("Request Content");
153: JScrollPane scrollPane = new JScrollPane(resultArea);
154:
155: if (messageExchange != null) {
156: JSplitPane split = UISupport
157: .createVerticalSplit(
158: new JScrollPane(
159: new JTable(
160: new StringToStringMapTableModel(
161: messageExchange
162: .getRequestHeaders(),
163: "Header", "Value",
164: false))),
165: scrollPane);
166: split.setDividerLocation(150);
167: return split;
168: }
169:
170: return scrollPane;
171: }
172: }
|