Revision: 5946
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=5946&view=rev
Author: manningr
Date: 2010-10-30 18:14:42 +0000 (Sat, 30 Oct 2010)
Log Message:
-----------
Use ProgressCallBackFactory (instead of directly instantiating ProgressCallBackDialog) as this safely creates a ProgressCallBackDialog using the EDT (satisfying Substance's strict requirements for initializing Swing components) and removing the need for ugly GUIUtilities.processOnSwingEventThread(...) code everywhere. This also has the nice benefit of allowing code to be test-able in a headless environment by injecting a mock implementation of ProgressCallBackFactory, which creates mock ProgressCallBack implementations. ProgressCallBackAdaptor is provided as a convenience no-op implementation of ProgressCallBack for methods that require ProgressCallBack, but the caller just wants progress feedback and isn't interested in constructing a dialog (SchemaInfo).
Modified Paths:
--------------
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/db/ColumnDetailDialog.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/mainframe/action/UpdateCommand.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/action/DeleteTablesCommand.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/schemainfo/SchemaInfo.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/ProgressCallBack.java
trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/sql/SQLUtilitiesTest.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/commands/CopyTableCommand.java
trunk/sql12/plugins/postgres/src/main/java/net/sourceforge/squirrel_sql/plugins/postgres/commands/handler/ProgressSQLExecuterHandler.java
trunk/sql12/plugins/refactoring/src/main/java/net/sourceforge/squirrel_sql/plugins/refactoring/commands/DropTablesCommand.java
Added Paths:
-----------
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/IProgressCallBackFactory.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressCallBackDialog.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressCallBackFactory.java
trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/gui/ProgressCallBackDialogTestUI.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/ProgressCallBackAdaptor.java
Removed Paths:
-------------
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgessCallBackDialog.java
Added: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/IProgressCallBackFactory.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/IProgressCallBackFactory.java (rev 0)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/IProgressCallBackFactory.java 2010-10-30 18:14:42 UTC (rev 5946)
@@ -0,0 +1,47 @@
+package net.sourceforge.squirrel_sql.client.gui;
+
+import java.awt.Frame;
+
+import javax.swing.JDialog;
+
+import net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack;
+
+/*
+ * Copyright (C) 2010 Rob Manning
+ * man...@us...
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+public interface IProgressCallBackFactory
+{
+
+ /**
+ * @param owner
+ * @param title
+ * @param totalItems
+ * @return
+ */
+ public abstract ProgressCallBack create(Frame owner, String title, int totalItems);
+
+ /**
+ * @param owner
+ * @param title
+ * @param totalItems
+ * @return
+ */
+ public abstract ProgressCallBack create(JDialog owner, String title, int totalItems);
+
+}
\ No newline at end of file
Deleted: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgessCallBackDialog.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgessCallBackDialog.java 2010-10-30 18:06:17 UTC (rev 5945)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgessCallBackDialog.java 2010-10-30 18:14:42 UTC (rev 5946)
@@ -1,210 +0,0 @@
-package net.sourceforge.squirrel_sql.client.gui;
-/*
- * Copyright (C) 2007 Rob Manning
- * man...@us...
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-import java.awt.Dialog;
-import java.awt.Dimension;
-import java.awt.Frame;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
-import java.awt.Window;
-
-import javax.swing.BorderFactory;
-import javax.swing.JDialog;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JProgressBar;
-
-import net.sourceforge.squirrel_sql.client.ApplicationArguments;
-import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
-import net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack;
-import net.sourceforge.squirrel_sql.fw.util.StringManager;
-import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
-import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
-import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
-
-/**
- * A simple class that can be used to show the user a dialog to indicate the
- * progress of some task using the ProgressCallBack interface. Since certain
- * classes in fw module interact with the database and certain operations can
- * take quite a long time, letting the user know how it's going is nice.
- * However, fw module classes don't (and shouldn't) know anything about the UI
- * as this is the responsibility of the app module classes. So, this class
- * can be passed in by app classes to certain fw long-running methods to
- * bridge the gap and provide feedback to the user.
- *
- * @author manningr
- */
-public class ProgessCallBackDialog extends JDialog
- implements ProgressCallBack {
-
- /** Logger for this class. */
- private final static ILogger s_log =
- LoggerController.createLogger(ProgessCallBackDialog.class);
-
- /** Internationalized strings for this class */
- private static final StringManager s_stringMgr =
- StringManagerFactory.getStringManager(ProgessCallBackDialog.class);
-
- static interface i18n {
- //i18n[ProgressCallBackDialog.defaultLoadingPrefix=Loading:]
- String DEFAULT_LOADING_PREFIX =
- s_stringMgr.getString("ProgressCallBackDialog.defaultLoadingPrefix");
-
- //i18n[ProgressCallBackDialog.initialLoadingPrefix=Loading...]
- String INITIAL_LOADING_PREFIX =
- s_stringMgr.getString("ProgressCallBackDialog.initialLoadingPrefix");
- }
-
- private int itemCount = 0;
-
- private JProgressBar progressBar = null;
-
- private JLabel statusLabel = null;
-
- private String _loadingPrefix = i18n.DEFAULT_LOADING_PREFIX;
-
- public ProgessCallBackDialog(Dialog owner, String title, int totalItems) {
- super(owner, title);
- init(totalItems);
- }
-
- public ProgessCallBackDialog(Frame owner, String title, int totalItems) {
- super(owner, title);
- setLocationRelativeTo(owner);
- init(totalItems);
- }
-
- private void init(int totalItems) {
- itemCount = totalItems;
- final Window owner = super.getOwner();
- final ProgessCallBackDialog dialog = this;
-
- GUIUtils.processOnSwingEventThread(new Runnable() {
- public void run() {
- createGUI();
- setLocationRelativeTo(owner);
- dialog.setVisible(true);
- }
- }, true);
-
- }
-
- public void setTotalItems(int totalItems) {
- itemCount = totalItems;
- progressBar.setMaximum(totalItems);
- }
-
- /**
- * Sets the text that is displayed before each thing being loaded. By
- * default this is the string "Loading:".
- * @param loadingPrefix
- */
- public void setLoadingPrefix(String loadingPrefix) {
- if (loadingPrefix != null) {
- _loadingPrefix = loadingPrefix;
- }
- }
-
- /* (non-Javadoc)
- * @see net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack#currentlyLoading(java.lang.String)
- */
- public void currentlyLoading(final String simpleName) {
- final StringBuilder statusText = new StringBuilder();
- statusText.append(_loadingPrefix);
- statusText.append(" ");
- statusText.append(simpleName);
- try {
- GUIUtils.processOnSwingEventThread(new Runnable() {
- public void run() {
- statusLabel.setText(statusText.toString());
- progressBar.setValue(progressBar.getValue() + 1);
- if (finishedLoading()) {
- ProgessCallBackDialog.this.setVisible(false);
- return;
- }
- }
- });
- } catch (Exception e) {
- s_log.error("Unexpected exception: "+e.getMessage(), e);
- }
- }
-
- public boolean finishedLoading() {
- return progressBar.getValue() >= itemCount - 1;
- }
-
- private void createGUI() {
- JPanel dialogPanel = new JPanel(new GridBagLayout());
- dialogPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
- GridBagConstraints c;
-
- c = new GridBagConstraints();
- c.gridx = 0;
- c.gridy = 0;
- c.fill = GridBagConstraints.HORIZONTAL;
- c.anchor = GridBagConstraints.WEST;
-
- statusLabel = new JLabel(i18n.INITIAL_LOADING_PREFIX);
- dialogPanel.add(statusLabel, c);
-
- progressBar = new JProgressBar(0, itemCount);
- c = new GridBagConstraints();
- c.gridx = 0;
- c.gridy = 1;
- c.anchor = GridBagConstraints.WEST;
- c.fill = GridBagConstraints.HORIZONTAL;
- c.insets = new Insets(0,0,10,0);
- c.weightx = 1.0;
-
- dialogPanel.add(progressBar, c);
- super.getContentPane().add(dialogPanel);
- super.pack();
- super.setSize(new Dimension(400, 100));
- }
-
- /**
- * @param args
- */
- public static void main(String[] args) throws Exception {
- ApplicationArguments.initialize(new String[] {});
- String[] tables = new String[] {
- "table_a",
- "table_b",
- "table_c",
- "table_d",
- "table_e",
- };
- JFrame parent = new JFrame();
- GUIUtils.centerWithinScreen(parent);
- parent.setSize(new Dimension(200, 200));
- parent.setVisible(true);
- ProgessCallBackDialog dialog =
- new ProgessCallBackDialog(parent, "test", 5);
-
- dialog.setVisible(true);
- for (int i = 0; i < 5; i++) {
- dialog.currentlyLoading(tables[i]);
- Thread.sleep(1000);
- }
- System.exit(0);
- }
-
-}
Copied: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressCallBackDialog.java (from rev 5908, trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgessCallBackDialog.java)
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressCallBackDialog.java (rev 0)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressCallBackDialog.java 2010-10-30 18:14:42 UTC (rev 5946)
@@ -0,0 +1,257 @@
+package net.sourceforge.squirrel_sql.client.gui;
+
+/*
+ * Copyright (C) 2007 Rob Manning
+ * man...@us...
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+import java.awt.Dialog;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.Window;
+
+import javax.swing.BorderFactory;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JProgressBar;
+
+import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
+import net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack;
+import net.sourceforge.squirrel_sql.fw.util.StringManager;
+import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
+import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
+import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
+
+/**
+ * A simple class that can be used to show the user a dialog to indicate the progress of some task using the
+ * ProgressCallBack interface. Since certain classes in fw module interact with the database and certain
+ * operations can take quite a long time, letting the user know how it's going is nice. However, fw module
+ * classes don't (and shouldn't) know anything about the UI as this is the responsibility of the app module
+ * classes. So, this class can be passed in by app classes to certain fw long-running methods to bridge the
+ * gap and provide feedback to the user.
+ *
+ * @author manningr
+ */
+public class ProgressCallBackDialog extends JDialog implements ProgressCallBack
+{
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 1L;
+
+ /** Logger for this class. */
+ public final static ILogger s_log = LoggerController.createLogger(ProgressCallBackDialog.class);
+
+ /** Internationalized strings for this class */
+ private static final StringManager s_stringMgr =
+ StringManagerFactory.getStringManager(ProgressCallBackDialog.class);
+
+ static interface i18n
+ {
+ // i18n[ProgressCallBackDialog.defaultLoadingPrefix=Loading:]
+ String DEFAULT_LOADING_PREFIX = s_stringMgr.getString("ProgressCallBackDialog.defaultLoadingPrefix");
+
+ // i18n[ProgressCallBackDialog.initialLoadingPrefix=Loading...]
+ String INITIAL_LOADING_PREFIX = s_stringMgr.getString("ProgressCallBackDialog.initialLoadingPrefix");
+ }
+
+ private int itemCount = 0;
+
+ private JProgressBar progressBar = null;
+
+ private JLabel statusLabel = null;
+
+ private String _loadingPrefix = i18n.DEFAULT_LOADING_PREFIX;
+
+ /**
+ * Constructor which accepts a Dialog owner
+ *
+ * @param owner
+ * the owner Dialog from which the dialog is displayed or null if this dialog has no owner
+ * @param title
+ * the String to display in the dialog's title bar
+ * @param totalItems
+ * the total number of items at which point progress will indicate complete
+ */
+ public ProgressCallBackDialog(Dialog owner, String title, int totalItems)
+ {
+ super(owner, title);
+ init(totalItems);
+ }
+
+ /**
+ * Constructor which accepts a Frame owner
+ *
+ * @param owner
+ * the owner Frame from which the dialog is displayed or null if this dialog has no owner
+ * @param title
+ * the String to display in the dialog's title bar
+ * @param totalItems
+ * the total number of items at which point progress will indicate complete
+ */
+ public ProgressCallBackDialog(Frame owner, String title, int totalItems)
+ {
+ super(owner, title);
+ setLocationRelativeTo(owner);
+ init(totalItems);
+ }
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack#setTotalItems(int)
+ */
+ @Override
+ public void setTotalItems(int totalItems)
+ {
+ itemCount = totalItems;
+ progressBar.setMaximum(totalItems);
+ }
+
+ /**
+ * Sets the text that is displayed before each thing being loaded. By default this is the string
+ * "Loading:".
+ *
+ * @param loadingPrefix
+ */
+ @Override
+ public void setLoadingPrefix(String loadingPrefix)
+ {
+ if (loadingPrefix != null)
+ {
+ _loadingPrefix = loadingPrefix;
+ }
+ }
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack#currentlyLoading(java.lang.String)
+ */
+ @Override
+ public void currentlyLoading(final String simpleName)
+ {
+ final StringBuilder statusText = new StringBuilder();
+ statusText.append(_loadingPrefix);
+ statusText.append(" ");
+ statusText.append(simpleName);
+ try
+ {
+ GUIUtils.processOnSwingEventThread(new Runnable()
+ {
+ public void run()
+ {
+ statusLabel.setText(statusText.toString());
+ progressBar.setValue(progressBar.getValue() + 1);
+
+ if (finishedLoading())
+ {
+ ProgressCallBackDialog.this.setVisible(false);
+ return;
+ }
+ }
+ });
+ }
+ catch (Exception e)
+ {
+ s_log.error("Unexpected exception: " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack#finishedLoading()
+ */
+ @Override
+ public boolean finishedLoading()
+ {
+ return progressBar.getValue() == itemCount;
+ }
+
+ /**
+ * @see java.awt.Window#dispose()
+ */
+ @Override
+ public void dispose()
+ {
+ GUIUtils.processOnSwingEventThread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ ProgressCallBackDialog.this.dispose();
+ }
+ });
+ }
+
+ /**
+ * @see java.awt.Dialog#setVisible(boolean)
+ */
+ @Override
+ public void setVisible(final boolean b)
+ {
+ GUIUtils.processOnSwingEventThread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ ProgressCallBackDialog.this.setVisible(b);
+ }
+ });
+ }
+
+ private void init(int totalItems)
+ {
+ itemCount = totalItems;
+ final Window owner = super.getOwner();
+ final ProgressCallBackDialog dialog = this;
+ createGUI();
+ setLocationRelativeTo(owner);
+ dialog.setVisible(true);
+ }
+
+ private void createGUI()
+ {
+ JPanel dialogPanel = new JPanel(new GridBagLayout());
+ dialogPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
+ GridBagConstraints c;
+
+ c = new GridBagConstraints();
+ c.gridx = 0;
+ c.gridy = 0;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.anchor = GridBagConstraints.WEST;
+
+ statusLabel = new JLabel(i18n.INITIAL_LOADING_PREFIX);
+ dialogPanel.add(statusLabel, c);
+
+ progressBar = new JProgressBar(0, itemCount);
+ c = new GridBagConstraints();
+ c.gridx = 0;
+ c.gridy = 1;
+ c.anchor = GridBagConstraints.WEST;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.insets = new Insets(0, 0, 10, 0);
+ c.weightx = 1.0;
+
+ dialogPanel.add(progressBar, c);
+ super.getContentPane().add(dialogPanel);
+ super.pack();
+ super.setSize(new Dimension(400, 100));
+ }
+
+
+}
Added: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressCallBackFactory.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressCallBackFactory.java (rev 0)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressCallBackFactory.java 2010-10-30 18:14:42 UTC (rev 5946)
@@ -0,0 +1,110 @@
+package net.sourceforge.squirrel_sql.client.gui;
+
+import java.awt.Frame;
+
+import javax.swing.JDialog;
+
+import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
+import net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack;
+
+/*
+ * Copyright (C) 2010 Rob Manning
+ * man...@us...
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/**
+ * A factory that creates a ProgressCallBack on the Swing Event Dispatch Thread.
+ */
+public class ProgressCallBackFactory implements IProgressCallBackFactory
+{
+ /**
+ * @see net.sourceforge.squirrel_sql.client.gui.IProgressCallBackFactory#create(java.awt.Frame,
+ * java.lang.String, int)
+ */
+ @Override
+ public ProgressCallBack create(Frame owner, String title, int totalItems)
+ {
+ ProgressCallBackCreationTask task = new ProgressCallBackCreationTask(owner, title, totalItems);
+ GUIUtils.processOnSwingEventThread(task, true);
+ return task.getResult();
+ }
+
+ /**
+ * @see net.sourceforge.squirrel_sql.client.gui.IProgressCallBackFactory#
+ * create(javax.swing.JDialog, java.lang.String, int)
+ */
+ @Override
+ public ProgressCallBack create(JDialog owner, String title, int totalItems)
+ {
+ ProgressCallBackCreationTask task = new ProgressCallBackCreationTask(owner, title, totalItems);
+ GUIUtils.processOnSwingEventThread(task, true);
+ return task.getResult();
+ }
+
+
+ /**
+ * This runnable is used by the factory methods above to create the ProgressCallBackDialog. This allows
+ * this task to be performed on the event dispatch thread, and afterwards the ProgressCallBackDialog can
+ * be obtained using getResult().
+ */
+ private class ProgressCallBackCreationTask implements Runnable
+ {
+
+ private ProgressCallBack result = null;
+
+ private final String title;
+
+ private final int totalItems;
+
+ private Frame frameOwner;
+
+ private JDialog dialogOwner;
+
+ public ProgressCallBackCreationTask(Frame owner, String title, int totalItems)
+ {
+ this.frameOwner = owner;
+ this.title = title;
+ this.totalItems = totalItems;
+ }
+
+ public ProgressCallBackCreationTask(JDialog owner, String title, int totalItems)
+ {
+ this.dialogOwner = owner;
+ this.title = title;
+ this.totalItems = totalItems;
+ }
+
+ @Override
+ public void run()
+ {
+ if (frameOwner != null) {
+ result = new ProgressCallBackDialog(frameOwner, title, totalItems);
+ } else {
+ result = new ProgressCallBackDialog(dialogOwner, title, totalItems);
+ }
+ }
+
+ /**
+ * @return the result
+ */
+ public ProgressCallBack getResult()
+ {
+ return result;
+ }
+
+ }
+}
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/db/ColumnDetailDialog.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/db/ColumnDetailDialog.java 2010-10-30 18:06:17 UTC (rev 5945)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/db/ColumnDetailDialog.java 2010-10-30 18:14:42 UTC (rev 5946)
@@ -134,9 +134,6 @@
//i18n[ColumnDetailsDialog.lengthLabel=Length: ]
String LENGTH_LABEL =
s_stringMgr.getString("ColumnDetailsDialog.lengthLabel");
- //i18n[ColumnDetailsDialog.modifyColumnTitle=Modify Column]
- String MODIFY_TITLE =
- s_stringMgr.getString("ColumnDetailsDialog.modifyColumnTitle");
//i18n[ColumnDetailsDialog.nullableLabel=Nullable: ]
String NULLABLE_LABEL =
s_stringMgr.getString("ColumnDetailsDialog.nullableLabel");
@@ -420,10 +417,10 @@
lengthSpinner = new JSpinner();
lengthSpinner.setPreferredSize(mediumField);
- double value = 10;
- double min = 1;
- double max = Long.MAX_VALUE;
- double step = 1;
+ int value = 10;
+ int min = 1;
+ int max = Integer.MAX_VALUE;
+ int step = 1;
SpinnerNumberModel model = new SpinnerNumberModel(value, min, max, step);
lengthSpinner.setModel(model);
lengthSpinner.setPreferredSize(mediumField);
@@ -438,7 +435,7 @@
precisionSpinner.setPreferredSize(mediumField);
value = 8;
min = 0;
- max = Long.MAX_VALUE;
+ max = Integer.MAX_VALUE;
step = 1;
SpinnerNumberModel precisionModel =
new SpinnerNumberModel(value, min, max, step);
@@ -455,7 +452,7 @@
scaleSpinner.setPreferredSize(mediumField);
value = 8;
min = 0;
- max = Long.MAX_VALUE;
+ max = Integer.MAX_VALUE;
step = 1;
SpinnerNumberModel scaleModel =
new SpinnerNumberModel(value, min, max, step);
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/mainframe/action/UpdateCommand.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/mainframe/action/UpdateCommand.java 2010-10-30 18:06:17 UTC (rev 5945)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/mainframe/action/UpdateCommand.java 2010-10-30 18:14:42 UTC (rev 5946)
@@ -23,6 +23,8 @@
import net.sourceforge.squirrel_sql.client.update.UpdateControllerFactoryImpl;
import net.sourceforge.squirrel_sql.client.update.UpdateUtilImpl;
import net.sourceforge.squirrel_sql.client.update.downloader.ArtifactDownloaderFactoryImpl;
+import net.sourceforge.squirrel_sql.fw.gui.JOptionPaneService;
+import net.sourceforge.squirrel_sql.fw.util.FileWrapperFactoryImpl;
import net.sourceforge.squirrel_sql.fw.util.ICommand;
/**
* This <CODE>ICommand</CODE> allows the user to check for updates and apply changes to the currently
@@ -61,7 +63,7 @@
{
UpdateController updateController =
updateControllerFactory.createUpdateController(_app, new ArtifactDownloaderFactoryImpl(),
- new UpdateUtilImpl());
+ new UpdateUtilImpl(), new JOptionPaneService(), new FileWrapperFactoryImpl());
updateController.showUpdateDialog();
}
}
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/action/DeleteTablesCommand.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/action/DeleteTablesCommand.java 2010-10-30 18:06:17 UTC (rev 5945)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/action/DeleteTablesCommand.java 2010-10-30 18:14:42 UTC (rev 5946)
@@ -24,13 +24,15 @@
import java.util.HashSet;
import java.util.List;
-import net.sourceforge.squirrel_sql.client.gui.ProgessCallBackDialog;
+import net.sourceforge.squirrel_sql.client.gui.IProgressCallBackFactory;
+import net.sourceforge.squirrel_sql.client.gui.ProgressCallBackFactory;
import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
import net.sourceforge.squirrel_sql.client.session.ISession;
import net.sourceforge.squirrel_sql.client.session.SQLExecuterTask;
import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
+import net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack;
import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
import net.sourceforge.squirrel_sql.fw.sql.SQLUtilities;
import net.sourceforge.squirrel_sql.fw.util.ICommand;
@@ -78,6 +80,8 @@
/** API for the current tree. */
private IObjectTreeAPI _tree;
+ private IProgressCallBackFactory progressCallBackFactory = new ProgressCallBackFactory();
+
/**
* Ctor.
*
@@ -103,11 +107,11 @@
* Delete records from the selected tables in the object tree.
*/
public void execute()
- {
- ProgessCallBackDialog cb =
- new ProgessCallBackDialog(_session.getApplication().getMainFrame(), i18n.PROGRESS_DIALOG_TITLE,
- _tables.size());
-
+ {
+ ProgressCallBack cb =
+ progressCallBackFactory.create(_session.getApplication().getMainFrame(),
+ i18n.PROGRESS_DIALOG_TITLE, _tables.size());
+
cb.setLoadingPrefix(i18n.LOADING_PREFIX);
DeleteExecuter executer = new DeleteExecuter(cb);
_session.getApplication().getThreadPool().addTask(executer);
@@ -116,9 +120,9 @@
private class DeleteExecuter implements Runnable
{
- ProgessCallBackDialog _cb = null;
+ ProgressCallBack _cb = null;
- public DeleteExecuter(ProgessCallBackDialog cb)
+ public DeleteExecuter(ProgressCallBack cb)
{
Utilities.checkNull("DeleteExecuter.init", "cb", cb);
_cb = cb;
@@ -241,4 +245,9 @@
}
+ public void setProgressCallBackFactory(IProgressCallBackFactory progressCallBackFactory)
+ {
+ this.progressCallBackFactory = progressCallBackFactory;
+ }
+
}
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/schemainfo/SchemaInfo.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/schemainfo/SchemaInfo.java 2010-10-30 18:06:17 UTC (rev 5945)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/schemainfo/SchemaInfo.java 2010-10-30 18:14:42 UTC (rev 5946)
@@ -50,6 +50,7 @@
import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
import net.sourceforge.squirrel_sql.fw.sql.ProcedureInfo;
import net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack;
+import net.sourceforge.squirrel_sql.fw.sql.ProgressCallBackAdaptor;
import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
import net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo;
import net.sourceforge.squirrel_sql.fw.sql.TableInfo;
@@ -578,8 +579,8 @@
try
{
- ProgressCallBack pcb = new ProgressCallBack()
- {
+ ProgressCallBack pcb = new ProgressCallBackAdaptor()
+ { @Override
public void currentlyLoading(String simpleName)
{
setProgress(msg + " (" + simpleName + ")", beginProgress);
@@ -1108,10 +1109,11 @@
try
{
String[] buf = missingTypes.toArray(new String[missingTypes.size()]);
- ProgressCallBack pcb = new ProgressCallBack()
+ ProgressCallBack pcb = new ProgressCallBackAdaptor()
{
+ @Override
public void currentlyLoading(String simpleName)
- {
+ {
StringBuilder tmp = new StringBuilder(i18n.LOADING_TABLES_MSG);
tmp.append(" (");
tmp.append(simpleName);
@@ -1194,8 +1196,8 @@
{
try
{
- ProgressCallBack pcb = new ProgressCallBack()
- {
+ ProgressCallBack pcb = new ProgressCallBackAdaptor()
+ { @Override
public void currentlyLoading(String simpleName)
{
setProgress(msg + " (" + simpleName + ")", beginProgress);
@@ -1647,6 +1649,4 @@
throw new RuntimeException(e);
}
}
-
-
}
Added: trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/gui/ProgressCallBackDialogTestUI.java
===================================================================
--- trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/gui/ProgressCallBackDialogTestUI.java (rev 0)
+++ trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/gui/ProgressCallBackDialogTestUI.java 2010-10-30 18:14:42 UTC (rev 5946)
@@ -0,0 +1,57 @@
+package net.sourceforge.squirrel_sql.client.gui;
+
+import java.awt.Dimension;
+
+import javax.swing.JFrame;
+
+import net.sourceforge.squirrel_sql.client.ApplicationArguments;
+import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
+import net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack;
+
+/*
+ * Copyright (C) 2010 Rob Manning
+ * man...@us...
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+public class ProgressCallBackDialogTestUI
+{
+
+ private static IProgressCallBackFactory progressCallBackFactory = new ProgressCallBackFactory();
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) throws Exception
+ {
+ ApplicationArguments.initialize(new String[] {});
+ String[] tables = new String[] { "table_a", "table_b", "table_c", "table_d", "table_e", };
+ JFrame parent = new JFrame();
+ GUIUtils.centerWithinScreen(parent);
+ parent.setSize(new Dimension(200, 200));
+ parent.setVisible(true);
+ ProgressCallBack pcb = progressCallBackFactory.create(parent, "test", 5);
+
+ pcb.setVisible(true);
+ for (int i = 0; i < 5; i++)
+ {
+ pcb.currentlyLoading(tables[i]);
+ Thread.sleep(1000);
+ }
+ System.exit(0);
+ }
+
+}
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/ProgressCallBack.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/ProgressCallBack.java 2010-10-30 18:06:17 UTC (rev 5945)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/ProgressCallBack.java 2010-10-30 18:14:42 UTC (rev 5946)
@@ -1,7 +1,65 @@
package net.sourceforge.squirrel_sql.fw.sql;
+/*
+ * Copyright (C) 2006 Gerd Wagner
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+/**
+ * Interface for ProgressCallBack implementations.
+ */
public interface ProgressCallBack
{
+ /**
+ * @param simpleName
+ */
+ void currentlyLoading(String simpleName);
- void currentlyLoading(String simpleName);
+ /**
+ * Sets the text that is displayed before each thing being loaded. For example, it could be a string like
+ * "Loading:". See the implementation for details.
+ *
+ * @param loadingPrefix the string to use as the loadingPrefix.
+ */
+ void setLoadingPrefix(String loadingPrefix);
+
+ /**
+ * Whether or not to make this callback visible.
+ *
+ * @param b
+ */
+ void setVisible(boolean b);
+
+ /**
+ * Sets the total number of items for the progress bar
+ *
+ * @param totalItems
+ */
+ void setTotalItems(int totalItems);
+
+ /**
+ * Whether or not the progress bar has reached the total count of items
+ *
+ * @return true if finished loading; false otherwise
+ */
+ boolean finishedLoading();
+
+ /**
+ * Dispose of the resources used by this progress callback.
+ */
+ void dispose();
}
Added: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/ProgressCallBackAdaptor.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/ProgressCallBackAdaptor.java (rev 0)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/ProgressCallBackAdaptor.java 2010-10-30 18:14:42 UTC (rev 5946)
@@ -0,0 +1,89 @@
+/**
+ *
+ */
+package net.sourceforge.squirrel_sql.fw.sql;
+
+
+/*
+ * Copyright (C) 2010 Rob Manning
+ * man...@us...
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/**
+ * This adaptor allows callers of methods that accept a ProgressCallBack to get feedback on progress from
+ * callee's and do whatever is necessary to show that progress to the user. This allows for custom behavior
+ * of some of the ProgressCallBack interface without requiring implementation all of the call back methods.
+ */
+public class ProgressCallBackAdaptor implements ProgressCallBack
+{
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack#currentlyLoading(java.lang.String)
+ */
+ @Override
+ public void currentlyLoading(String simpleName)
+ {
+ /* override in sub-class */
+ }
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack#dispose()
+ */
+ @Override
+ public void dispose()
+ {
+ /* override in sub-class */
+ }
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack#finishedLoading()
+ */
+ @Override
+ public boolean finishedLoading()
+ {
+ /* override in sub-class */
+ return false;
+ }
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack#setLoadingPrefix(java.lang.String)
+ */
+ @Override
+ public void setLoadingPrefix(String loadingPrefix)
+ {
+ /* override in sub-class */
+ }
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack#setTotalItems(int)
+ */
+ @Override
+ public void setTotalItems(int totalItems)
+ {
+ /* override in sub-class */
+ }
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack#setVisible(boolean)
+ */
+ @Override
+ public void setVisible(boolean b)
+ {
+ /* override in sub-class */
+ }
+
+}
Modified: trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/sql/SQLUtilitiesTest.java
===================================================================
--- trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/sql/SQLUtilitiesTest.java 2010-10-30 18:06:17 UTC (rev 5945)
+++ trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/sql/SQLUtilitiesTest.java 2010-10-30 18:14:42 UTC (rev 5946)
@@ -84,7 +84,7 @@
try
{
List<ITableInfo> result =
- SQLUtilities.getInsertionOrder(tables, mockSQLDatabaseMetaData, new MyCallback());
+ SQLUtilities.getInsertionOrder(tables, mockSQLDatabaseMetaData, new ProgressCallBackAdaptor());
Assert.assertEquals(tables.size(), result.size());
}
catch (Exception e)
@@ -117,13 +117,4 @@
assertEquals(tableName, quotedTableName);
}
- private static class MyCallback implements ProgressCallBack
- {
-
- public void currentlyLoading(String simpleName)
- {
- // Do Nothing
- }
-
- }
}
Modified: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/commands/CopyTableCommand.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/commands/CopyTableCommand.java 2010-10-30 18:06:17 UTC (rev 5945)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/commands/CopyTableCommand.java 2010-10-30 18:14:42 UTC (rev 5946)
@@ -23,12 +23,14 @@
import java.util.ArrayList;
import java.util.List;
-import net.sourceforge.squirrel_sql.client.gui.ProgessCallBackDialog;
+import net.sourceforge.squirrel_sql.client.gui.IProgressCallBackFactory;
+import net.sourceforge.squirrel_sql.client.gui.ProgressCallBackFactory;
import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
import net.sourceforge.squirrel_sql.client.session.ISession;
import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
+import net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack;
import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
import net.sourceforge.squirrel_sql.fw.sql.SQLUtilities;
import net.sourceforge.squirrel_sql.fw.util.ICommand;
@@ -41,119 +43,131 @@
public class CopyTableCommand implements ICommand
{
- /**
- * Current session.
- */
- private ISession _session;
-
- /**
- * Current plugin.
- */
- private final DBCopyPlugin _plugin;
-
- /** Logger for this class. */
- private final static ILogger log =
- LoggerController.createLogger(CopyTableCommand.class);
-
- /** Internationalized strings for this class */
- private static final StringManager s_stringMgr =
- StringManagerFactory.getStringManager(CopyTableCommand.class);
-
- static interface i18n {
-
- //i18n[CopyTablesCommand.progressDialogTitle=Analyzing FKs in Tables to Copy]
- String PROGRESS_DIALOG_TITLE =
- s_stringMgr.getString("CopyTablesCommand.progressDialogTitle");
-
- //i18n[CopyTablesCommand.loadingPrefix=Analyzing table:]
- String LOADING_PREFIX =
- s_stringMgr.getString("CopyTablesCommand.loadingPrefix");
-
- }
-
- /**
- * Ctor specifying the current session.
- */
- public CopyTableCommand(ISession session, DBCopyPlugin plugin)
- {
- super();
- _session = session;
- _plugin = plugin;
- }
-
- /**
- * Execute this command. Save the session and selected objects in the plugin
- * for use in paste command.
- */
- public void execute()
- {
- IObjectTreeAPI api = _session.getObjectTreeAPIOfActiveSessionWindow();
- if (api != null) {
- IDatabaseObjectInfo[] dbObjs = api.getSelectedDatabaseObjects();
- if (DatabaseObjectType.TABLE_TYPE_DBO.equals(dbObjs[0].getDatabaseObjectType())) {
- String catalog = dbObjs[0].getCatalogName();
- String schema = dbObjs[0].getSchemaName();
- if (log.isDebugEnabled()) {
- log.debug("CopyTableCommand.execute: catalog="+catalog);
- log.debug("CopyTableCommand.execute: schema="+schema);
- }
- dbObjs = DBUtil.getTables(_session, catalog, schema, null);
- for (int i = 0; i < dbObjs.length; i++) {
- ITableInfo info = (ITableInfo)dbObjs[i];
- if (log.isDebugEnabled()) {
- log.debug("dbObj["+i+"] = "+info.getSimpleName());
- }
+ /**
+ * Current session.
+ */
+ private ISession _session;
+
+ /**
+ * Current plugin.
+ */
+ private final DBCopyPlugin _plugin;
+
+ /** Logger for this class. */
+ private final static ILogger log = LoggerController.createLogger(CopyTableCommand.class);
+
+ /** Internationalized strings for this class */
+ private static final StringManager s_stringMgr =
+ StringManagerFactory.getStringManager(CopyTableCommand.class);
+
+ private IProgressCallBackFactory progressCallBackFactory = new ProgressCallBackFactory();
+
+ static interface i18n
+ {
+
+ // i18n[CopyTablesCommand.progressDialogTitle=Analyzing FKs in Tables to Copy]
+ String PROGRESS_DIALOG_TITLE = s_stringMgr.getString("CopyTablesCommand.progressDialogTitle");
+
+ // i18n[CopyTablesCommand.loadingPrefix=Analyzing table:]
+ String LOADING_PREFIX = s_stringMgr.getString("CopyTablesCommand.loadingPrefix");
+
+ }
+
+ /**
+ * Ctor specifying the current session.
+ */
+ public CopyTableCommand(ISession session, DBCopyPlugin plugin)
+ {
+ super();
+ _session = session;
+ _plugin = plugin;
+ }
+
+ public void setProgressCallBackFactory(IProgressCallBackFactory progressCallBackFactory)
+ {
+ this.progressCallBackFactory = progressCallBackFactory;
+ }
+
+ /**
+ * Execute this command. Save the session and selected objects in the plugin for use in paste command.
+ */
+ public void execute()
+ {
+ IObjectTreeAPI api = _session.getObjectTreeAPIOfActiveSessionWindow();
+ if (api != null)
+ {
+ IDatabaseObjectInfo[] dbObjs = api.getSelectedDatabaseObjects();
+ if (DatabaseObjectType.TABLE_TYPE_DBO.equals(dbObjs[0].getDatabaseObjectType()))
+ {
+ String catalog = dbObjs[0].getCatalogName();
+ String schema = dbObjs[0].getSchemaName();
+ if (log.isDebugEnabled())
+ {
+ log.debug("CopyTableCommand.execute: catalog=" + catalog);
+ log.debug("CopyTableCommand.execute: schema=" + schema);
}
- }
+ dbObjs = DBUtil.getTables(_session, catalog, schema, null);
+ for (int i = 0; i < dbObjs.length; i++)
+ {
+ ITableInfo info = (ITableInfo) dbObjs[i];
+ if (log.isDebugEnabled())
+ {
+ log.debug("dbObj[" + i + "] = " + info.getSimpleName());
+ }
+ }
+ }
- _plugin.setCopySourceSession(_session);
- final IDatabaseObjectInfo[] fdbObjs = dbObjs;
- final SQLDatabaseMetaData md =
- _session.getSQLConnection().getSQLMetaData();
- _session.getApplication().getThreadPool().addTask(new Runnable() {
- public void run() {
- try {
- getInsertionOrder(fdbObjs, md);
- _plugin.setPasteMenuEnabled(true);
- } catch (SQLException e) {
- log.error("Unexected exception: ", e);
- }
- }
- });
-
- }
- }
-
- private void getInsertionOrder(IDatabaseObjectInfo[] dbObjs,
- SQLDatabaseMetaData md)
- throws SQLException
- {
-
- // Only concerned about order when more than one table.
- if (dbObjs.length > 1) {
- List<ITableInfo> selectedTables = new ArrayList<ITableInfo>();
- for (int i = 0; i < dbObjs.length; i++) {
- selectedTables.add((ITableInfo)dbObjs[i]);
- }
-
- ProgessCallBackDialog cb =
- new ProgessCallBackDialog(_session.getApplication().getMainFrame(),
- i18n.PROGRESS_DIALOG_TITLE,
- dbObjs.length);
-
- cb.setLoadingPrefix(i18n.LOADING_PREFIX);
- selectedTables =
- SQLUtilities.getInsertionOrder(selectedTables,
- md,
- cb);
- cb.setVisible(false);
+ _plugin.setCopySourceSession(_session);
+ final IDatabaseObjectInfo[] fdbObjs = dbObjs;
+ final SQLDatabaseMetaData md = _session.getSQLConnection().getSQLMetaData();
+ _session.getApplication().getThreadPool().addTask(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ getInsertionOrder(fdbObjs, md);
+ _plugin.setPasteMenuEnabled(true);
+ }
+ catch (SQLException e)
+ {
+ log.error("Unexected exception: ", e);
+ }
+ }
+ });
- _plugin.setSelectedDatabaseObjects(
- selectedTables.toArray(new IDatabaseObjectInfo[dbObjs.length]));
-
- } else {
- _plugin.setSelectedDatabaseObjects(dbObjs);
- }
- }
-
+ }
+ }
+
+ private void getInsertionOrder(IDatabaseObjectInfo[] dbObjs, SQLDatabaseMetaData md) throws SQLException
+ {
+
+ // Only concerned about order when more than one table.
+ if (dbObjs.length > 1)
+ {
+ List<ITableInfo> selectedTables = new ArrayList<ITableInfo>();
+ for (int i = 0; i < dbObjs.length; i++)
+ {
+ selectedTables.add((ITableInfo) dbObjs[i]);
+ }
+
+ ProgressCallBack cb =
+ progressCallBackFactory.create(_session.getApplication().getMainFrame(),
+ i18n.PROGRESS_DIALOG_TITLE, dbObjs.length);
+
+ cb.setLoadingPrefix(i18n.LOADING_PREFIX);
+ selectedTables = SQLUtilities.getInsertionOrder(selectedTables, md, cb);
+ cb.setVisible(false);
+ cb.dispose();
+
+ _plugin.setSelectedDatabaseObjects(selectedTables.toArray(new IDatabaseObjectInfo[dbObjs.length]));
+
+ }
+ else
+ {
+ _plugin.setSelectedDatabaseObjects(dbObjs);
+ }
+ }
+
+
}
\ No newline at end of file
Modified: trunk/sql12/plugins/postgres/src/main/java/net/sourceforge/squirrel_sql/plugins/postgres/commands/handler/ProgressSQLExecuterHandler.java
===================================================================
--- trunk/sql12/plugins/postgres/src/main/java/net/sourceforge/squirrel_sql/plugins/postgres/commands/handler/ProgressSQLExecuterHandler.java 2010-10-30 18:06:17 UTC (rev 5945)
+++ trunk/sql12/plugins/postgres/src/main/java/net/sourceforge/squirrel_sql/plugins/postgres/commands/handler/ProgressSQLExecuterHandler.java 2010-10-30 18:14:42 UTC (rev 5946)
@@ -18,25 +18,30 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-import net.sourceforge.squirrel_sql.client.gui.ProgessCallBackDialog;
+import java.sql.ResultSet;
+import java.sql.SQLWarning;
+
+import javax.swing.JDialog;
+
+import net.sourceforge.squirrel_sql.client.gui.IProgressCallBackFactory;
+import net.sourceforge.squirrel_sql.client.gui.ProgressCallBackFactory;
import net.sourceforge.squirrel_sql.client.session.ISQLExecuterHandler;
import net.sourceforge.squirrel_sql.client.session.ISession;
import net.sourceforge.squirrel_sql.client.session.SQLExecutionInfo;
import net.sourceforge.squirrel_sql.fw.datasetviewer.IDataSetUpdateableTableModel;
+import net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack;
import net.sourceforge.squirrel_sql.fw.sql.SQLExecutionException;
import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
-import javax.swing.*;
-import java.sql.ResultSet;
-import java.sql.SQLWarning;
-
public abstract class ProgressSQLExecuterHandler implements ISQLExecuterHandler
{
protected ISession _session;
- protected ProgessCallBackDialog _pdialog;
+ protected ProgressCallBack _pdialog;
+ protected IProgressCallBackFactory progressCallBackFactory = new ProgressCallBackFactory();
+
protected String _commandPrefix;
/**
@@ -48,10 +53,15 @@
String commandPrefix)
{
_session = session;
- _pdialog = new ProgessCallBackDialog(owner, progressDialogTitle, 0);
+ _pdialog = progressCallBackFactory.create(owner, progressDialogTitle, 0);
_commandPrefix = commandPrefix;
}
+ public void setProgressCallBackFactory(IProgressCallBackFactory progressCallBackFactory)
+ {
+ this.progressCallBackFactory = progressCallBackFactory;
+ }
+
public void sqlToBeExecuted(String sql)
{
if (s_log.isDebugEnabled())
@@ -94,13 +104,7 @@
public void sqlExecutionCancelled()
{
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- _pdialog.dispose();
- }
- });
+ _pdialog.dispose();
}
public void sqlDataUpdated(int updateCount)
@@ -120,12 +124,6 @@
{
s_log.info(message);
}
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- _pdialog.dispose();
- }
- });
+ _pdialog.dispose();
}
}
Modified: trunk/sql12/plugins/refactoring/src/main/java/net/sourceforge/squirrel_sql/plugins/refactoring/commands/DropTablesCommand.java
===================================================================
--- trunk/sql12/plugins/refactoring/src/main/java/net/sourceforge/squirrel_sql/plugins/refactoring/commands/DropTablesCommand.java 2010-10-30 18:06:17 UTC (rev 5945)
+++ trunk/sql12/plugins/refactoring/src/main/java/net/sourceforge/squirrel_sql/plugins/refactoring/commands/DropTablesCommand.java 2010-10-30 18:14:42 UTC (rev 5946)
@@ -26,7 +26,8 @@
import java.util.HashSet;
import java.util.List;
-import net.sourceforge.squirrel_sql.client.gui.ProgessCallBackDialog;
+import net.sourceforge.squirrel_sql.client.gui.IProgressCallBackFactory;
+import net.sourceforge.squirrel_sql.client.gui.ProgressCallBackFactory;
import net.sourceforge.squirrel_sql.client.session.DefaultSQLExecuterHandler;
import net.sourceforge.squirrel_sql.client.session.ISession;
import net.sourceforge.squirrel_sql.client.session.SQLExecuterTask;
@@ -37,6 +38,7 @@
import net.sourceforge.squirrel_sql.fw.sql.ForeignKeyInfo;
import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
+import net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack;
import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
import net.sourceforge.squirrel_sql.fw.sql.SQLUtilities;
import net.sourceforge.squirrel_sql.fw.util.StringManager;
@@ -79,8 +81,10 @@
private List<ITableInfo> orderedTables;
- ProgessCallBackDialog getOrderedTablesCallBack;
+ ProgressCallBack getOrderedTablesCallBack;
+ private IProgressCallBackFactory progressCallBackFactory = new ProgressCallBackFactory();
+
/**
* A set of materialized view names in the same schema as the table(s) being dropped.
*/
@@ -135,7 +139,8 @@
if (tables.size() > 1)
{
orderedTables = getOrderedTables(tables);
- } else
+ }
+ else
{
orderedTables = tables;
}
@@ -171,7 +176,8 @@
_dialect.getTableDropSQL(info, cascadeConstraints, isMaterializedView, _qualifier, _sqlPrefs);
result.addAll(sqls);
}
- } catch (final UnsupportedOperationException e2)
+ }
+ catch (final UnsupportedOperationException e2)
{
_session.showMessage(s_stringMgr.getString("DropTablesCommand.unsupportedOperationMsg",
_dialect.getDisplayName()));
@@ -220,18 +226,10 @@
}
final SQLDatabaseMetaData md = _session.getSQLConnection().getSQLMetaData();
- // Create the analysis dialog using the EDT, and wait for it to finish.
- GUIUtils.processOnSwingEventThread(new Runnable()
- {
- public void run()
- {
- getOrderedTablesCallBack =
- new ProgessCallBackDialog(customDialog, i18n.PROGRESS_DIALOG_ANALYZE_TITLE, tables.size());
+ ProgressCallBack getOrderedTablesCallBack =
+ progressCallBackFactory.create(customDialog, i18n.PROGRESS_DIALOG_ANALYZE_TITLE, tables.size());
+ getOrderedTablesCallBack.setLoadingPrefix(i18n.LOADING_PREFIX);
- getOrderedTablesCallBack.setLoadingPrefix(i18n.LOADING_PREFIX);
- }
- }, true);
-
// Now, get the drop order (same as delete) and update the dialog
// status while doing so.
final List<ITableInfo> result = SQLUtilities.getDeletionOrder(tables, md, getOrderedTablesCallBack);
@@ -293,7 +291,8 @@
final String tableName = rs.getString(1);
matViewLookup.add(tableName);
}
- } finally
+ }
+ finally
{
SQLUtilities.closeResultSet(rs);
SQLUtilities.closeStatement(stmt);
@@ -318,16 +317,16 @@
final SQLExecuterTask executer = new SQLExecuterTask(_session, script, handler);
executer.setSchemaCheck(false);
executer.run();
-
+
GUIUtils.processOnSwingEventThread(new Runnable()
{
public void run()
{
- handler.hideProgressDialog();
+ handler.hideProgressDialog();
customDialog.setVisible(false);
}
});
-
+
_session.getSchemaInfo().reloadAllTables();
}
});
@@ -352,7 +351,7 @@
private class DropTableCommandExecHandler extends DefaultSQLExecuterHandler
{
- ProgessCallBackDialog cb = null;
+ ProgressCallBack cb = null;
/**
* This is used to track the number of tables seen so far, so that we can pick the right one from the
@@ -363,20 +362,22 @@
public DropTableCommandExecHandler(final ISession session)
{
super(session);
+
cb =
- new ProgessCallBackDialog( customDialog,
- i18n.PROGRESS_DIALOG_DROP_TITLE,
- DropTablesCommand.this.orderedTables.size());
+ progressCallBackFactory.create(customDialog, i18n.PROGRESS_DIALOG_DROP_TITLE,
+ DropTablesCommand.this.orderedTables.size());
+
}
/**
* hides the progress dialog.
*/
- public void hideProgressDialog() {
+ public void hideProgressDialog()
+ {
cb.setVisible(false);
cb.dispose();
}
-
+
/**
* @see net.sourceforge.squirrel_sql.client.session.DefaultSQLExecuterHandler#sqlStatementCount(int)
*/
@@ -403,7 +404,8 @@
// Hack!!! hopefully the FK name will always be the last token!
final String[] parts = StringUtilities.split(sql, ' ');
cb.currentlyLoading(parts[parts.length - 1]);
- } else
+ }
+ else
{
cb.setLoadingPrefix(i18n.DROPPING_TABLE_PREFIX);
if (tableCount < DropTablesCommand.this.orderedTables.size())
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|