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.support.DefaultHyperlinkListener;
34 import com.eviware.soapui.support.UISupport;
35 import com.eviware.soapui.support.components.JXToolBar;
36
37 public class WSIReportPanel extends JPanel
38 {
39 private File reportFile;
40 private JEditorPane editorPane;
41 private final String configFile;
42 private final File logFile;
43
44 public WSIReportPanel( File reportFile, String configFile, File logFile ) throws Exception
45 {
46 super( new BorderLayout() );
47
48 this.reportFile = reportFile;
49 this.configFile = configFile;
50 this.logFile = logFile;
51
52 add( buildToolbar(), BorderLayout.NORTH );
53 add( buildContent(), BorderLayout.CENTER );
54 }
55
56 private JComponent buildToolbar()
57 {
58 JXToolBar toolbar = UISupport.createToolbar();
59
60 toolbar.addFixed( UISupport.createToolbarButton( new SaveReportAction() ));
61 toolbar.addGlue();
62 toolbar.setBorder( BorderFactory.createEmptyBorder( 3, 3, 3, 3 ));
63
64 return toolbar;
65 }
66
67 private JComponent buildContent() throws Exception
68 {
69 JTabbedPane tabs = new JTabbedPane( JTabbedPane.BOTTOM );
70
71 editorPane = new JEditorPane();
72 editorPane.setEditorKit( new HTMLEditorKit() );
73 editorPane.setEditable( false );
74 editorPane.setPage( reportFile.toURL() );
75 editorPane.addHyperlinkListener( new DefaultHyperlinkListener( editorPane ));
76
77 JTextArea configContent = new JTextArea( );
78 configContent.setEditable( false );
79 configContent.setText( configFile );
80
81 tabs.addTab( "Report", new JScrollPane( editorPane ));
82 tabs.addTab( "Config", new JScrollPane( configContent ));
83
84 if( logFile != null )
85 {
86 String logFileContent = XmlObject.Factory.parse( logFile ).toString();
87 JTextArea logContent = new JTextArea( );
88 logContent.setEditable( false );
89 logContent.setText( logFileContent );
90
91 tabs.addTab( "Log", new JScrollPane( logContent ));
92 }
93
94 return UISupport.createTabPanel( tabs, true );
95 }
96
97 private class SaveReportAction extends AbstractAction
98 {
99 public SaveReportAction()
100 {
101 putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/export.gif"));
102 putValue( Action.SHORT_DESCRIPTION, "Saves this report to a file" );
103 }
104
105 public void actionPerformed(ActionEvent e)
106 {
107 File file = UISupport.getFileDialogs().saveAs( this, "Save Report", "html", "HTML files", null );
108 if( file == null )
109 return;
110
111 try
112 {
113 FileWriter writer = new FileWriter( file );
114 writer.write( editorPane.getText() );
115 writer.close();
116
117 UISupport.showInfoMessage( "Report saved to [" + file.getAbsolutePath() + "]" );
118 }
119 catch (Exception e1)
120 {
121 e1.printStackTrace();
122 }
123 }
124 }
125 }