📄 databasemanagerswing.java
字号:
CommonSwing.errorMessage(e); } } else if (s.startsWith("LFMODE:")) { setLF(s.substring("LFMODE:".length())); } else if (s.equals("Set Fonts")) { // Added: (weconsultants@users) FontDialogSwing.CreatFontDialog(refForFontDialogSwing); } else if (s.equals(AUTOCOMMIT_BOX_TEXT)) { try { cConn.setAutoCommit(boxAutoCommit.isSelected()); } catch (SQLException e) { boxAutoCommit.setSelected(!boxAutoCommit.isSelected()); // Added: (weconsultants@users) CommonSwing.errorMessage(e); } } else if (s.equals("Commit")) { try { cConn.commit(); } catch (SQLException e) { // Added: (weconsultants@users) CommonSwing.errorMessage(e); } } else if (s.equals("Insert test data")) { insertTestData(); refreshTree(); } else if (s.equals("Rollback")) { try { cConn.rollback(); } catch (SQLException e) { // Added: (weconsultants@users) CommonSwing.errorMessage(e); } } else if (s.equals("Disable MaxRows")) { try { sStatement.setMaxRows(0); } catch (SQLException e) { // Added: (weconsultants@users) CommonSwing.errorMessage(e); } } else if (s.equals("Set MaxRows to 100")) { try { sStatement.setMaxRows(100); } catch (SQLException e) { CommonSwing.errorMessage(e); } } else if (s.equals("SELECT")) { showHelp(DatabaseManagerCommon.selectHelp); } else if (s.equals("INSERT")) { showHelp(DatabaseManagerCommon.insertHelp); } else if (s.equals("UPDATE")) { showHelp(DatabaseManagerCommon.updateHelp); } else if (s.equals("DELETE")) { showHelp(DatabaseManagerCommon.deleteHelp); } else if (s.equals("EXECUTE")) { executeCurrentSQL(); } else if (s.equals("CREATE TABLE")) { showHelp(DatabaseManagerCommon.createTableHelp); } else if (s.equals("DROP TABLE")) { showHelp(DatabaseManagerCommon.dropTableHelp); } else if (s.equals("CREATE INDEX")) { showHelp(DatabaseManagerCommon.createIndexHelp); } else if (s.equals("DROP INDEX")) { showHelp(DatabaseManagerCommon.dropIndexHelp); } else if (s.equals("CHECKPOINT")) { showHelp(DatabaseManagerCommon.checkpointHelp); } else if (s.equals("SCRIPT")) { showHelp(DatabaseManagerCommon.scriptHelp); } else if (s.equals("SHUTDOWN")) { showHelp(DatabaseManagerCommon.shutdownHelp); } else if (s.equals("SET")) { showHelp(DatabaseManagerCommon.setHelp); } else if (s.equals("Test Script")) { showHelp(DatabaseManagerCommon.testHelp); } else if (s.equals(SHOWSCHEMAS_BOX_TEXT)) { showSchemas = boxShowSchemas.isSelected(); refreshTree(); } else { throw new RuntimeException("Unexpected action triggered: " + s); } } private void displayResults() { if (gridFormat) { setResultsInGrid(); } else { setResultsInText(); } } private void setResultsInGrid() { pResult.removeAll(); pResult.add(gScrollPane, BorderLayout.CENTER); pResult.doLayout(); gResult.fireTableChanged(null); pResult.repaint(); } private void setResultsInText() { pResult.removeAll(); pResult.add(txtResultScroll, BorderLayout.CENTER); pResult.doLayout(); showResultInText(); pResult.repaint(); } private void showHelp(String[] help) { txtCommand.setText(help[0]); bHelp = true; pResult.removeAll(); pResult.add(txtResultScroll, BorderLayout.CENTER); pResult.doLayout(); txtResult.setText(help[1]); pResult.repaint(); txtCommand.requestFocus(); txtCommand.setCaretPosition(help[0].length()); } public void windowActivated(WindowEvent e) {} public void windowDeactivated(WindowEvent e) {} public void windowClosed(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowOpened(WindowEvent e) {} public void windowClosing(WindowEvent ev) { stop(); try { if (cConn != null) { cConn.close(); } if (prefs != null) { prefs.autoRefresh = autoRefresh; prefs.showRowCounts = displayRowCounts; prefs.showSysTables = showSys; prefs.showSchemas = showSchemas; prefs.resultGrid = gridFormat; prefs.showTooltips = showTooltips; prefs.laf = currentLAF; prefs.store(); } } catch (Exception e) { // Added: (weconsultants@users) CommonSwing.errorMessage(e); } if (fMain instanceof java.awt.Window) { ((java.awt.Window) fMain).dispose(); } if (bMustExit) { System.exit(0); } } private void clear() { sqlScriptBuffer = null; txtCommand.setText(""); txtCommand.setEnabled(true); } private String busyText = null; private void backgroundIt(Runnable r, String description) { if (busyText != null) { Toolkit.getDefaultToolkit().beep(); return; } // set Waiting mode here. Inverse op must be called by final() // in the Thread.run() of every background thread. setWaiting(description); SwingUtilities.invokeLater(r); } private void clearResultPanel() { gResult.setHead(new Object[0]); gResult.clear(); if (gridFormat) { gResult.fireTableChanged(null); } else { showResultInText(); } } public void setWaiting(String description) { busyText = description; if (busyText == null) { // restore the cursors we saved if (fMain instanceof java.awt.Frame) { ((java.awt.Frame) fMain).setCursor(fMainCursor); } else { ((Component) fMain).setCursor(fMainCursor); } txtCommand.setCursor(txtCommandCursor); txtResult.setCursor(txtResultCursor); //TODO: Enable actionButtons } else { // save the old cursors if (fMainCursor == null) { fMainCursor = ((fMain instanceof java.awt.Frame) ? (((java.awt.Frame) fMain).getCursor()) : (((Component) fMain).getCursor()) ); txtCommandCursor = txtCommand.getCursor(); txtResultCursor = txtResult.getCursor(); } // set the cursors to the wait cursor if (fMain instanceof java.awt.Frame) { ((java.awt.Frame) fMain).setCursor(waitCursor); } else { ((Component) fMain).setCursor(waitCursor); } txtCommand.setCursor(waitCursor); txtResult.setCursor(waitCursor); //TODO: Disable actionButtons } setStatusLine(busyText, ((busyText == null) ? gResult.getRowCount() : 0)); } private Runnable enableButtonRunnable = new Runnable() { public void run() { jbuttonClear.setEnabled(true); jbuttonExecute.setEnabled(true); } }; private Runnable disableButtonRunnable = new Runnable() { public void run() { jbuttonClear.setEnabled(false); jbuttonExecute.setEnabled(false); } }; private Thread buttonUpdaterThread = null; private static final int BUTTON_CHECK_PERIOD = 500; private Runnable buttonUpdater = new Runnable() { public void run() { boolean havesql; while (true) { try { Thread.sleep(BUTTON_CHECK_PERIOD); } catch (InterruptedException ie) { } if (buttonUpdaterThread == null) { // Pointer to me return; } havesql = (txtCommand.getText().length() > 0); if (jbuttonClear.isEnabled() != havesql) { SwingUtilities.invokeLater( havesql ? enableButtonRunnable : disableButtonRunnable ); } } } }; private JButton jbuttonClear; private JButton jbuttonExecute; public void start() { if (buttonUpdaterThread == null) { buttonUpdaterThread = new Thread(buttonUpdater); } buttonUpdaterThread.start(); } public void stop() {System.err.println("Stopping"); buttonUpdaterThread = null; } private Runnable treeRefreshRunnable = new Runnable() { public void run() { try { directRefreshTree(); } catch (RuntimeException re) { CommonSwing.errorMessage(re); throw re; } finally { setWaiting(null); } } }; /** * Schedules to run in a Gui-safe thread */ protected void executeCurrentSQL() { if (txtCommand.getText().length() < 1) { CommonSwing.errorMessage("No SQL to execute"); return; } backgroundIt(new StatementExecRunnable(), "Executing SQL"); } protected class StatementExecRunnable implements Runnable { public void run() { gResult.clear(); try { if (txtCommand.getText().startsWith("-->>>TEST<<<--")) { testPerformance(); } else { executeSQL(); } updateResult(); displayResults(); updateAutoCommitBox(); System.gc(); } catch (RuntimeException re) { CommonSwing.errorMessage(re); throw re; } finally { setWaiting(null); } } } ; private void executeSQL() { String[] g = new String[1]; String sql = null; try { lTime = System.currentTimeMillis(); sql = ((sqlScriptBuffer == null ? txtCommand.getText() : sqlScriptBuffer)); sStatement.execute(sql); int r = sStatement.getUpdateCount(); if (r == -1) { formatResultSet(sStatement.getResultSet()); } else { g[0] = "update count";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -