001: /*
002: * ObjectCompilerUI.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.gui.dbobjects;
013:
014: import java.awt.BorderLayout;
015: import java.awt.EventQueue;
016: import java.awt.Window;
017: import java.awt.event.WindowListener;
018: import java.sql.SQLException;
019: import java.util.List;
020:
021: import javax.swing.JFrame;
022: import javax.swing.JPanel;
023:
024: import workbench.db.DbObject;
025: import workbench.db.WbConnection;
026: import workbench.db.oracle.OracleObjectCompiler;
027: import workbench.gui.WbSwingUtilities;
028: import workbench.gui.sql.EditorPanel;
029: import workbench.resource.ResourceMgr;
030: import workbench.resource.Settings;
031: import workbench.util.WbThread;
032:
033: /**
034: *
035: * @author support@sql-workbench.net
036: */
037: public class ObjectCompilerUI extends JPanel implements Runnable,
038: WindowListener {
039: private Thread worker;
040: protected EditorPanel log;
041: private JFrame window;
042: private List<DbObject> objects;
043: private OracleObjectCompiler compiler;
044: private WbConnection dbConnection;
045:
046: public ObjectCompilerUI(List<DbObject> objectList, WbConnection conn)
047: throws SQLException {
048: super ();
049: this .objects = objectList;
050: this .dbConnection = conn;
051: this .compiler = new OracleObjectCompiler(conn);
052: this .setLayout(new BorderLayout());
053: this .log = EditorPanel.createTextEditor();
054: this .add(this .log, BorderLayout.CENTER);
055: }
056:
057: private void startCompile() {
058: this .worker = new WbThread(this , "ObjectCompiler Thread");
059: this .worker.start();
060: }
061:
062: public void run() {
063: String msg = ResourceMgr.getString("TxtCompilingObject");
064: this .log.setText("");
065: int count = this .objects.size();
066: try {
067: this .dbConnection.setBusy(true);
068: for (int i = 0; i < count; i++) {
069: DbObject o = this .objects.get(i);
070: if (i > 0)
071: appendLog("\n");
072: appendLog(msg + " " + o.getObjectName() + "... ");
073: String error = this .compiler.compileObject(o);
074: if (error == null) {
075: appendLog(ResourceMgr.getString("TxtOK"));
076: } else {
077: appendLog(ResourceMgr.getString("TxtError")
078: + "\n " + error);
079: }
080: }
081: } finally {
082: this .dbConnection.setBusy(false);
083: }
084: this .log.setCaretPosition(0);
085: }
086:
087: private void appendLog(final String msg) {
088: EventQueue.invokeLater(new Runnable() {
089: public void run() {
090: log.appendLine(msg);
091: }
092: });
093: }
094:
095: public void show(Window aParent) {
096: if (this .window == null) {
097: this .window = new JFrame(ResourceMgr
098: .getString("TxtWindowTitleCompileStatus"));
099: this .window.getContentPane().setLayout(new BorderLayout());
100: this .window.getContentPane().add(this , BorderLayout.CENTER);
101: this .window.setIconImage(ResourceMgr.getImage("workbench")
102: .getImage());
103: if (!Settings.getInstance().restoreWindowSize(this .window,
104: ObjectCompilerUI.class.getName())) {
105: this .window.setSize(500, 400);
106: }
107:
108: if (!Settings.getInstance().restoreWindowPosition(
109: this .window, ObjectCompilerUI.class.getName())) {
110: WbSwingUtilities.center(this .window, aParent);
111: }
112: this .window.addWindowListener(this );
113: }
114: this .window.setVisible(true);
115: this .startCompile();
116: }
117:
118: public void windowActivated(java.awt.event.WindowEvent e) {
119: }
120:
121: public void windowClosed(java.awt.event.WindowEvent e) {
122: }
123:
124: public void windowClosing(java.awt.event.WindowEvent e) {
125: if (this .worker != null) {
126: this .worker.interrupt();
127: this .compiler.close();
128: this .compiler = null;
129: this .worker = null;
130: }
131: Settings.getInstance().storeWindowPosition(this .window,
132: ObjectCompilerUI.class.getName());
133: Settings.getInstance().storeWindowSize(this .window,
134: ObjectCompilerUI.class.getName());
135: this .window.setVisible(false);
136: this .window.dispose();
137: }
138:
139: public void windowDeactivated(java.awt.event.WindowEvent e) {
140: }
141:
142: public void windowDeiconified(java.awt.event.WindowEvent e) {
143: }
144:
145: public void windowIconified(java.awt.event.WindowEvent e) {
146: }
147:
148: public void windowOpened(java.awt.event.WindowEvent e) {
149: }
150:
151: }
|