KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hsqldb > util > DatabaseManagerSwing


1 /* Copyright (c) 1995-2000, The Hypersonic SQL Group.
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * Neither the name of the Hypersonic SQL Group nor the names of its
15  * contributors may be used to endorse or promote products derived from this
16  * software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE HYPERSONIC SQL GROUP,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * This software consists of voluntary contributions made by many individuals
31  * on behalf of the Hypersonic SQL Group.
32  *
33  *
34  * For work added by the HSQL Development Group:
35  *
36  * Copyright (c) 2001-2005, The HSQL Development Group
37  * All rights reserved.
38  *
39  * Redistribution and use in source and binary forms, with or without
40  * modification, are permitted provided that the following conditions are met:
41  *
42  * Redistributions of source code must retain the above copyright notice, this
43  * list of conditions and the following disclaimer.
44  *
45  * Redistributions in binary form must reproduce the above copyright notice,
46  * this list of conditions and the following disclaimer in the documentation
47  * and/or other materials provided with the distribution.
48  *
49  * Neither the name of the HSQL Development Group nor the names of its
50  * contributors may be used to endorse or promote products derived from this
51  * software without specific prior written permission.
52  *
53  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
54  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56  * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
57  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
58  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
59  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
60  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
61  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
63  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64  */

65
66
67 package org.hsqldb.util;
68
69 import java.io.File JavaDoc;
70 import java.io.FileInputStream JavaDoc;
71 import java.io.FileOutputStream JavaDoc;
72 import java.io.IOException JavaDoc;
73 import java.lang.reflect.Constructor JavaDoc;
74 import java.lang.reflect.InvocationTargetException JavaDoc;
75 import java.sql.Connection JavaDoc;
76 import java.sql.DatabaseMetaData JavaDoc;
77 import java.sql.Driver JavaDoc;
78 import java.sql.DriverManager JavaDoc;
79 import java.sql.ResultSet JavaDoc;
80 import java.sql.ResultSetMetaData JavaDoc;
81 import java.sql.SQLException JavaDoc;
82 import java.sql.Statement JavaDoc;
83 import java.text.DecimalFormat JavaDoc;
84 import java.util.ArrayList JavaDoc;
85 import java.util.HashMap JavaDoc;
86 import java.util.HashSet JavaDoc;
87 import java.util.Hashtable JavaDoc;
88 import java.util.Iterator JavaDoc;
89 import java.util.Locale JavaDoc;
90 import java.util.Properties JavaDoc;
91 import java.util.Vector JavaDoc;
92 import java.awt.BorderLayout JavaDoc;
93 import java.awt.Cursor JavaDoc;
94 import java.awt.Dimension JavaDoc;
95 import java.awt.Event JavaDoc;
96 import java.awt.Font JavaDoc;
97 import java.awt.Insets JavaDoc;
98 import java.awt.Toolkit JavaDoc;
99 import java.awt.event.ActionEvent JavaDoc;
100 import java.awt.event.ActionListener JavaDoc;
101 import java.awt.event.KeyEvent JavaDoc;
102 import java.awt.event.KeyListener JavaDoc;
103 import java.awt.event.WindowEvent JavaDoc;
104 import java.awt.event.WindowListener JavaDoc;
105 import java.awt.Component JavaDoc;
106 import java.awt.Container JavaDoc;
107
108 import javax.swing.ButtonGroup JavaDoc;
109 import javax.swing.ImageIcon JavaDoc;
110 import javax.swing.JApplet JavaDoc;
111 import javax.swing.JButton JavaDoc;
112 import javax.swing.JCheckBoxMenuItem JavaDoc;
113 import javax.swing.JComponent JavaDoc;
114 import javax.swing.JFileChooser JavaDoc;
115 import javax.swing.JFrame JavaDoc;
116 import javax.swing.JLabel JavaDoc;
117 import javax.swing.JMenu JavaDoc;
118 import javax.swing.JMenuBar JavaDoc;
119 import javax.swing.JMenuItem JavaDoc;
120 import javax.swing.JOptionPane JavaDoc;
121 import javax.swing.JPanel JavaDoc;
122 import javax.swing.JRadioButtonMenuItem JavaDoc;
123 import javax.swing.JScrollPane JavaDoc;
124 import javax.swing.JSplitPane JavaDoc;
125 import javax.swing.JTable JavaDoc;
126 import javax.swing.JTextArea JavaDoc;
127 import javax.swing.JToolBar JavaDoc;
128 import javax.swing.JTree JavaDoc;
129 import javax.swing.KeyStroke JavaDoc;
130 import javax.swing.SwingUtilities JavaDoc;
131 import javax.swing.table.TableModel JavaDoc;
132 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
133 import javax.swing.tree.DefaultTreeModel JavaDoc;
134 import javax.swing.tree.MutableTreeNode JavaDoc;
135 import javax.swing.RootPaneContainer JavaDoc;
136
137 import java.security.AccessControlException JavaDoc;
138
139 import org.hsqldb.lib.java.JavaSystem;
140
141 //dmarshall@users - 20020101 - original swing port of DatabaseManager
142
//sqlbob@users 20020401 - patch 537501 by ulrivo - commandline arguments
143
//sqlbob@users 20020407 - patch 1.7.0 - reengineering and enhancements
144
//nickferguson@users 20021005 - patch 1.7.1 - enhancements
145
//deccles@users 20040412 - patch 933671 - various bug fixes
146
//deccles@users 2004xxxx - enhancements
147
//weconsultants@users 20041109 - version 1.8.0 - reengineering and enhancements:
148
// Added: Goodies 'Look and Feel'.
149
// Added: a Font Changer(Font Type\Style).
150
// Added: a Color Changer (foreground\bckground).
151
// Added: RowCounts for each JTree table nodes.
152
// Added: OneTouchExpandable attribute to JSplitPanes.
153
// Moved: setFramePositon code to a CommonSwing.setFramePositon() Method.
154
// Added: call to new method to handle exception processing (CommonSwing.errorMessage());
155
// Added: Added a new pane added at the bottom of the Frame. (Status Icon and StatusLine).
156
// Added: 2 Methods (setStatusMessage()), one overrides the other. One to change the ruung status
157
// another to allow a message to be posted without changing the Status Icon if needed.
158
// Added: Added a customCursor for the current wait cursor
159
// Added: Ability to switch the current LAF while runing (Native,Java or Motif)
160
//unsaved@users 2005xxxx - improvements and bug fixes
161

