1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.mock;
14
15 import java.awt.BorderLayout;
16 import java.awt.Component;
17 import java.awt.Dimension;
18 import java.awt.event.ActionEvent;
19 import java.util.Date;
20
21 import javax.swing.AbstractAction;
22 import javax.swing.BorderFactory;
23 import javax.swing.JComponent;
24 import javax.swing.JLabel;
25 import javax.swing.JPanel;
26 import javax.swing.JScrollPane;
27 import javax.swing.JSplitPane;
28 import javax.swing.JTabbedPane;
29 import javax.swing.JTable;
30
31 import com.eviware.soapui.impl.wsdl.panels.request.StringToStringMapTableModel;
32 import com.eviware.soapui.support.UISupport;
33 import com.eviware.soapui.support.xml.JXEditTextArea;
34 import com.eviware.soapui.support.xml.XmlUtils;
35 import com.eviware.soapui.ui.desktop.DesktopPanel;
36 import com.eviware.soapui.ui.support.DefaultDesktopPanel;
37 import com.jgoodies.forms.builder.ButtonBarBuilder;
38
39 /***
40 * Shows a desktop-panel with the TestStepResult for a WsdlTestRequestStepResult
41 *
42 * @author Ole.Matzura
43 */
44
45 public class ViewWsdlMockResultAction extends AbstractAction
46 {
47 private final WsdlMockResult result;
48 private DefaultDesktopPanel desktopPanel;
49
50 public ViewWsdlMockResultAction(WsdlMockResult result)
51 {
52 super( "Show Results" );
53
54 this.result = result;
55 }
56
57 public void actionPerformed(ActionEvent e)
58 {
59 try
60 {
61 if( result.isDiscarded() )
62 UISupport.showInfoMessage( "Request has been discarded.." );
63 else
64 UISupport.showDesktopPanel(buildFrame());
65 }
66 catch (Exception ex)
67 {
68 ex.printStackTrace();
69 }
70 }
71
72 private DesktopPanel buildFrame()
73 {
74 if( desktopPanel == null )
75 {
76 String title = "Mock Result for [" + result.getMockResponse().getName() + "]";
77 desktopPanel = new DefaultDesktopPanel( title, title, buildContent() );
78 }
79
80 return desktopPanel;
81 }
82
83 private JComponent buildContent()
84 {
85 JTabbedPane messageTabs = new JTabbedPane();
86 messageTabs.addTab( "Request", buildRequestTab() );
87 messageTabs.addTab( "Response", buildResponseTab() );
88 messageTabs.setPreferredSize( new Dimension( 500, 400 ));
89
90 JPanel panel = new JPanel( new BorderLayout() );
91 panel.add( UISupport.createTabPanel( messageTabs, true ), BorderLayout.CENTER );
92
93 ButtonBarBuilder builder = new ButtonBarBuilder();
94 builder.addFixed( new JLabel( "Mock Request handled at " + new Date( result.getTimestamp() ) +
95 ", time taken: " + result.getTimeTaken() + "ms"));
96 builder.addGlue();
97 builder.setBorder( BorderFactory.createEmptyBorder( 2, 2, 2, 2 ) );
98 panel.add( builder.getPanel(), BorderLayout.PAGE_START );
99
100 return panel;
101 }
102
103 private Component buildResponseTab()
104 {
105 JXEditTextArea resultArea = JXEditTextArea.createXmlEditor();
106 resultArea.setText( XmlUtils.prettyPrintXml( result.getResponseContent() ) );
107 resultArea.setEditable( false );
108 resultArea.setToolTipText( "Response Content" );
109 JScrollPane scrollPane = new JScrollPane( resultArea );
110
111 JSplitPane split = UISupport.createVerticalSplit( new JScrollPane( new JTable(
112 new StringToStringMapTableModel( result.getResponseHeaders(), "Header", "Value", false)) ), scrollPane );
113 split.setDividerLocation( 150 );
114 return split;
115 }
116
117 private Component buildRequestTab()
118 {
119 JXEditTextArea resultArea = JXEditTextArea.createXmlEditor();
120 resultArea.setText( XmlUtils.prettyPrintXml( result.getMockRequest().getRequestContent() ) );
121 resultArea.setEditable( false );
122 resultArea.setToolTipText( "Request Content" );
123 JScrollPane scrollPane = new JScrollPane( resultArea );
124
125 JSplitPane split = UISupport.createVerticalSplit( new JScrollPane( new JTable(
126 new StringToStringMapTableModel( result.getMockRequest().getRequestHeaders(), "Header", "Value", false)) ), scrollPane );
127 split.setDividerLocation( 150 );
128 return split;
129 }
130 }