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.actions.iface.tools.wsi;
014:
015: import java.awt.BorderLayout;
016: import java.awt.event.ActionEvent;
017: import java.io.File;
018: import java.io.FileWriter;
019:
020: import javax.swing.AbstractAction;
021: import javax.swing.Action;
022: import javax.swing.BorderFactory;
023: import javax.swing.JComponent;
024: import javax.swing.JEditorPane;
025: import javax.swing.JPanel;
026: import javax.swing.JScrollPane;
027: import javax.swing.JTabbedPane;
028: import javax.swing.JTextArea;
029: import javax.swing.text.html.HTMLEditorKit;
030:
031: import org.apache.xmlbeans.XmlObject;
032:
033: import com.eviware.soapui.SoapUI;
034: import com.eviware.soapui.support.DefaultHyperlinkListener;
035: import com.eviware.soapui.support.UISupport;
036: import com.eviware.soapui.support.components.JXToolBar;
037:
038: /**
039: * Panel for displaying a WS-I Report
040: *
041: * @author ole.matzura
042: */
043:
044: public class WSIReportPanel extends JPanel {
045: private File reportFile;
046: private JEditorPane editorPane;
047: private final String configFile;
048: private final File logFile;
049:
050: public WSIReportPanel(File reportFile, String configFile,
051: File logFile) throws Exception {
052: super (new BorderLayout());
053:
054: this .reportFile = reportFile;
055: this .configFile = configFile;
056: this .logFile = logFile;
057:
058: add(buildToolbar(), BorderLayout.NORTH);
059: add(buildContent(), BorderLayout.CENTER);
060: }
061:
062: private JComponent buildToolbar() {
063: JXToolBar toolbar = UISupport.createToolbar();
064:
065: toolbar.addFixed(UISupport
066: .createToolbarButton(new SaveReportAction()));
067: toolbar.addGlue();
068: toolbar.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
069:
070: return toolbar;
071: }
072:
073: private JComponent buildContent() throws Exception {
074: JTabbedPane tabs = new JTabbedPane(JTabbedPane.BOTTOM);
075:
076: editorPane = new JEditorPane();
077: editorPane.setEditorKit(new HTMLEditorKit());
078: editorPane.setEditable(false);
079: editorPane.setPage(reportFile.toURL());
080: editorPane.addHyperlinkListener(new DefaultHyperlinkListener(
081: editorPane));
082:
083: JTextArea configContent = new JTextArea();
084: configContent.setEditable(false);
085: configContent.setText(configFile);
086:
087: tabs.addTab("Report", new JScrollPane(editorPane));
088: tabs.addTab("Config", new JScrollPane(configContent));
089:
090: if (logFile != null) {
091: String logFileContent = XmlObject.Factory.parse(logFile)
092: .toString();
093: JTextArea logContent = new JTextArea();
094: logContent.setEditable(false);
095: logContent.setText(logFileContent);
096:
097: tabs.addTab("Log", new JScrollPane(logContent));
098: }
099:
100: return UISupport.createTabPanel(tabs, true);
101: }
102:
103: private class SaveReportAction extends AbstractAction {
104: public SaveReportAction() {
105: putValue(Action.SMALL_ICON, UISupport
106: .createImageIcon("/export.gif"));
107: putValue(Action.SHORT_DESCRIPTION,
108: "Saves this report to a file");
109: }
110:
111: public void actionPerformed(ActionEvent e) {
112: File file = UISupport.getFileDialogs().saveAs(this ,
113: "Save Report", "html", "HTML files", null);
114: if (file == null)
115: return;
116:
117: try {
118: FileWriter writer = new FileWriter(file);
119: writer.write(editorPane.getText());
120: writer.close();
121:
122: UISupport.showInfoMessage("Report saved to ["
123: + file.getAbsolutePath() + "]");
124: } catch (Exception e1) {
125: SoapUI.logError(e1);
126: }
127: }
128: }
129: }
|