162 /**
163  * Swing Tool for managing a JDBC database.<p>
164  * <pre>
165  * Usage: java DatabaseManagerSwing [--options]
166  * where options include:
167  * --driver <classname> jdbc driver class
168  * --url <name> jdbc url
169  * --user <name> username used for connection
170  * --password <password> password for this user
171  * --dir <path> default directory
172  * --script <file> reads from script file
173  * --urlid <urlid> get connection info from RC file
174  * --rcfile <file> use instead of default (with urlid)
175  * --noexit Don't exit JVM
176  * </pre>
177  *
178  * Note that the sys-table switch will not work for Oracle, because Oracle
179  * does not categorize their system tables correctly in the JDBC Metadata.
180  *
181  * New class based on Hypersonic SQL original
182  *
183  * @author dmarshall@users
184  * @version 1.8.0
185  * @since 1.7.0
186  */

187 public class DatabaseManagerSwing extends JApplet JavaDoc
188 implements ActionListener JavaDoc, WindowListener JavaDoc, KeyListener JavaDoc {
189
190     /*
191      * This is down here because it is an implementation note, not a
192      * Javadoc comment!
193      * Tue Apr 26 16:38:54 EDT 2005
194      * Switched default switch method from "-switch" to "--switch" because
195      * "-switch" usage is ambiguous as used here. Single switches should
196      * be reserved for single-letter switches which can be mixed like
197      * "-u -r -l" = "-url". -blaine
198      */

199     private static String JavaDoc homedir = null;
200
201     static {
202         try {
203             Class JavaDoc c = Class.forName("sun.security.action.GetPropertyAction");
204             Constructor JavaDoc constructor = c.getConstructor(new Class JavaDoc[]{
205                 String JavaDoc.class });
206             java.security.PrivilegedAction JavaDoc a =
207                 (java.security.PrivilegedAction JavaDoc) constructor.newInstance(
208                     new Object JavaDoc[]{ "user.home" });
209
210             homedir = (String JavaDoc) java.security.AccessController.doPrivileged(a);
211         } catch (IllegalAccessException JavaDoc e) {
212             System.err.println(
213                 "Failed to get home directory.\n"
214                 + "Therefore not retrieving/storing user preferences.\n("
215                 + e.getMessage() + ')');
216         } catch (NoSuchMethodException JavaDoc e) {
217             System.err.println(
218                 "Failed to get home directory.\n"
219                 + "Therefore not retrieving/storing user preferences.\n("
220                 + e.getMessage() + ')');
221         } catch (ClassNotFoundException JavaDoc e) {
222             System.err.println(
223                 "Failed to get home directory.\n"
224                 + "Therefore not retrieving/storing user preferences.\n("
225                 + e.getMessage() + ')');
226         } catch (InstantiationException JavaDoc e) {
227             System.err.println(
228                 "Failed to get home directory.\n"
229                 + "Therefore not retrieving/storing user preferences.\n("
230                 + e.getMessage() + ')');
231         } catch (InvocationTargetException JavaDoc e) {
232             System.err.println(
233                 "Failed to get home directory.\n"
234                 + "Therefore not retrieving/storing user preferences.\n("
235                 + e.getMessage() + ')');
236         } catch (AccessControlException JavaDoc e) {
237             System.err.println(
238                 "Failed to get home directory.\n"
239                 + "Therefore not retrieving/storing user preferences.\n("
240                 + e.getMessage() + ')');
241         }
242     }
243
244     ArrayList JavaDoc localActionList = new ArrayList JavaDoc();
245     private JFrame JavaDoc jframe = null;
246     private static final String JavaDoc DEFAULT_RCFILE = homedir + "/dbmanager.rc";
247     private static final String JavaDoc HELP_TEXT =
248         "See the forums, mailing lists, and HSQLDB User Guide\n"
249         + "at http://hsqldb.org.\n\n"
250         + "Please paste the following version identifier with any\n"
251         + "problem reports or help requests: $Revision: 1.69 $";
252     private static final String JavaDoc ABOUT_TEXT =
253         "$Revision: 1.69 $ of DatabaseManagerSwing\n\n"
254         + "Copyright (c) 1995-2000, The Hypersonic SQL Group.\n"
255         + "Copyright (c) 2001-2005, The HSQL Development Group.\n"
256         + "http://hsqldb.org\n\n\n"
257         + "You may use and redistribute according to the HSQLDB\n"
258         + "license documented in the source code and at the web\n"
259         + "site above.";
260     static final String JavaDoc NL = System.getProperty("line.separator");
261     static final String JavaDoc NULL_STR = "[null]";
262     static int iMaxRecent = 24;
263     Connection JavaDoc cConn;
264     Connection JavaDoc rowConn; // holds the connetion for getting table row counts
265
DatabaseMetaData JavaDoc dMeta;
266     Statement JavaDoc sStatement;
267     JMenu JavaDoc mRecent;
268     String JavaDoc[] sRecent;
269     int iRecent;
270     JTextArea JavaDoc txtCommand;
271     JScrollPane JavaDoc txtCommandScroll;
272     JButton JavaDoc butExecute;
273     JTree JavaDoc tTree;
274     JScrollPane JavaDoc tScrollPane;
275     DefaultTreeModel JavaDoc treeModel;
276     TableModel JavaDoc tableModel;
277     DefaultMutableTreeNode JavaDoc rootNode;
278     JPanel JavaDoc pResult;
279     long lTime;
280     GridSwing gResult;
281
282     /**
283      * I think this is used to store model info whether we're using Grid
284      * output or not (this object is queried for data to display for
285      * text output mode).
286      * If so, the presentation-independent model part should be moved
287      * to an appropriately-named class instead of storing pure data in
288      * a Swing-specific class.
289      */

290     JTable JavaDoc gResultTable;
291     JScrollPane JavaDoc gScrollPane;
292     JTextArea JavaDoc txtResult;
293     JScrollPane JavaDoc txtResultScroll;
294     JSplitPane JavaDoc nsSplitPane; // Contains query over results
295
JSplitPane JavaDoc ewSplitPane; // Contains tree beside nsSplitPane
296
boolean bHelp;
297     RootPaneContainer JavaDoc fMain;
298     static boolean bMustExit;
299
300     /** Value of this variable only retained if huge input script read in. */
301     String JavaDoc sqlScriptBuffer = null;
302     JToolBar JavaDoc jtoolbar;
303     private boolean showSchemas = true;
304     private boolean showTooltips = true;
305     private boolean autoRefresh = true;
306     private boolean gridFormat = true;
307
308     // Added: (weconsultants@users)
309
static DatabaseManagerSwing refForFontDialogSwing;
310     boolean displayRowCounts = false;
311     boolean showSys = false;
312     boolean showIndexDetails = true;
313     String JavaDoc currentLAF = null;
314     JPanel JavaDoc pStatus;
315     static JButton JavaDoc iReadyStatus;
316     JRadioButtonMenuItem JavaDoc rbAllSchemas = new JRadioButtonMenuItem JavaDoc("*");
317     JMenuItem JavaDoc mitemAbout = new JMenuItem JavaDoc("About", 'A');
318     JMenuItem JavaDoc mitemHelp = new JMenuItem JavaDoc("Help", 'H');
319     JMenuItem JavaDoc mitemUpdateSchemas = new JMenuItem JavaDoc("Update Schemas");
320     JCheckBoxMenuItem JavaDoc boxAutoCommit =
321         new JCheckBoxMenuItem JavaDoc(AUTOCOMMIT_BOX_TEXT);
322     JCheckBoxMenuItem JavaDoc boxLogging = new JCheckBoxMenuItem JavaDoc(LOGGING_BOX_TEXT);
323     JCheckBoxMenuItem JavaDoc boxShowSchemas =
324         new JCheckBoxMenuItem JavaDoc(SHOWSCHEMAS_BOX_TEXT);
325     JCheckBoxMenuItem JavaDoc boxAutoRefresh =
326         new JCheckBoxMenuItem JavaDoc(AUTOREFRESH_BOX_TEXT);
327     JCheckBoxMenuItem JavaDoc boxTooltips = new JCheckBoxMenuItem JavaDoc(SHOWTIPS_BOX_TEXT);
328     JCheckBoxMenuItem JavaDoc boxRowCounts =
329         new JCheckBoxMenuItem JavaDoc(ROWCOUNTS_BOX_TEXT);
330     JCheckBoxMenuItem JavaDoc boxShowGrid = new JCheckBoxMenuItem JavaDoc(GRID_BOX_TEXT);
331     JCheckBoxMenuItem JavaDoc boxShowSys = new JCheckBoxMenuItem JavaDoc(SHOWSYS_BOX_TEXT);
332
333     // Consider adding GTK and Plaf L&Fs.
334
JRadioButtonMenuItem JavaDoc rbNativeLF =
335         new JRadioButtonMenuItem JavaDoc("Native Look & Feel");
336     JRadioButtonMenuItem JavaDoc rbJavaLF =
337         new JRadioButtonMenuItem JavaDoc("Java Look & Feel");
338     JRadioButtonMenuItem JavaDoc rbMotifLF =
339         new JRadioButtonMenuItem JavaDoc("Motif Look & Feel");
340     JLabel JavaDoc jStatusLine;
341     static String JavaDoc READY_STATUS = "Ready";
342     private static final String JavaDoc AUTOCOMMIT_BOX_TEXT = "Autocommit mode";
343     private static final String JavaDoc LOGGING_BOX_TEXT = "Logging mode";
344     private static final String JavaDoc SHOWSCHEMAS_BOX_TEXT = "Show schemas";
345     private static final String JavaDoc AUTOREFRESH_BOX_TEXT = "Auto-refresh tree";
346     private static final String JavaDoc SHOWTIPS_BOX_TEXT = "Show Tooltips";
347     private static final String JavaDoc ROWCOUNTS_BOX_TEXT = "Show row counts";
348     private static final String JavaDoc SHOWSYS_BOX_TEXT = "Show system tables";
349     private static final String JavaDoc GRID_BOX_TEXT =
350         "Show results in Grid (a.o.t. Text)";
351
352     // variables to hold the default cursors for these top level swing objects
353
// so we can restore them when we exit our thread
354
Cursor JavaDoc fMainCursor;
355     Cursor JavaDoc txtCommandCursor;
356     Cursor JavaDoc txtResultCursor;
357     HashMap JavaDoc tipMap = new HashMap JavaDoc();
358     private JMenu JavaDoc mnuSchemas = new JMenu JavaDoc("Schemas");
359
360     /**
361      * Wait Cursor
362      */

363
364     // Changed: (weconsultants@users): commonted out the, out of the box, cursor to use a custom cursor
365
private final Cursor JavaDoc waitCursor = new Cursor JavaDoc(Cursor.WAIT_CURSOR);
366
367     //getToolkit().createCustomCursor(CommonSwing.getIcon("SystemCursor"),
368
// new Point(4, 4), "HourGlass cursor");
369
// (ulrivo): variables set by arguments from the commandline
370
static String JavaDoc defDriver = "org.hsqldb.jdbcDriver";
371     static String JavaDoc defURL = "jdbc:hsqldb:.";
372     static String JavaDoc defUser = "sa";
373     static String JavaDoc defPassword = "";
374     static String JavaDoc defScript;
375     static String JavaDoc defDirectory;
376     private String JavaDoc schemaFilter = null;
377
378     public DatabaseManagerSwing() {
379         jframe = new JFrame JavaDoc("HSQLDB DatabaseManager");
380         fMain = jframe;
381     }
382     ;
383
384     public DatabaseManagerSwing(JFrame JavaDoc frameIn) {
385         jframe = frameIn;
386         fMain = jframe;
387     }
388     ;
389
390     public void init() {
391
392         javax.swing.AbstractButton JavaDoc btn;
393
394         fMain = this;
395
396         main();
397
398         for (int i = 0; i < localActionList.size(); i++) {
399             btn = (javax.swing.AbstractButton JavaDoc) localActionList.get(i);
400
401             btn.setEnabled(false);
402         }
403
404         Connection JavaDoc c = null;
405         boolean auto = false;
406
407         if (getParameter("jdbcDriver") != null) {
408             auto = true;
409             defDriver = getParameter("jdbcDriver");
410         }
411
412         if (getParameter("jdbcUrl") != null) {
413             auto = true;
414             defURL = getParameter("jdbcUrl");
415         }
416
417         if (getParameter("jdbcUser") != null) {
418             auto = true;
419             defUser = getParameter("jdbcUser");
420         }
421
422         if (getParameter("jdbcPassword") != null) {
423             auto = true;
424             defPassword = getParameter("jdbcPassword");
425         }
426
427         try {
428             setWaiting("Initializing");
429
430             //insertTestData();
431
//updateAutoCommitBox();
432
c = (auto
433                  ? ConnectionDialogSwing.createConnection(defDriver, defURL,
434                      defUser, defPassword)
435                  : ConnectionDialogSwing.createConnection(jframe, "Connect"));
436         } catch (Exception JavaDoc e) {
437
438             // Added: (weconsultants@users)
439
CommonSwing.errorMessage(e);
440         } finally {
441             setWaiting(null);
442         }
443
444         if (c != null) {
445             connect(c);
446         }
447
448         if (getParameter("loadSampleData") != null
449                 && getParameter("loadSampleData").equals("true")) {
450             insertTestData();
451
452             try {
453                 Thread.sleep(1000);
454             } catch (InterruptedException JavaDoc ie) {}
455             ;
456
457             // I don't know why, but the tree refresh below sometimes
458
// doesn't show all tables unless I put this delay here.
459
refreshTree();
460         }
461
462         if (getParameter("schemaFilter") != null) {
463             schemaFilter = getParameter("schemaFilter");
464         }
465     }
466
467     public static void main(String JavaDoc[] arg) {
468
469         System.getProperties().put("sun.java2d.noddraw", "true");
470
471         // (ulrivo): read all arguments from the command line
472
String JavaDoc lowerArg;
473         String JavaDoc urlid = null;
474         String JavaDoc rcFile = null;
475         boolean autoConnect = false;
476         boolean urlidConnect = false;
477
478         bMustExit = true;
479
480         for (int i = 0; i < arg.length; i++) {
481             lowerArg = arg[i].toLowerCase();
482
483             if (lowerArg.length() > 1 && lowerArg.charAt(1) == '-') {
484                 lowerArg = lowerArg.substring(1);
485             }
486
487             i++;
488
489             if (lowerArg.equals("-driver")) {
490                 defDriver = arg[i];
491                 autoConnect = true;
492             } else if (lowerArg.equals("-url")) {
493                 defURL = arg[i];
494                 autoConnect = true;
495             } else if (lowerArg.equals("-user")) {
496                 defUser = arg[i];
497                 autoConnect = true;
498             } else if (lowerArg.equals("-password")) {
499                 defPassword = arg[i];
500                 autoConnect = true;
501             } else if (lowerArg.equals("-urlid")) {
502                 urlid = arg[i];
503                 urlidConnect = true;
504             } else if (lowerArg.equals("-rcfile")) {
505                 rcFile = arg[i];
506                 urlidConnect = true;
507             } else if (lowerArg.equals("-dir")) {
508                 defDirectory = arg[i];
509             } else if (lowerArg.equals("-script")) {
510                 defScript = arg[i];
511             } else if (lowerArg.equals("-noexit")) {
512                 bMustExit = false;
513
514                 i--;
515             } else {
516                 showUsage();
517
518                 return;
519             }
520         }
521
522         DatabaseManagerSwing m =
523             new DatabaseManagerSwing(new JFrame JavaDoc("HSQL Database Manager"));
524
525         // Added: (weconsultants@users): Need databaseManagerSwing for later Reference
526
refForFontDialogSwing = m;
527
528         m.main();
529
530         Connection JavaDoc c = null;
531
532         m.setWaiting("Initializing");
533
534         try {
535             if (autoConnect && urlidConnect) {
536                 throw new IllegalArgumentException JavaDoc(
537                     "You may not specify both (urlid) AND (url/user/password).");
538             }
539
540             if (autoConnect) {
541                 c = ConnectionDialogSwing.createConnection(defDriver, defURL,
542                         defUser, defPassword);
543             } else if (urlidConnect) {
544                 if (urlid == null) {
545                     throw new IllegalArgumentException JavaDoc(
546                         "You must specify an 'urlid' to use an RC file");
547                 }
548
549                 autoConnect = true;
550
551                 String JavaDoc rcfilepath = (rcFile == null) ? DEFAULT_RCFILE
552                                                      : rcFile;
553                 RCData rcdata = new RCData(new File JavaDoc(rcfilepath), urlid);
554
555                 c = rcdata.getConnection(
556                     null, System.getProperty("sqlfile.charset"),
557                     System.getProperty("javax.net.ssl.trustStore"));
558             } else {
559                 c = ConnectionDialogSwing.createConnection(m.jframe,
560                         "Connect");
561             }
562         } catch (Exception JavaDoc e) {
563
564             // Added: (weconsultants@users)
565
CommonSwing.errorMessage(e);
566         } finally {
567             m.setWaiting(null);
568         }
569
570         if (c != null) {
571             m.connect(c);
572         }
573
574         // Added: (weconsultants@users): For preloadng FontDialogSwing
575
FontDialogSwing.CreatFontDialog(refForFontDialogSwing);
576         m.start();
577     }
578
579     /**
580      * This stuff is all quick, except for the refreshTree().
581      * This unit can be kicked off in main Gui thread. The refreshTree
582      * will be backgrounded and this method will return.
583      */

584     public void connect(Connection JavaDoc c) {
585
586         schemaFilter = null;
587
588         if (c == null) {
589             return;
590         }
591
592         if (cConn != null) {
593             try {
594                 cConn.close();
595             } catch (SQLException JavaDoc e) {
596
597                 // Added: (weconsultants@users)
598
CommonSwing.errorMessage(e);
599             }
600         }
601
602         cConn = c;
603
604         // Added: (weconsultants@users) Need to barrow to get the table rowcounts
605
rowConn = c;
606
607         try {
608             dMeta = cConn.getMetaData();
609             sStatement = cConn.createStatement();
610
611             updateAutoCommitBox();
612
613             // Workaround for EXTREME SLOWNESS getting this info from O.
614
showIndexDetails =
615                 (dMeta.getDatabaseProductName().indexOf("Oracle") < 0);
616
617             Driver JavaDoc driver = DriverManager.getDriver(dMeta.getURL());
618             ConnectionSetting newSetting = new ConnectionSetting(
619                 dMeta.getDatabaseProductName(), driver.getClass().getName(),
620                 dMeta.getURL(),
621                 dMeta.getUserName().replaceAll("@localhost", ""), "");
622             Hashtable JavaDoc settings =
623                 ConnectionDialogCommon.loadRecentConnectionSettings();
624
625             ConnectionDialogCommon.addToRecentConnectionSettings(settings,
626                     newSetting);
627             ConnectionDialogSwing.setConnectionSetting(newSetting);
628             refreshTree();
629             clearResultPanel();
630
631             if (fMain instanceof JApplet JavaDoc) {
632                 getAppletContext().showStatus(
633                     "JDBC Connection established to a "
634                     + dMeta.getDatabaseProductName() + " v. "
635                     + dMeta.getDatabaseProductVersion() + " database as '"
636                     + dMeta.getUserName() + "'.");
637             }
638         } catch (SQLException JavaDoc e) {
639
640             // Added: (weconsultants@users)
641
CommonSwing.errorMessage(e);
642         } catch (IOException JavaDoc e) {
643
644             // Added: (weconsultants@users)
645
CommonSwing.errorMessage(e);
646         } catch (Exception JavaDoc e) {
647             CommonSwing.errorMessage(e);
648         }
649     }
650
651     private static void showUsage() {
652
653         System.out.println(
654             "Usage: java DatabaseManagerSwing [--options]\n"
655             + "where options include:\n"
656             + " --driver <classname> jdbc driver class\n"
657             + " --url <name> jdbc url\n"
658             + " --user <name> username used for connection\n"
659             + " --password <password> password for this user\n"
660             + " --urlid <urlid> use url/user/password/driver in rc file\n"
661             + " --rcfile <file> (defaults to 'dbmanager.rc' in home dir)\n"
662             + " --dir <path> default directory\n"
663             + " --script <file> reads from script file\n"
664             + " --noexit do not call system.exit()\n"
665             + "(Single-hypen switches like '-driver' are also supported)");
666     }
667
668     private void insertTestData() {
669
670         try {
671             DatabaseManagerCommon.createTestTables(sStatement);
672             txtCommand.setText(
673                 DatabaseManagerCommon.createTestData(sStatement));
674
675             for (int i = 0; i < DatabaseManagerCommon.testDataSql.length;
676                     i++) {
677                 addToRecent(DatabaseManagerCommon.testDataSql[i]);
678             }
679
680             executeCurrentSQL();
681         } catch (SQLException JavaDoc e) {
682
683             // Added: (weconsultants@users)
684
CommonSwing.errorMessage(e);
685         }
686     }
687
688     public void setMustExit(boolean b) {
689         this.bMustExit = b;
690     }
691
692     private DBMPrefs prefs = null;
693
694     public void main() {
695
696         JMenu JavaDoc jmenu;
697         JMenuItem JavaDoc mitem;
698
699         try {
700             prefs = new DBMPrefs(fMain instanceof JApplet JavaDoc);
701         } catch (Exception JavaDoc e) {
702             System.err.println(
703                 "Failed to load preferences. Proceeding with defaults:\n");
704         }
705
706         if (prefs == null) {
707             setLF(CommonSwing.Native);
708         } else {
709             autoRefresh = prefs.autoRefresh;
710             displayRowCounts = prefs.showRowCounts;
711             showSys = prefs.showSysTables;
712             showSchemas = prefs.showSchemas;
713             gridFormat = prefs.resultGrid;
714             showTooltips = prefs.showTooltips;
715
716             setLF(prefs.laf);
717         }
718
719         // (ulrivo): An actual icon. N.b., this adds some tips to the tip map
720
fMain.getContentPane().add(createToolBar(), "North");
721
722         if (fMain instanceof java.awt.Frame JavaDoc) {
723             ((java.awt.Frame JavaDoc) fMain).setIconImage(
724                 CommonSwing.