📄 databasemanagerswing.java
字号:
/* Copyright (c) 1995-2000, The Hypersonic SQL Group.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Hypersonic SQL Group nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE HYPERSONIC SQL GROUP,
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Hypersonic SQL Group.
*
*
* For work added by the HSQL Development Group:
*
* Copyright (c) 2001-2005, The HSQL Development Group
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the HSQL Development Group nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.hsqldb.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Locale;
import java.util.Properties;
import java.util.Vector;
import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.Component;
import java.awt.Container;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JToolBar;
import javax.swing.JTree;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.table.TableModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import javax.swing.RootPaneContainer;
import java.security.AccessControlException;
import org.hsqldb.lib.java.JavaSystem;
//dmarshall@users - 20020101 - original swing port of DatabaseManager
//sqlbob@users 20020401 - patch 537501 by ulrivo - commandline arguments
//sqlbob@users 20020407 - patch 1.7.0 - reengineering and enhancements
//nickferguson@users 20021005 - patch 1.7.1 - enhancements
//deccles@users 20040412 - patch 933671 - various bug fixes
//deccles@users 2004xxxx - enhancements
//weconsultants@users 20041109 - version 1.8.0 - reengineering and enhancements:
// Added: Goodies 'Look and Feel'.
// Added: a Font Changer(Font Type\Style).
// Added: a Color Changer (foreground\bckground).
// Added: RowCounts for each JTree table nodes.
// Added: OneTouchExpandable attribute to JSplitPanes.
// Moved: setFramePositon code to a CommonSwing.setFramePositon() Method.
// Added: call to new method to handle exception processing (CommonSwing.errorMessage());
// Added: Added a new pane added at the bottom of the Frame. (Status Icon and StatusLine).
// Added: 2 Methods (setStatusMessage()), one overrides the other. One to change the ruung status
// another to allow a message to be posted without changing the Status Icon if needed.
// Added: Added a customCursor for the current wait cursor
// Added: Ability to switch the current LAF while runing (Native,Java or Motif)
//unsaved@users 2005xxxx - improvements and bug fixes
/**
* Swing Tool for managing a JDBC database.<p>
* <pre>
* Usage: java DatabaseManagerSwing [--options]
* where options include:
* --driver <classname> jdbc driver class
* --url <name> jdbc url
* --user <name> username used for connection
* --password <password> password for this user
* --dir <path> default directory
* --script <file> reads from script file
* --urlid <urlid> get connection info from RC file
* --rcfile <file> use instead of default (with urlid)
* --noexit Don't exit JVM
* </pre>
*
* Note that the sys-table switch will not work for Oracle, because Oracle
* does not categorize their system tables correctly in the JDBC Metadata.
*
* New class based on Hypersonic SQL original
*
* @author dmarshall@users
* @version 1.8.0
* @since 1.7.0
*/
public class DatabaseManagerSwing extends JApplet
implements ActionListener, WindowListener, KeyListener {
/*
* This is down here because it is an implementation note, not a
* Javadoc comment!
* Tue Apr 26 16:38:54 EDT 2005
* Switched default switch method from "-switch" to "--switch" because
* "-switch" usage is ambiguous as used here. Single switches should
* be reserved for single-letter switches which can be mixed like
* "-u -r -l" = "-url". -blaine
*/
private static String homedir = null;
static {
try {
Class c = Class.forName("sun.security.action.GetPropertyAction");
Constructor constructor = c.getConstructor(new Class[]{
String.class });
java.security.PrivilegedAction a =
(java.security.PrivilegedAction) constructor.newInstance(
new Object[]{ "user.home" });
homedir = (String) java.security.AccessController.doPrivileged(a);
} catch (IllegalAccessException e) {
System.err.println(
"Failed to get home directory.\n"
+ "Therefore not retrieving/storing user preferences.\n("
+ e.getMessage() + ')');
} catch (NoSuchMethodException e) {
System.err.println(
"Failed to get home directory.\n"
+ "Therefore not retrieving/storing user preferences.\n("
+ e.getMessage() + ')');
} catch (ClassNotFoundException e) {
System.err.println(
"Failed to get home directory.\n"
+ "Therefore not retrieving/storing user preferences.\n("
+ e.getMessage() + ')');
} catch (InstantiationException e) {
System.err.println(
"Failed to get home directory.\n"
+ "Therefore not retrieving/storing user preferences.\n("
+ e.getMessage() + ')');
} catch (InvocationTargetException e) {
System.err.println(
"Failed to get home directory.\n"
+ "Therefore not retrieving/storing user preferences.\n("
+ e.getMessage() + ')');
} catch (AccessControlException e) {
System.err.println(
"Failed to get home directory.\n"
+ "Therefore not retrieving/storing user preferences.\n("
+ e.getMessage() + ')');
}
}
ArrayList localActionList = new ArrayList();
private JFrame jframe = null;
private static final String DEFAULT_RCFILE = homedir + "/dbmanager.rc";
private static final String HELP_TEXT =
"See the forums, mailing lists, and HSQLDB User Guide\n"
+ "at http://hsqldb.org.\n\n"
+ "Please paste the following version identifier with any\n"
+ "problem reports or help requests: $Revision: 1.69 $";
private static final String ABOUT_TEXT =
"$Revision: 1.69 $ of DatabaseManagerSwing\n\n"
+ "Copyright (c) 1995-2000, The Hypersonic SQL Group.\n"
+ "Copyright (c) 2001-2005, The HSQL Development Group.\n"
+ "http://hsqldb.org\n\n\n"
+ "You may use and redistribute according to the HSQLDB\n"
+ "license documented in the source code and at the web\n"
+ "site above.";
static final String NL = System.getProperty("line.separator");
static final String NULL_STR = "[null]";
static int iMaxRecent = 24;
Connection cConn;
Connection rowConn; // holds the connetion for getting table row counts
DatabaseMetaData dMeta;
Statement sStatement;
JMenu mRecent;
String[] sRecent;
int iRecent;
JTextArea txtCommand;
JScrollPane txtCommandScroll;
JButton butExecute;
JTree tTree;
JScrollPane tScrollPane;
DefaultTreeModel treeModel;
TableModel tableModel;
DefaultMutableTreeNode rootNode;
JPanel pResult;
long lTime;
GridSwing gResult;
/**
* I think this is used to store model info whether we're using Grid
* output or not (this object is queried for data to display for
* text output mode).
* If so, the presentation-independent model part should be moved
* to an appropriately-named class instead of storing pure data in
* a Swing-specific class.
*/
JTable gResultTable;
JScrollPane gScrollPane;
JTextArea txtResult;
JScrollPane txtResultScroll;
JSplitPane nsSplitPane; // Contains query over results
JSplitPane ewSplitPane; // Contains tree beside nsSplitPane
boolean bHelp;
RootPaneContainer fMain;
static boolean bMustExit;
/** Value of this variable only retained if huge input script read in. */
String sqlScriptBuffer = null;
JToolBar jtoolbar;
private boolean showSchemas = true;
private boolean showTooltips = true;
private boolean autoRefresh = true;
private boolean gridFormat = true;
// Added: (weconsultants@users)
static DatabaseManagerSwing refForFontDialogSwing;
boolean displayRowCounts = false;
boolean showSys = false;
boolean showIndexDetails = true;
String currentLAF = null;
JPanel pStatus;
static JButton iReadyStatus;
JRadioButtonMenuItem rbAllSchemas = new JRadioButtonMenuItem("*");
JMenuItem mitemAbout = new JMenuItem("About", 'A');
JMenuItem mitemHelp = new JMenuItem("Help", 'H');
JMenuItem mitemUpdateSchemas = new JMenuItem("Update Schemas");
JCheckBoxMenuItem boxAutoCommit =
new JCheckBoxMenuItem(AUTOCOMMIT_BOX_TEXT);
JCheckBoxMenuItem boxLogging = new JCheckBoxMenuItem(LOGGING_BOX_TEXT);
JCheckBoxMenuItem boxShowSchemas =
new JCheckBoxMenuItem(SHOWSCHEMAS_BOX_TEXT);
JCheckBoxMenuItem boxAutoRefresh =
new JCheckBoxMenuItem(AUTOREFRESH_BOX_TEXT);
JCheckBoxMenuItem boxTooltips = new JCheckBoxMenuItem(SHOWTIPS_BOX_TEXT);
JCheckBoxMenuItem boxRowCounts =
new JCheckBoxMenuItem(ROWCOUNTS_BOX_TEXT);
JCheckBoxMenuItem boxShowGrid = new JCheckBoxMenuItem(GRID_BOX_TEXT);
JCheckBoxMenuItem boxShowSys = new JCheckBoxMenuItem(SHOWSYS_BOX_TEXT);
// Consider adding GTK and Plaf L&Fs.
JRadioButtonMenuItem rbNativeLF =
new JRadioButtonMenuItem("Native Look & Feel");
JRadioButtonMenuItem rbJavaLF =
new JRadioButtonMenuItem("Java Look & Feel");
JRadioButtonMenuItem rbMotifLF =
new JRadioButtonMenuItem("Motif Look & Feel");
JLabel jStatusLine;
static String READY_STATUS = "Ready";
private static final String AUTOCOMMIT_BOX_TEXT = "Autocommit mode";
private static final String LOGGING_BOX_TEXT = "Logging mode";
private static final String SHOWSCHEMAS_BOX_TEXT = "Show schemas";
private static final String AUTOREFRESH_BOX_TEXT = "Auto-refresh tree";
private static final String SHOWTIPS_BOX_TEXT = "Show Tooltips";
private static final String ROWCOUNTS_BOX_TEXT = "Show row counts";
private static final String SHOWSYS_BOX_TEXT = "Show system tables";
private static final String GRID_BOX_TEXT =
"Show results in Grid (a.o.t. Text)";
// variables to hold the default cursors for these top level swing objects
// so we can restore them when we exit our thread
Cursor fMainCursor;
Cursor txtCommandCursor;
Cursor txtResultCursor;
HashMap tipMap = new HashMap();
private JMenu mnuSchemas = new JMenu("Schemas");
/**
* Wait Cursor
*/
// Changed: (weconsultants@users): commonted out the, out of the box, cursor to use a custom cursor
private final Cursor waitCursor = new Cursor(Cursor.WAIT_CURSOR);
//getToolkit().createCustomCursor(CommonSwing.getIcon("SystemCursor"),
// new Point(4, 4), "HourGlass cursor");
// (ulrivo): variables set by arguments from the commandline
static String defDriver = "org.hsqldb.jdbcDriver";
static String defURL = "jdbc:hsqldb:.";
static String defUser = "sa";
static String defPassword = "";
static String defScript;
static String defDirectory;
private String schemaFilter = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -