Revision: 6610
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6610&view=rev
Author: gerdwagner
Date: 2012-04-07 15:50:57 +0000 (Sat, 07 Apr 2012)
Log Message:
-----------
Fixed some event dispatch thread violations in sql to file export
Modified Paths:
--------------
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressAbortDialog.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/AbstractExportCommand.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ResultSetExportCommand.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/AbstractDataExportFileWriter.java
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressAbortDialog.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressAbortDialog.java 2012-04-07 14:48:32 UTC (rev 6609)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressAbortDialog.java 2012-04-07 15:50:57 UTC (rev 6610)
@@ -315,14 +315,23 @@
*/
private void appendToHistory(String string) {
if (this.historyArea != null) {
- StringBuilder sb = new StringBuilder();
+ final StringBuilder sb = new StringBuilder();
sb.append(dateFormat.format(new Date()));
sb.append(": ");
sb.append(string);
sb.append(StringUtilities.getEolStr());
- this.historyArea.append(sb.toString());
- this.historyArea.setCaretPosition(historyArea.getDocument().getLength());
- }
+
+ Runnable runnable = new Runnable()
+ {
+ public void run()
+ {
+ historyArea.append(sb.toString());
+ historyArea.setCaretPosition(historyArea.getDocument().getLength());
+ }
+ };
+
+ GUIUtils.processOnSwingEventThread(runnable);
+ }
}
/**
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/AbstractExportCommand.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/AbstractExportCommand.java 2012-04-07 14:48:32 UTC (rev 6609)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/AbstractExportCommand.java 2012-04-07 15:50:57 UTC (rev 6610)
@@ -20,9 +20,10 @@
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
import java.text.NumberFormat;
-import javax.swing.JOptionPane;
+import javax.swing.*;
import net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.ClobDescriptor;
import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
@@ -126,10 +127,20 @@
Object[] params = new Object[] { file, e.getMessage() };
// i18n[TableExportCsvCommand.failedToWriteFile=Failed to write
// file\n{0}\nError message\n{1}\nSee last log entry for details.]
- String msg = s_stringMgr.getString("TableExportCsvCommand.failedToWriteFile", params);
+ final String msg = s_stringMgr.getString("TableExportCsvCommand.failedToWriteFile", params);
s_log.error(msg, e);
- JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), msg);
- return -1;
+
+ Runnable runnable = new Runnable()
+ {
+ public void run()
+ {
+ JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), msg);
+ }
+ };
+
+ GUIUtils.processOnSwingEventThread(runnable, true);
+
+ return -1;
}
}
@@ -145,113 +156,181 @@
{
Object[] params = new Object[]{command, e.getMessage()};
// i18n[TableExportCsvCommand.failedToExecuteCommand=Failed to execute\n{0}\nError message\n{1}\nSee last log entry for details.]
- String msg = s_stringMgr.getString("TableExportCsvCommand.failedToExecuteCommand", params);
+ final String msg = s_stringMgr.getString("TableExportCsvCommand.failedToExecuteCommand", params);
s_log.error(msg, e);
- JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), msg);
- }
+
+ Runnable runnable = new Runnable()
+ {
+ public void run()
+ {
+ JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), msg);
+ }
+ };
+
+ GUIUtils.processOnSwingEventThread(runnable, true);
+ }
}
-
- public void execute() throws ExportDataException
- {
- try{
-
- boolean fileIsInUse = false;
-
- TableExportCsvController ctrl;
- do{
- ctrl = createTableExportController();
- if(false == ctrl.isOK())
- {
- return;
- }
+ public void execute() throws ExportDataException
+ {
+ try
+ {
- if (checkMissingData(ctrl.getSeparatorChar())) {
- int choice = JOptionPane.showConfirmDialog(GUIUtils.getMainFrame(),
- i18n.missingClobDataMsg);
- if (choice == JOptionPane.YES_OPTION) {
- // Need to somehow call
- // SQLResultExecuterPanel.reRunSelectedResultTab(true);
- //
- // Something like :
- // SQLResultExecuterPanel panel = getPanel();
- // panel.reRunSelectedResultTab(true);
- //
- // However, that doesn't apply when the user is exporting from the
- // table contents table. There needs to be a more generic way to
- // do this for all tables containing data that is to be exported
- // where some of the fields contain placeholders.
- // For now, we just inform the user and let them either continue
- // or abort and change the configuration manually,
- // re-run the query / reload the table data and re-export.
- }
- if (choice == JOptionPane.NO_OPTION) {
- // abort the export
- return;
- }
- if (choice == JOptionPane.CANCEL_OPTION) {
- // abort the export
- return;
- }
- }
+ boolean fileIsInUse = false;
- this.targetFile = ctrl.getFile();
-
- /*
- * Allow only one export at a time.
- */
- if(fileContainer.add(this.targetFile) == false){
- fileIsInUse = true;
- JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), i18n.ANOTHER_EXPORT_IS_ACTIVE, i18n.TITLE_ANOTHER_EXPORT_IS_ACTIVE, JOptionPane.WARNING_MESSAGE);
- }else {
- fileIsInUse = false;
- }
-
- }while(fileIsInUse);
+ TableExportCsvController ctrl;
+ do
+ {
+ ctrl = createTableExportController();
+ if (false == ctrl.isOK())
+ {
+ return;
+ }
- this.progressController = createProgressController();
+ if (checkMissingData(ctrl.getSeparatorChar()))
+ {
+ int choice = JOptionPane.showConfirmDialog(GUIUtils.getMainFrame(),
+ i18n.missingClobDataMsg);
+ if (choice == JOptionPane.YES_OPTION)
+ {
+ // Need to somehow call
+ // SQLResultExecuterPanel.reRunSelectedResultTab(true);
+ //
+ // Something like :
+ // SQLResultExecuterPanel panel = getPanel();
+ // panel.reRunSelectedResultTab(true);
+ //
+ // However, that doesn't apply when the user is exporting from the
+ // table contents table. There needs to be a more generic way to
+ // do this for all tables containing data that is to be exported
+ // where some of the fields contain placeholders.
+ // For now, we just inform the user and let them either continue
+ // or abort and change the configuration manually,
+ // re-run the query / reload the table data and re-export.
+ }
+ if (choice == JOptionPane.NO_OPTION)
+ {
+ // abort the export
+ return;
+ }
+ if (choice == JOptionPane.CANCEL_OPTION)
+ {
+ // abort the export
+ return;
+ }
+ }
+ this.targetFile = ctrl.getFile();
+ /*
+ * Allow only one export at a time.
+ */
+ if (fileContainer.add(this.targetFile) == false)
+ {
+ fileIsInUse = true;
+ Runnable runnable = new Runnable()
+ {
+ public void run()
+ {
+ JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), i18n.ANOTHER_EXPORT_IS_ACTIVE, i18n.TITLE_ANOTHER_EXPORT_IS_ACTIVE, JOptionPane.WARNING_MESSAGE);
+ }
+ };
- try {
- writtenRows = writeFile(ctrl, createExportData(ctrl));
- } catch (ExportDataException e) {
- // Show an error and re-throw the exception.
- s_log.error(i18n.FAILED);
- JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), i18n.FAILED);
- throw e;
- }
+ GUIUtils.processOnSwingEventThread(runnable, true);
- if(writtenRows >= 0){
- String command = ctrl.getCommand();
+ }
+ else
+ {
+ fileIsInUse = false;
+ }
- if(null != command)
- {
- executeCommand(command);
- } else {
- // i18n[TableExportCsvCommand.writeFileSuccess=Export to file
- // "{0}" is complete.]
- String msg =
- s_stringMgr.getString("TableExportCsvCommand.writeFileSuccess", NumberFormat.getIntegerInstance().format(writtenRows),
- ctrl.getFile().getAbsolutePath());
- if (s_log.isInfoEnabled()) {
- s_log.info(msg);
- }
- JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), msg);
- }
- }else{
- s_log.info(i18n.FAILED);
- JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), i18n.FAILED);
- }
- }finally{
- if(this.targetFile != null){
- this.fileContainer.remove(this.targetFile);
- }
- }
- }
+ } while (fileIsInUse);
- /**
+
+ this.progressController = createProgressController();
+
+
+ try
+ {
+ writtenRows = writeFile(ctrl, createExportData(ctrl));
+ }
+ catch (ExportDataException e)
+ {
+ // Show an error and re-throw the exception.
+ s_log.error(i18n.FAILED);
+
+ Runnable runnable = new Runnable()
+ {
+ public void run()
+ {
+ JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), i18n.FAILED);
+ }
+ };
+
+ GUIUtils.processOnSwingEventThread(runnable);
+
+ throw e;
+ }
+
+ if (writtenRows >= 0)
+ {
+ String command = ctrl.getCommand();
+
+ if (null != command)
+ {
+ executeCommand(command);
+ }
+ else
+ {
+ // i18n[TableExportCsvCommand.writeFileSuccess=Export to file
+ // "{0}" is complete.]
+ final String msg =
+ s_stringMgr.getString("TableExportCsvCommand.writeFileSuccess", NumberFormat.getIntegerInstance().format(writtenRows),
+ ctrl.getFile().getAbsolutePath());
+ if (s_log.isInfoEnabled())
+ {
+ s_log.info(msg);
+ }
+
+ Runnable runnable = new Runnable()
+ {
+ public void run()
+ {
+ JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), msg);
+ }
+ };
+
+ GUIUtils.processOnSwingEventThread(runnable, true);
+
+ }
+ }
+ else
+ {
+ s_log.info(i18n.FAILED);
+
+ Runnable runnable = new Runnable()
+ {
+ public void run()
+ {
+ JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), i18n.FAILED);
+ }
+ };
+
+ GUIUtils.processOnSwingEventThread(runnable, true);
+
+ }
+ }
+ finally
+ {
+ if (this.targetFile != null)
+ {
+ this.fileContainer.remove(this.targetFile);
+ }
+ }
+ }
+
+ /**
* Create a instance of {@link ProgressAbortCallback} if necessary.
* Subclasse may override this.
* @return returns null.
@@ -265,9 +344,28 @@
* @return
*/
protected TableExportCsvController createTableExportController() {
- return new TableExportCsvController();
- }
+ try
+ {
+ final TableExportCsvController[] buf = new TableExportCsvController[1];
+
+ Runnable runnable = new Runnable()
+ {
+ public void run()
+ {
+ buf[0] = new TableExportCsvController();
+ }
+ };
+ GUIUtils.processOnSwingEventThread(runnable, true);
+
+ return buf[0];
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
/**
* @param separatorChar
* @return
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ResultSetExportCommand.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ResultSetExportCommand.java 2012-04-07 14:48:32 UTC (rev 6609)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ResultSetExportCommand.java 2012-04-07 15:50:57 UTC (rev 6610)
@@ -23,6 +23,7 @@
import java.sql.Statement;
import net.sourceforge.squirrel_sql.fw.dialects.DialectType;
+import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
import net.sourceforge.squirrel_sql.fw.gui.action.exportData.ExportDataException;
import net.sourceforge.squirrel_sql.fw.gui.action.exportData.IExportData;
import net.sourceforge.squirrel_sql.fw.gui.action.exportData.ResultSetExportData;
@@ -33,6 +34,8 @@
import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
+import javax.swing.*;
+
/**
* Command for exporting a result set to a file.
*
@@ -105,10 +108,30 @@
* @see net.sourceforge.squirrel_sql.fw.gui.action.AbstractExportCommand#createTableExportController()
*/
@Override
- protected TableExportCsvController createTableExportController() {
- return new ResultSetExportCsvController();
- }
+ protected TableExportCsvController createTableExportController()
+ {
+ try
+ {
+ final ResultSetExportCsvController[] buf = new ResultSetExportCsvController[1];
+ Runnable runnable = new Runnable()
+ {
+ public void run()
+ {
+ buf[0] = new ResultSetExportCsvController();
+ }
+ };
+
+ GUIUtils.processOnSwingEventThread(runnable, true);
+
+ return buf[0];
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
/**
* Create a new {@link ProgressAbortCallback}.
* @see net.sourceforge.squirrel_sql.fw.gui.action.AbstractExportCommand#createProgressController()
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/AbstractDataExportFileWriter.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/AbstractDataExportFileWriter.java 2012-04-07 14:48:32 UTC (rev 6609)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/AbstractDataExportFileWriter.java 2012-04-07 15:50:57 UTC (rev 6610)
@@ -21,6 +21,7 @@
import java.io.File;
import java.text.NumberFormat;
import java.util.Iterator;
+import java.util.concurrent.TimeUnit;
import javax.swing.plaf.SliderUI;
@@ -69,7 +70,7 @@
/**
* Constant, for updating the progress bar each x seconds.
*/
- private static final int FEEDBACK_EVRY_N_SECONDS = 5;
+ private static final int FEEDBACK_EVRY_N_SECONDS = 2;
/**
* The target file.
*/
@@ -178,7 +179,8 @@
*/
private boolean isStatusUpdateNecessary() {
long time = System.currentTimeMillis();
- if((timeOfLastStatusUpdate + FEEDBACK_EVRY_N_SECONDS*1000) < time){
+
+ if((timeOfLastStatusUpdate + TimeUnit.SECONDS.toMillis(FEEDBACK_EVRY_N_SECONDS)) < time){
timeOfLastStatusUpdate = time;
return true;
}else{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|