01: /*
02: * SchemaReportAction.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.actions;
13:
14: import java.awt.Component;
15: import java.awt.EventQueue;
16: import java.awt.event.ActionEvent;
17: import java.util.List;
18: import javax.swing.JFrame;
19: import javax.swing.SwingUtilities;
20: import workbench.db.DbObject;
21: import workbench.db.WbConnection;
22: import workbench.db.report.SchemaReporter;
23: import workbench.gui.WbSwingUtilities;
24: import workbench.gui.dbobjects.DbObjectList;
25: import workbench.log.LogMgr;
26: import workbench.util.ExceptionUtil;
27: import workbench.util.FileDialogUtil;
28: import workbench.util.WbThread;
29:
30: /**
31: * @author support@sql-workbench.net
32: */
33: public class SchemaReportAction extends WbAction {
34: private DbObjectList client;
35:
36: public SchemaReportAction(DbObjectList list) {
37: initMenuDefinition("MnuTxtSchemaReport");
38: client = list;
39: }
40:
41: @Override
42: public void executeAction(ActionEvent e) {
43: saveReport();
44: }
45:
46: protected void saveReport() {
47: if (client == null)
48: return;
49:
50: final WbConnection dbConnection = client.getConnection();
51: final Component caller = client.getComponent();
52:
53: if (!WbSwingUtilities.checkConnection(caller, dbConnection))
54: return;
55: List<? extends DbObject> objects = client.getSelectedObjects();
56: if (objects == null)
57: return;
58:
59: FileDialogUtil dialog = new FileDialogUtil();
60:
61: String filename = dialog.getXmlReportFilename(client
62: .getComponent());
63: if (filename == null)
64: return;
65:
66: final SchemaReporter reporter = new SchemaReporter(client
67: .getConnection());
68: reporter.setShowProgress(true, (JFrame) SwingUtilities
69: .getWindowAncestor(caller));
70: reporter.setObjectList(objects);
71: reporter.setOutputFilename(filename);
72:
73: Thread t = new WbThread("Schema Report") {
74: public void run() {
75: try {
76: dbConnection.setBusy(true);
77: reporter.writeXml();
78: } catch (Throwable e) {
79: LogMgr.logError("TableListPanel.saveReport()",
80: "Error writing schema report", e);
81: final String msg = ExceptionUtil.getDisplay(e);
82: EventQueue.invokeLater(new Runnable() {
83: public void run() {
84: WbSwingUtilities.showErrorMessage(caller,
85: msg);
86: }
87: });
88: } finally {
89: dbConnection.setBusy(false);
90: }
91: }
92: };
93: t.start();
94: }
95:
96: }
|