Source Code Cross Referenced for ExecuteSqlDialog.java in  » Database-Client » SQL-Workbench » workbench » gui » sql » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » SQL Workbench » workbench.gui.sql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ExecuteSqlDialog.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.sql;
013:
014:        import java.awt.BorderLayout;
015:        import java.awt.Dimension;
016:        import java.awt.EventQueue;
017:        import java.awt.FlowLayout;
018:        import java.awt.Frame;
019:        import java.awt.event.ActionListener;
020:        import java.awt.event.WindowListener;
021:        import java.sql.Statement;
022:
023:        import javax.swing.JDialog;
024:        import javax.swing.JLabel;
025:        import javax.swing.JPanel;
026:        import javax.swing.border.EtchedBorder;
027:
028:        import workbench.db.WbConnection;
029:        import workbench.util.ExceptionUtil;
030:        import workbench.gui.WbSwingUtilities;
031:        import workbench.gui.components.WbButton;
032:        import workbench.resource.ResourceMgr;
033:        import workbench.resource.Settings;
034:        import workbench.util.WbThread;
035:
036:        /**
037:         *
038:         * @author  support@sql-workbench.net
039:         */
040:        public class ExecuteSqlDialog extends JDialog implements 
041:                ActionListener, WindowListener {
042:            protected WbConnection dbConn;
043:            protected EditorPanel sqlEditor;
044:            protected WbButton startButton = new WbButton(ResourceMgr
045:                    .getString("LblStartSql"));
046:            protected WbButton closeButton = new WbButton(ResourceMgr
047:                    .getString("LblClose"));
048:            protected JLabel statusMessage;
049:            private Thread worker;
050:
051:            /** Creates a new instance of ExecuteSqlDialog */
052:            public ExecuteSqlDialog(Frame owner, String aTitle, String sql,
053:                    final String highlight, WbConnection aConnection) {
054:                super (owner, aTitle, true);
055:                this .dbConn = aConnection;
056:                this .getContentPane().setLayout(new BorderLayout());
057:                JPanel buttonPanel = new JPanel();
058:                buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
059:                this .startButton.addActionListener(this );
060:                this .closeButton.addActionListener(this );
061:                buttonPanel.add(startButton);
062:                buttonPanel.add(closeButton);
063:                JPanel mainPanel = new JPanel();
064:                sqlEditor = EditorPanel.createSqlEditor();
065:                sqlEditor.showFormatSql();
066:                mainPanel.setLayout(new BorderLayout());
067:                mainPanel.add(sqlEditor, BorderLayout.CENTER);
068:                sqlEditor.setDatabaseConnection(this .dbConn);
069:                sqlEditor.setText(sql);
070:
071:                this .statusMessage = new JLabel("");
072:                this .statusMessage.setBorder(new EtchedBorder());
073:                this .statusMessage.setMaximumSize(new Dimension(32768, 22));
074:                this .statusMessage.setMinimumSize(new Dimension(10, 22));
075:                this .statusMessage.setPreferredSize(new Dimension(60, 22));
076:                mainPanel.add(this .statusMessage, BorderLayout.SOUTH);
077:                this .getContentPane().add(mainPanel, BorderLayout.CENTER);
078:                this .getContentPane().add(buttonPanel, BorderLayout.SOUTH);
079:                if (!Settings.getInstance().restoreWindowSize(this ,
080:                        this .getClass().getName())) {
081:                    this .setSize(500, 400);
082:                }
083:                this .addWindowListener(this );
084:
085:                WbSwingUtilities.center(this , owner);
086:                EventQueue.invokeLater(new Runnable() {
087:                    public void run() {
088:                        highlightText(highlight);
089:                    }
090:                });
091:            }
092:
093:            public void setStartButtonText(String aText) {
094:                this .startButton.setText(aText);
095:            }
096:
097:            private void highlightText(String aText) {
098:                if (aText == null || aText.trim().length() == 0)
099:                    return;
100:                sqlEditor.reformatSql();
101:                sqlEditor.setCaretPosition(0);
102:                int start = sqlEditor.getReplacer().findFirst(aText, true,
103:                        true, false);
104:                int end = start + aText.length();
105:                if (start > -1) {
106:                    sqlEditor.select(start, end);
107:                }
108:                sqlEditor.requestFocusInWindow();
109:            }
110:
111:            public void closeWindow() {
112:                if (this .worker != null) {
113:                    this .worker.interrupt();
114:                    this .worker = null;
115:                }
116:                Settings.getInstance().storeWindowSize(this ,
117:                        this .getClass().getName());
118:                this .setVisible(false);
119:                this .dispose();
120:            }
121:
122:            private void startCreate() {
123:                if (this .dbConn == null)
124:                    return;
125:
126:                if (this .dbConn.isBusy()) {
127:                    WbSwingUtilities.showMessageKey(this , "ErrConnectionBusy");
128:                    return;
129:                }
130:                this .statusMessage.setText(ResourceMgr
131:                        .getString("MsgCreatingIndex"));
132:
133:                this .worker = new WbThread("Create index thread") {
134:                    public void run() {
135:                        Statement stmt = null;
136:                        try {
137:                            String sql = sqlEditor.getText().trim().replaceAll(
138:                                    ";", "");
139:                            dbConn.setBusy(true);
140:                            stmt = dbConn.createStatement();
141:                            stmt.executeUpdate(sql);
142:                            statusMessage.setText(ResourceMgr
143:                                    .getString("MsgIndexCreated"));
144:                            if (dbConn.shouldCommitDDL()) {
145:                                dbConn.commit();
146:                            }
147:                            EventQueue.invokeLater(new Runnable() {
148:                                public void run() {
149:                                    createSuccess();
150:                                }
151:                            });
152:                        } catch (Exception e) {
153:                            if (dbConn.shouldCommitDDL()) {
154:                                try {
155:                                    dbConn.rollback();
156:                                } catch (Throwable th) {
157:                                }
158:                            }
159:                            createFailure(e);
160:                        } finally {
161:                            dbConn.setBusy(false);
162:                            try {
163:                                stmt.close();
164:                            } catch (Throwable th) {
165:                            }
166:                        }
167:                    }
168:                };
169:                WbSwingUtilities.showWaitCursor(this );
170:                this .startButton.setEnabled(false);
171:                this .closeButton.setEnabled(false);
172:                this .sqlEditor.setEnabled(false);
173:                this .worker.start();
174:            }
175:
176:            protected void createSuccess() {
177:                createFinished();
178:                WbSwingUtilities.showMessage(this , ResourceMgr
179:                        .getString("MsgIndexCreated"));
180:                this .closeWindow();
181:            }
182:
183:            protected void createFinished() {
184:                WbSwingUtilities.showDefaultCursor(this );
185:                this .startButton.setEnabled(true);
186:                this .closeButton.setEnabled(true);
187:                this .sqlEditor.setEnabled(true);
188:                this .worker = null;
189:            }
190:
191:            protected void createFailure(Exception e) {
192:                createFinished();
193:                String error = ExceptionUtil.getDisplay(e);
194:                statusMessage.setText(error);
195:                String msg = ResourceMgr.getString("MsgCreateIndexError")
196:                        + "\n" + error;
197:                WbSwingUtilities.showErrorMessage(this , msg);
198:            }
199:
200:            public void actionPerformed(java.awt.event.ActionEvent e) {
201:                if (this .worker != null)
202:                    return;
203:                if (e.getSource() == this .closeButton) {
204:                    this .closeWindow();
205:                } else if (e.getSource() == this .startButton) {
206:                    this .startCreate();
207:                }
208:            }
209:
210:            public void windowActivated(java.awt.event.WindowEvent e) {
211:            }
212:
213:            public void windowClosed(java.awt.event.WindowEvent e) {
214:            }
215:
216:            public void windowClosing(java.awt.event.WindowEvent e) {
217:                if (this .worker == null)
218:                    this .closeWindow();
219:            }
220:
221:            public void windowDeactivated(java.awt.event.WindowEvent e) {
222:            }
223:
224:            public void windowDeiconified(java.awt.event.WindowEvent e) {
225:            }
226:
227:            public void windowIconified(java.awt.event.WindowEvent e) {
228:            }
229:
230:            public void windowOpened(java.awt.event.WindowEvent e) {
231:            }
232:
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.