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.mock;
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.BorderFactory;
023: import javax.swing.JComponent;
024: import javax.swing.JLabel;
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.support.UISupport;
034: import com.eviware.soapui.support.xml.JXEditTextArea;
035: import com.eviware.soapui.support.xml.XmlUtils;
036: import com.eviware.soapui.ui.desktop.DesktopPanel;
037: import com.eviware.soapui.ui.support.DefaultDesktopPanel;
038: import com.jgoodies.forms.builder.ButtonBarBuilder;
039:
040: /**
041: * Shows a desktop-panel with the MessageExchange for a WsdlMockResult
042: *
043: * @author Ole.Matzura
044: */
045:
046: public class ViewWsdlMockResultAction extends AbstractAction {
047: private final WsdlMockResult result;
048: private DefaultDesktopPanel desktopPanel;
049:
050: public ViewWsdlMockResultAction(WsdlMockResult result) {
051: super ("Show Results");
052:
053: this .result = result;
054: }
055:
056: public void actionPerformed(ActionEvent e) {
057: try {
058: if (result.isDiscarded())
059: UISupport
060: .showInfoMessage("Request has been discarded..");
061: else
062: UISupport.showDesktopPanel(buildFrame());
063: } catch (Exception ex) {
064: SoapUI.logError(ex);
065: }
066: }
067:
068: private DesktopPanel buildFrame() {
069: if (desktopPanel == null) {
070: String title = "Mock Result for ["
071: + result.getMockResponse().getName() + "]";
072: desktopPanel = new DefaultDesktopPanel(title, title,
073: buildContent());
074: }
075:
076: return desktopPanel;
077: }
078:
079: private JComponent buildContent() {
080: JTabbedPane messageTabs = new JTabbedPane();
081: messageTabs.addTab("Request", buildRequestTab());
082: messageTabs.addTab("Response", buildResponseTab());
083: messageTabs.setPreferredSize(new Dimension(500, 400));
084:
085: JPanel panel = new JPanel(new BorderLayout());
086: panel.add(UISupport.createTabPanel(messageTabs, true),
087: BorderLayout.CENTER);
088:
089: ButtonBarBuilder builder = new ButtonBarBuilder();
090: builder.addFixed(new JLabel("Mock Request handled at "
091: + new Date(result.getTimestamp()) + ", time taken: "
092: + result.getTimeTaken() + "ms"));
093: builder.addGlue();
094: builder.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
095: panel.add(builder.getPanel(), BorderLayout.PAGE_START);
096:
097: return panel;
098: }
099:
100: private Component buildResponseTab() {
101: JXEditTextArea responseArea = JXEditTextArea.createXmlEditor();
102: responseArea.setText(XmlUtils.prettyPrintXml(result
103: .getResponseContent()));
104: responseArea.setEditable(false);
105: responseArea.setToolTipText("Response Content");
106: JScrollPane scrollPane = new JScrollPane(responseArea);
107:
108: JSplitPane split = UISupport.createVerticalSplit(
109: new JScrollPane(new JTable(
110: new StringToStringMapTableModel(result
111: .getResponseHeaders(), "Header",
112: "Value", false))), scrollPane);
113: split.setDividerLocation(150);
114: return split;
115: }
116:
117: private Component buildRequestTab() {
118: JXEditTextArea resultArea = JXEditTextArea.createXmlEditor();
119: resultArea.setText(XmlUtils.prettyPrintXml(result
120: .getMockRequest().getRequestContent()));
121: resultArea.setEditable(false);
122: resultArea.setToolTipText("Request Content");
123: JScrollPane scrollPane = new JScrollPane(resultArea);
124:
125: JSplitPane split = UISupport
126: .createVerticalSplit(new JScrollPane(new JTable(
127: new StringToStringMapTableModel(result
128: .getMockRequest().getRequestHeaders(),
129: "Header", "Value", false))), scrollPane);
130: split.setDividerLocation(150);
131: return split;
132: }
133: }
|