1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.actions.iface.tools.wsi;
14
15 import com.eviware.soapui.SoapUI;
16 import com.eviware.soapui.support.UISupport;
17 import com.eviware.soapui.support.components.BrowserComponent;
18 import com.eviware.soapui.support.components.JXToolBar;
19 import org.apache.xmlbeans.XmlObject;
20
21 import javax.swing.*;
22 import java.awt.*;
23 import java.awt.event.ActionEvent;
24 import java.io.File;
25 import java.io.FileWriter;
26
27 /***
28 * Panel for displaying a WS-I Report
29 *
30 * @author ole.matzura
31 */
32
33 public class WSIReportPanel extends JPanel
34 {
35 private File reportFile;
36
37 private final String configFile;
38 private final File logFile;
39 private SaveReportAction saveReportAction;
40 private BrowserComponent browser;
41
42 public WSIReportPanel( File reportFile, String configFile, File logFile, boolean addToolbar ) throws Exception
43 {
44 super( new BorderLayout() );
45
46 this.reportFile = reportFile;
47 this.configFile = configFile;
48 this.logFile = logFile;
49
50 saveReportAction = new SaveReportAction();
51
52 if( addToolbar )
53 add( buildToolbar(), BorderLayout.NORTH );
54
55 add( buildContent(), BorderLayout.CENTER );
56 }
57
58 public SaveReportAction getSaveReportAction()
59 {
60 return saveReportAction;
61 }
62
63 private JComponent buildToolbar()
64 {
65 JXToolBar toolbar = UISupport.createToolbar();
66
67 toolbar.addFixed( UISupport.createToolbarButton( saveReportAction ));
68 toolbar.addGlue();
69 toolbar.setBorder( BorderFactory.createEmptyBorder( 3, 3, 3, 3 ));
70
71 return toolbar;
72 }
73
74 private JComponent buildContent() throws Exception
75 {
76 JTabbedPane tabs = new JTabbedPane( JTabbedPane.BOTTOM );
77
78
79
80
81
82
83
84
85
86 JTextArea configContent = new JTextArea( );
87 configContent.setEditable( false );
88 configContent.setText( configFile );
89
90 browser = new BrowserComponent();
91 browser.navigate( reportFile.toURI().toURL().toString() );
92
93 tabs.addTab( "Report", browser.getComponent() );
94 tabs.addTab( "Config", new JScrollPane( configContent ));
95
96 if( logFile != null )
97 {
98 String logFileContent = XmlObject.Factory.parse( logFile ).toString();
99 JTextArea logContent = new JTextArea( );
100 logContent.setEditable( false );
101 logContent.setText( logFileContent );
102
103 tabs.addTab( "Log", new JScrollPane( logContent ));
104 }
105
106 return UISupport.createTabPanel( tabs, true );
107 }
108
109 public class SaveReportAction extends AbstractAction
110 {
111 public SaveReportAction()
112 {
113 putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/export.gif"));
114 putValue( Action.SHORT_DESCRIPTION, "Saves this report to a file" );
115 }
116
117 public void actionPerformed(ActionEvent e)
118 {
119 File file = UISupport.getFileDialogs().saveAs( this, "Save Report", "html", "HTML files", null );
120 if( file == null )
121 return;
122
123 try
124 {
125 FileWriter writer = new FileWriter( file );
126 writer.write( browser.getContent() );
127 writer.close();
128
129 UISupport.showInfoMessage( "Report saved to [" + file.getAbsolutePath() + "]" );
130 }
131 catch (Exception e1)
132 {
133 SoapUI.logError( e1 );
134 }
135 }
136 }
137 }