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