Revision: 6352
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6352&view=rev
Author: wis775
Date: 2011-08-09 20:14:20 +0000 (Tue, 09 Aug 2011)
Log Message:
-----------
Store result of SQL in file:
- Now, the progress monitor appears after the export config dialog is closed.
- The progress monitor shows the file and SQL in a readable format
- The title of the progress monitor contains the name of the target file
- After a sucessfully export, the number of rows, the file and the elapsed time is shown in the message panel
Modified Paths:
--------------
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressAbortDialog.java
trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/gui/I18NStrings.properties
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
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/IDataExportWriter.java
trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/I18NStrings.properties
trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/CreateFileOfCurrentSQLCommand.java
trunk/sql12/plugins/sqlscript/src/main/resources/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/I18NStrings.properties
Added Paths:
-----------
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/ProgressAbortFactoryCallback.java
trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/SQL2FileProgressAbortDialog.java
trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/gui/
trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/gui/TaskDescriptionComponent.java
trunk/sql12/plugins/sqlscript/src/main/resources/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/gui/
trunk/sql12/plugins/sqlscript/src/main/resources/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/gui/I18NStrings.properties
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 2011-08-09 18:44:59 UTC (rev 6351)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressAbortDialog.java 2011-08-09 20:14:20 UTC (rev 6352)
@@ -32,6 +32,7 @@
import javax.swing.BorderFactory;
import javax.swing.JButton;
+import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
@@ -88,6 +89,8 @@
// i18n[ProgressAbortDialog.confirmCancel=Should the export be canceled?]
String CONFIRM_CANCEL = s_stringMgr.getString("ProgressAbortDialog.confirmCancel");
+
+ String TITEL_PROGRESS = s_stringMgr.getString("ProgressAbortDialog.titelProgress");
}
/**
@@ -139,7 +142,7 @@
/**
* Description of the long running operation.
*/
- private JLabel taskDescriptionLabel;
+ private JComponent taskDescriptionComponent;
/**
* Flag, if the operation should be canceled
@@ -151,6 +154,12 @@
* Someone told us, that all tasks are done.
*/
private boolean finished;
+
+
+ /**
+ * A simple description for this task
+ */
+ private String simpleTaskDescription = null;
/**
* Constructor which accepts a Dialog owner
@@ -263,6 +272,8 @@
if(StringUtils.isNotBlank(status)){
statusText.append(status);
+ }else{
+ statusText.append(" ");
}
try
@@ -372,14 +383,15 @@
itemCount = totalItems;
this.indeterminate = intermediate;
this.abortHandler = abortHandler;
+ this.simpleTaskDescription = description;
final Window owner = super.getOwner();
final ProgressAbortDialog dialog = this;
- createGUI(description);
+ createGUI();
setLocationRelativeTo(owner);
dialog.setVisible(true);
}
- private void createGUI(String description)
+ private void createGUI()
{
JPanel dialogPanel = new JPanel(new GridBagLayout());
dialogPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
@@ -388,27 +400,41 @@
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
- c.fill = GridBagConstraints.HORIZONTAL;
+ c.fill = GridBagConstraints.BOTH;
+ c.weightx=1.0;
+ c.weighty=0.5;
c.anchor = GridBagConstraints.WEST;
c.insets = new Insets(4, 0, 4, 0);
- taskDescriptionLabel = new JLabel(description);
- dialogPanel.add(taskDescriptionLabel, c);
+ taskDescriptionComponent = createTaskDescripion();
+ dialogPanel.add(taskDescriptionComponent, c);
+
c.gridy++;
+ JPanel progressPanel = new JPanel(new GridBagLayout());
+ progressPanel.setMinimumSize(new Dimension(400,200));
+ progressPanel.setPreferredSize(new Dimension(400,200));
+ progressPanel.setBorder(BorderFactory.createTitledBorder("Progress"));
+ dialogPanel.add(progressPanel, c);
+
+ c.gridy = 0;
+ c.gridx = 0;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.weightx=0.0;
+ c.weighty=0.0;
c.insets = new Insets(4, 10, 4, 10);
statusLabel = new JLabel(i18n.INITIAL_LOADING_PREFIX);
- dialogPanel.add(statusLabel, c);
+ progressPanel.add(statusLabel, c);
c.gridy++;
c.insets = new Insets(4, 10, 4, 10);
- additionalStatusLabel = new JLabel();
- dialogPanel.add(additionalStatusLabel, c);
+ additionalStatusLabel = new JLabel(" "); // Must be a space :-)
+ progressPanel.add(additionalStatusLabel, c);
c.gridy++;
c.weightx = 1.0;
progressBar = new JProgressBar(0, itemCount);
progressBar.setIndeterminate(indeterminate);
- dialogPanel.add(progressBar, c);
+ progressPanel.add(progressBar, c);
c.gridy++;
c.fill = GridBagConstraints.BOTH;
@@ -417,7 +443,7 @@
historyArea = new JTextArea();
historyArea.setEditable(false);
JScrollPane jScrollPane = new JScrollPane(historyArea);
- dialogPanel.add(jScrollPane, c);
+ progressPanel.add(jScrollPane, c);
if(abortHandler != null){
@@ -445,9 +471,20 @@
super.getContentPane().add(dialogPanel);
super.pack();
- super.setSize(new Dimension(400, 400));
+ super.setSize(new Dimension(450, 450));
super.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
}
+
+ /**
+ * Creates the description of the task/operation.
+ * Per default, this will be a simple {@link JLabel} with the {@link #simpleTaskDescription} of this dialog..
+ * A subclass may override this for a solution, that is more sophisticated.
+ * @see #simpleTaskDescription
+ * @return a {@link JComponent} as task description
+ */
+ protected JComponent createTaskDescripion() {
+ return new JLabel(this.simpleTaskDescription);
+ }
/**
* Just for playing...
Modified: trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/gui/I18NStrings.properties
===================================================================
--- trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/gui/I18NStrings.properties 2011-08-09 18:44:59 UTC (rev 6351)
+++ trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/gui/I18NStrings.properties 2011-08-09 20:14:20 UTC (rev 6352)
@@ -56,6 +56,7 @@
ProgressAbortDialog.defaultLoadingPrefix=Loading:
ProgressAbortDialog.initialLoadingPrefix=Loading...
ProgressAbortDialog.confirmCancel=Should the operation be canceled?
+ProgressAbortDialog.titelProgress=Progress
SplashScreen.error.updatingprogressbar=Error occured updating progress bar
SplashScreen.info.loadingfile=Loading file -
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 2011-08-09 18:44:59 UTC (rev 6351)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/AbstractExportCommand.java 2011-08-09 20:14:20 UTC (rev 6352)
@@ -20,6 +20,7 @@
import java.io.File;
import java.io.IOException;
+import java.text.NumberFormat;
import javax.swing.JOptionPane;
@@ -74,23 +75,23 @@
static ILogger s_log = LoggerController.createLogger(AbstractExportCommand.class);
private ProgressAbortCallback progressController = null;
+ private File targetFile;
+ private long writtenRows = -1;
/**
* @param progressController
*/
public AbstractExportCommand() {
}
-
+
/**
- * @param progressController
+ * Exports the data structure.
+ * @param ctrl the controller to use
+ * @param data The data to export
+ * @return the number of written data rows or a negative value, if not the whole data are exported.
*/
- public AbstractExportCommand(ProgressAbortCallback progressController) {
- this.progressController =progressController;
- }
-
-
- protected boolean writeFile(TableExportCsvController ctrl, IExportData data) {
+ protected long writeFile(TableExportCsvController ctrl, IExportData data) {
File file = null;
try {
@@ -119,7 +120,7 @@
String msg = s_stringMgr.getString("TableExportCsvCommand.failedToWriteFile", params);
s_log.error(msg, e);
JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), msg);
- return false;
+ return -1;
}
}
@@ -179,10 +180,14 @@
}
}
- boolean writeFileSuccess = false;
+ this.targetFile = ctrl.getFile();
+ this.progressController = createProgressController();
+
+
+
try {
- writeFileSuccess = writeFile(ctrl, createExportData(ctrl));
+ writtenRows = writeFile(ctrl, createExportData(ctrl));
} catch (ExportDataException e) {
// Show an error and re-throw the exception.
s_log.error(i18n.FAILED);
@@ -190,7 +195,7 @@
throw e;
}
- if(writeFileSuccess){
+ if(writtenRows >= 0){
String command = ctrl.getCommand();
if(null != command)
@@ -200,7 +205,7 @@
// i18n[TableExportCsvCommand.writeFileSuccess=Export to file
// "{0}" is complete.]
String msg =
- s_stringMgr.getString("TableExportCsvCommand.writeFileSuccess",
+ s_stringMgr.getString("TableExportCsvCommand.writeFileSuccess", NumberFormat.getIntegerInstance().format(writtenRows),
ctrl.getFile().getAbsolutePath());
if (s_log.isInfoEnabled()) {
s_log.info(msg);
@@ -214,6 +219,16 @@
}
/**
+ * Create a instance of {@link ProgressAbortCallback} if necessary.
+ * Subclasse may override this.
+ * @return returns null.
+ */
+ protected ProgressAbortCallback createProgressController() {
+ // default null;
+ return null;
+ }
+
+ /**
* @return
*/
protected TableExportCsvController createTableExportController() {
@@ -256,6 +271,20 @@
progressController.currentlyLoading(task);
}
}
+
+ /**
+ * @return the targetFile
+ */
+ public File getTargetFile() {
+ return targetFile;
+ }
+
+ /**
+ * @return the writtenRows
+ */
+ public long getWrittenRows() {
+ return writtenRows;
+ }
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 2011-08-09 18:44:59 UTC (rev 6351)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ResultSetExportCommand.java 2011-08-09 20:14:20 UTC (rev 6352)
@@ -27,6 +27,7 @@
import net.sourceforge.squirrel_sql.fw.gui.action.exportData.IExportData;
import net.sourceforge.squirrel_sql.fw.gui.action.exportData.ResultSetExportData;
import net.sourceforge.squirrel_sql.fw.sql.ProgressAbortCallback;
+import net.sourceforge.squirrel_sql.fw.sql.ProgressAbortFactoryCallback;
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;
@@ -38,7 +39,7 @@
* @author Stefan Willinger
*
*/
-public class ResultSetExportCommand extends AbstractExportCommand {
+public class ResultSetExportCommand extends AbstractExportCommand {
static final StringManager s_stringMgr = StringManagerFactory
.getStringManager(ResultSetExportCommand.class);
@@ -59,12 +60,15 @@
private Statement stmt;
+ private ProgressAbortFactoryCallback progressControllerFactory;
+
public ResultSetExportCommand(Statement stmt, String sql, DialectType dialect,
- ProgressAbortCallback progressController) {
- super(progressController);
+ ProgressAbortFactoryCallback progressControllerFactory) {
+ super();
this.sql = sql;
this.stmt = stmt;
this.dialect = dialect;
+ this.progressControllerFactory = progressControllerFactory;
}
/**
@@ -99,4 +103,21 @@
return new ResultSetExportCsvController();
}
+ /**
+ * Create a new {@link ProgressAbortCallback}.
+ * @see net.sourceforge.squirrel_sql.fw.gui.action.AbstractExportCommand#createProgressController()
+ * @see ProgressAbortFactoryCallback
+ */
+ @Override
+ protected ProgressAbortCallback createProgressController() {
+ return this.progressControllerFactory.create();
+ }
+
+ /**
+ * @return the sql
+ */
+ public String getSql() {
+ return sql;
+ }
+
}
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 2011-08-09 18:44:59 UTC (rev 6351)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/AbstractDataExportFileWriter.java 2011-08-09 20:14:20 UTC (rev 6352)
@@ -110,7 +110,7 @@
/**
* @see net.sourceforge.squirrel_sql.fw.gui.action.exportData.IDataExportWriter#write(net.sourceforge.squirrel_sql.fw.gui.action.exportData.IExportData)
*/
- public boolean write(IExportData data) throws Exception {
+ public long write(IExportData data) throws Exception {
beforeWorking(file);
@@ -131,11 +131,14 @@
progress(i18n.BEGIN_WRITING);
beforeRows();
- long rowsCount = 1;
+ long rowsCount = 0;
NumberFormat nfRowCount = NumberFormat.getInstance();
while (rows.hasNext() && isStop() == false) {
+ // FIXME - remove
+ Thread.sleep(500);
+ rowsCount++;
IExportDataRow aRow = rows.next();
if(isStatusUpdateNecessary()){
taskStatus(s_stringMgr.getString(i18n.KEY_NUMBER_OF_ROWS_COMPLETED, nfRowCount.format(rowsCount)));
@@ -148,7 +151,6 @@
addCell(cell);
}
afterRow();
- rowsCount++;
}
progress(s_stringMgr.getString(i18n.KEY_FINISHED_LOADING, nfRowCount.format(rowsCount)));
afterRows();
@@ -163,9 +165,9 @@
}
if (isStop()) {
- return false;
+ return -1;
} else {
- return true;
+ return rowsCount;
}
}
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/IDataExportWriter.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/IDataExportWriter.java 2011-08-09 18:44:59 UTC (rev 6351)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/IDataExportWriter.java 2011-08-09 20:14:20 UTC (rev 6352)
@@ -27,8 +27,8 @@
/**
* Exports the data structure.
* @param data The data to export
- * @return true, if the export was successfully, otherwise false.
+ * @return the number of written data rows or a negative value, if not the whole data are exported.
* @throws Exception if any Exception occurs
*/
- boolean write(IExportData data) throws Exception;
+ long write(IExportData data) throws Exception;
}
Added: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/ProgressAbortFactoryCallback.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/ProgressAbortFactoryCallback.java (rev 0)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/ProgressAbortFactoryCallback.java 2011-08-09 20:14:20 UTC (rev 6352)
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2011 Stefan Willinger
+ * wi...@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
+ */
+package net.sourceforge.squirrel_sql.fw.sql;
+
+import net.sourceforge.squirrel_sql.fw.gui.action.TableExportCsvController;
+
+/**
+ * Callback to create instances of {@link ProgressAbortCallback}.
+ * Thin interface is a part between the connection of the framework classes and the GUI.
+ * @author Stefan Willinger
+ * @see ProgressCallBack
+ * @see IAbortController
+ */
+public interface ProgressAbortFactoryCallback {
+ ProgressAbortCallback create();
+}
Property changes on: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/ProgressAbortFactoryCallback.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/I18NStrings.properties
===================================================================
--- trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/I18NStrings.properties 2011-08-09 18:44:59 UTC (rev 6351)
+++ trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/I18NStrings.properties 2011-08-09 20:14:20 UTC (rev 6352)
@@ -34,7 +34,7 @@
TableExportCsvCommand.failedToWriteFile=Failed to write file\n{0}\nError message\n{1}\nSee last log entry for details.
TableExportCsvCommand.failedToExecuteCommand=Failed to execute\n{0}\nError message\n{1}\nSee last log entry for details.
TableExportCsvCommand.missingClobDataMsg=Found Clob placeholder({0}) amongst data to be exported. Continue exporting cell data?
-TableExportCsvCommand.writeFileSuccess=Export to file "{0}" is complete.
+TableExportCsvCommand.writeFileSuccess=Export of {0} rows to file "{1}" is complete.
AbstractExportCommand.failed=Failed to export the SQL Select statement into a file.
TableExportCsvController.fileChooserTitel=Choose export file
Modified: trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/CreateFileOfCurrentSQLCommand.java
===================================================================
--- trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/CreateFileOfCurrentSQLCommand.java 2011-08-09 18:44:59 UTC (rev 6351)
+++ trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/CreateFileOfCurrentSQLCommand.java 2011-08-09 20:14:20 UTC (rev 6352)
@@ -19,25 +19,32 @@
package net.sourceforge.squirrel_sql.plugins.sqlscript.table_script;
import java.awt.Frame;
+import java.io.File;
import java.sql.SQLException;
import java.sql.Statement;
+import java.text.NumberFormat;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
+import org.apache.commons.lang.time.StopWatch;
+
import net.sourceforge.squirrel_sql.client.gui.IAbortEventHandler;
import net.sourceforge.squirrel_sql.client.gui.ProgressAbortDialog;
import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.fw.codereformat.CodeReformator;
+import net.sourceforge.squirrel_sql.fw.codereformat.CommentSpec;
import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
import net.sourceforge.squirrel_sql.fw.dialects.DialectType;
import net.sourceforge.squirrel_sql.fw.gui.action.ResultSetExportCommand;
import net.sourceforge.squirrel_sql.fw.gui.action.TableExportCsvDlg;
-import net.sourceforge.squirrel_sql.fw.gui.action.exportData.ExportDataException;
import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
import net.sourceforge.squirrel_sql.fw.sql.ProgressAbortCallback;
+import net.sourceforge.squirrel_sql.fw.sql.ProgressAbortFactoryCallback;
import net.sourceforge.squirrel_sql.fw.sql.SQLUtilities;
import net.sourceforge.squirrel_sql.fw.util.StringManager;
import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
+import net.sourceforge.squirrel_sql.fw.util.StringUtilities;
import net.sourceforge.squirrel_sql.plugins.sqlscript.SQLScriptPlugin;
/**
@@ -86,7 +93,6 @@
this.currentSQL = getSelectedSelectStatement();
- showProgressMonitor();
getSession().getApplication().getThreadPool().addTask(new Runnable() {
public void run() {
doCreateFileOfCurrentSQL();
@@ -114,13 +120,39 @@
stmt = getSession().getSQLConnection().createStatement();
}
+
+ ProgressAbortFactoryCallback progressFactory = new ProgressAbortFactoryCallback() {
+ @Override
+ public ProgressAbortCallback create() {
+ createProgressAbortDialog();
+ return progressDialog;
+ }
+ };
+
+
+ StopWatch stopWatch = new StopWatch();
+ stopWatch.start();
+
DialectType dialectType =
DialectFactory.getDialectType(getSession().getMetaData());
- resultSetExportCommand = new ResultSetExportCommand(stmt, currentSQL, dialectType, progressDialog);
+ resultSetExportCommand = new ResultSetExportCommand(stmt, currentSQL, dialectType, progressFactory);
resultSetExportCommand.execute();
+ stopWatch.stop();
+
if (isAborted()) {
return;
+ }else if(resultSetExportCommand.getWrittenRows() >= 0){
+ NumberFormat nf = NumberFormat.getIntegerInstance();
+
+ String rows = nf.format(resultSetExportCommand.getWrittenRows());
+ File targetFile = resultSetExportCommand.getTargetFile();
+ String seconds = nf.format(stopWatch.getTime()/1000);
+ String msg = s_stringMgr.getString("CreateFileOfCurrentSQLCommand.progress.sucessMessage",
+ rows,
+ targetFile,
+ seconds);
+ getSession().showMessage(msg);
}
} finally {
SQLUtilities.closeStatement(stmt);
@@ -166,29 +198,56 @@
/**
* Create and show a new progress monitor with the ability to cancel the task.
*/
- protected void showProgressMonitor() {
-
- // i18n[CreateFileOfCurrentSQLCommand.progress.description=Exporting the SQL {0} into a file.]
- String description = s_stringMgr.getString("CreateFileOfCurrentSQLCommand.progress.description", currentSQL);
-
- // i18n[CreateFileOfCurrentSQLCommand.progress.title=Exporting to a file.]
- String title = s_stringMgr.getString("CreateFileOfCurrentSQLCommand.progress.title");
- progressDialog = new ProgressAbortDialog((Frame)null, title, description, 0, true, new IAbortEventHandler() {
- @Override
- public void cancel() {
- /*
- * We need to cancel the statement at this point for the case, that we are waiting for the first rows.
- */
- if(stmt != null){
- try {
- stmt.cancel();
- } catch (SQLException e1) {
- // nothing todo
+ protected void createProgressAbortDialog() {
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
+
+ @Override
+ public void run() {
+ /*
+ * Copied from FormatSQLCommand.
+ * Is there a better way to get the CommentSpec[] ?
+ */
+
+ CommentSpec[] commentSpecs =
+ new CommentSpec[]
+ {
+ new CommentSpec("/*", "*/"),
+ new CommentSpec("--", StringUtilities.getEolStr())
+ };
+
+ String statementSep = getSession().getQueryTokenizer().getSQLStatementSeparator();
+
+ CodeReformator cr = new CodeReformator(statementSep, commentSpecs);
+
+ String reformatedSQL = cr.reformat(resultSetExportCommand.getSql());
+
+ String targetFile = resultSetExportCommand.getTargetFile().getAbsolutePath();
+
+ // i18n[CreateFileOfCurrentSQLCommand.progress.title=Exporting to a file.]
+ String title = s_stringMgr.getString("CreateFileOfCurrentSQLCommand.progress.title", targetFile);
+ progressDialog = new SQL2FileProgressAbortDialog((Frame)null, title, targetFile, reformatedSQL , new IAbortEventHandler() {
+ @Override
+ public void cancel() {
+ /*
+ * We need to cancel the statement at this point for the case, that we are waiting for the first rows.
+ */
+ if(stmt != null){
+ try {
+ stmt.cancel();
+ } catch (SQLException e1) {
+ // nothing todo
+ }
}
}
- }
- });
+ });
+ }
+ });
+ } catch (Exception e) {
+ throw new RuntimeException("Could not create the Progress Monitor.", e);
+ }
+
}
/**
Added: trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/SQL2FileProgressAbortDialog.java
===================================================================
--- trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/SQL2FileProgressAbortDialog.java (rev 0)
+++ trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/SQL2FileProgressAbortDialog.java 2011-08-09 20:14:20 UTC (rev 6352)
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2011 Stefan Willinger
+ * wi...@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
+ */
+package net.sourceforge.squirrel_sql.plugins.sqlscript.table_script;
+
+import java.awt.Dialog;
+import java.awt.Frame;
+
+import javax.swing.JComponent;
+import javax.swing.JScrollBar;
+
+import net.sourceforge.squirrel_sql.client.gui.IAbortEventHandler;
+import net.sourceforge.squirrel_sql.client.gui.ProgressAbortDialog;
+import net.sourceforge.squirrel_sql.plugins.sqlscript.table_script.gui.TaskDescriptionComponent;
+
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * A special extension for a ProgressAbortDialog, that customize the general information area about the operation.
+ * This class adds readable information about the SQL and the target file.
+ * @author Stefan Willinger
+ *
+ */
+public class SQL2FileProgressAbortDialog extends ProgressAbortDialog {
+
+
+ private String targetFile;
+
+ private String sql;
+
+ private TaskDescriptionComponent taskDescription;
+
+ /**
+ * @see ProgressAbortDialog
+ * @wbp.parser.constructor
+ */
+ public SQL2FileProgressAbortDialog(Dialog owner, String title, String targetFile, String sql, IAbortEventHandler abortHandler) {
+ super(owner, title, "", 0, true, abortHandler);
+ setTargetFile(targetFile);
+ setSql(sql);
+ setLabelValues();
+ }
+
+
+ /**
+ *
+ */
+ private void setLabelValues() {
+ taskDescription.setTargetFile(getTargetFile());
+ taskDescription.setSql(getSql());
+ }
+
+
+ /**
+ * @see ProgressAbortDialog
+ */
+ public SQL2FileProgressAbortDialog(Frame owner, String title, String targetFile, String sql, IAbortEventHandler abortHandler) {
+ super(owner, title, "", 0, true, abortHandler);
+ setTargetFile(targetFile);
+ setSql(sql);
+ setLabelValues();
+ }
+
+
+ /**
+ * Create a task description for this progress dialog.
+ * The task description is embedded in a {@link JScrollBar} and contains the following items:
+ * <ul>
+ * <li>The path of the target file</li>
+ * <li>The running SQL statement as a formated String.</li>
+ * </ul>
+ * @see net.sourceforge.squirrel_sql.client.gui.ProgressAbortDialog#createTaskDescripion()
+ * @see TaskDescriptionComponent
+ */
+ @Override
+ protected JComponent createTaskDescripion() {
+ this.taskDescription = new TaskDescriptionComponent(getTargetFile(), getSql());
+ return taskDescription;
+ }
+
+
+ /**
+ * @return the targetFile
+ */
+ public String getTargetFile() {
+ return targetFile;
+ }
+
+
+ /**
+ * @param targetFile the targetFile to set
+ */
+ public void setTargetFile(String targetFile) {
+ if(StringUtils.isBlank(targetFile)){
+ throw new IllegalArgumentException("targetFile must not be blank.");
+ }
+ this.targetFile = targetFile;
+ }
+
+
+ /**
+ * @return the sql
+ */
+ public String getSql() {
+ return sql;
+ }
+
+
+ /**
+ * @param sql the sql to set
+ */
+ public void setSql(String sql) {
+ if(StringUtils.isEmpty(sql)){
+ throw new IllegalArgumentException("sql must not be blank");
+ }
+ this.sql = sql;
+ }
+
+ /**
+ * Just for playing...
+ */
+ public static void main(String[] args) throws Exception {
+ IAbortEventHandler handler = new IAbortEventHandler() {
+
+ @Override
+ public void cancel() {
+ System.out.println("echo");
+ }
+ };
+
+ SQL2FileProgressAbortDialog dialog = new SQL2FileProgressAbortDialog((Frame)null, "myTitle", "file", "myDescription", handler);
+ Thread.sleep(3000);
+ dialog.currentlyLoading("Running query");
+ Thread.sleep(3000);
+ dialog.setTaskStatus("1 Row(s) exported");
+ Thread.sleep(3000);
+ dialog.setTaskStatus("100 Row(s) exported");
+ Thread.sleep(3000);
+ dialog.setTaskStatus("1000 Row(s) exported");
+ dialog.currentlyLoading("Finished");
+
+ }
+
+}
Property changes on: trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/SQL2FileProgressAbortDialog.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/gui/TaskDescriptionComponent.java
===================================================================
--- trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/gui/TaskDescriptionComponent.java (rev 0)
+++ trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/gui/TaskDescriptionComponent.java 2011-08-09 20:14:20 UTC (rev 6352)
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2011 Stefan Willinger
+ * wi...@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
+ */
+package net.sourceforge.squirrel_sql.plugins.sqlscript.table_script.gui;
+
+import javax.swing.BorderFactory;
+import javax.swing.JComponent;
+import javax.swing.JScrollPane;
+import javax.swing.BoxLayout;
+import javax.swing.JPanel;
+
+import java.awt.Dimension;
+import java.awt.GridBagLayout;
+import javax.swing.JLabel;
+import java.awt.GridBagConstraints;
+import javax.swing.JTextField;
+import java.awt.Insets;
+import javax.swing.JTextArea;
+import java.awt.BorderLayout;
+import javax.swing.SwingConstants;
+
+import net.sourceforge.squirrel_sql.fw.util.StringManager;
+import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
+
+import java.awt.FlowLayout;
+
+/**
+ * @author Stefan Willinger
+ *
+ */
+public class TaskDescriptionComponent extends JComponent {
+ private static final StringManager s_stringMgr = StringManagerFactory
+ .getStringManager(TaskDescriptionComponent.class);
+
+ interface i18n{
+ String TITEL_INFORMATION = s_stringMgr.getString("TaskDescriptionComponent.titelInformation");
+ String LABEL_FILE = s_stringMgr.getString("TaskDescriptionComponent.labelFile");
+ String LABEL_SQL = s_stringMgr.getString("TaskDescriptionComponent.labelSql");
+
+ }
+
+
+
+ private JTextField tfTargetFile;
+ private JTextArea taSql;
+
+ public TaskDescriptionComponent(String targetFile, String sql) {
+ this();
+ setTargetFile(targetFile);
+ setSql(sql);
+ }
+
+ /**
+ * @param sql
+ * SQL to show.
+ *
+ */
+ public void setSql(String sql) {
+ taSql.setText(sql);
+ taSql.setCaretPosition(0);
+ }
+
+ /**
+ * @param targetFile
+ * File to show
+ *
+ */
+ public void setTargetFile(String targetFile) {
+ tfTargetFile.setText(targetFile);
+ }
+
+ public TaskDescriptionComponent() {
+ init();
+ }
+
+ private void init() {
+ setBorder(BorderFactory.createTitledBorder(i18n.TITEL_INFORMATION));
+ setLayout(new BorderLayout());
+
+ JPanel viewPanel = new JPanel();
+ viewPanel.setMinimumSize(new Dimension(400, 200));
+ viewPanel.setPreferredSize(new Dimension(400, 200));
+ GridBagLayout gbl_viewPanel = new GridBagLayout();
+ viewPanel.setLayout(gbl_viewPanel);
+
+ add(viewPanel,BorderLayout.CENTER);
+
+ JLabel jlTargetFile = new JLabel();
+ jlTargetFile.setHorizontalAlignment(SwingConstants.RIGHT);
+ jlTargetFile.setText(i18n.LABEL_FILE);
+ GridBagConstraints gbc_jlTargetFile = new GridBagConstraints();
+ gbc_jlTargetFile.insets = new Insets(0, 0, 5, 5);
+ gbc_jlTargetFile.anchor = GridBagConstraints.EAST;
+ gbc_jlTargetFile.gridx = 0;
+ gbc_jlTargetFile.gridy = 0;
+ viewPanel.add(jlTargetFile, gbc_jlTargetFile);
+
+ tfTargetFile = new JTextField();
+ tfTargetFile.setEditable(false);
+ GridBagConstraints gbc_tfTargetFile = new GridBagConstraints();
+ gbc_tfTargetFile.weightx = 1.0;
+ gbc_tfTargetFile.insets = new Insets(0, 0, 5, 0);
+ gbc_tfTargetFile.fill = GridBagConstraints.HORIZONTAL;
+ gbc_tfTargetFile.gridx = 1;
+ gbc_tfTargetFile.gridy = 0;
+ viewPanel.add(tfTargetFile, gbc_tfTargetFile);
+ tfTargetFile.setColumns(10);
+
+ JLabel lblSql = new JLabel();
+ lblSql.setText(i18n.LABEL_SQL);
+ GridBagConstraints gbc_lblSql = new GridBagConstraints();
+ gbc_lblSql.anchor = GridBagConstraints.NORTHEAST;
+ gbc_lblSql.insets = new Insets(0, 0, 5, 5);
+ gbc_lblSql.gridx = 0;
+ gbc_lblSql.gridy = 1;
+ viewPanel.add(lblSql, gbc_lblSql);
+
+ taSql = new JTextArea();
+ taSql.setEditable(false);
+// taSql.setPreferredSize(new Dimension(400, 150));
+
+ JScrollPane spSql = new JScrollPane(taSql);
+ GridBagConstraints gbc_spSql = new GridBagConstraints();
+ gbc_spSql.weighty = 1.0;
+ gbc_spSql.weightx = 1.0;
+ gbc_spSql.insets = new Insets(0, 0, 5, 0);
+ gbc_spSql.fill = GridBagConstraints.BOTH;
+ gbc_spSql.gridx = 1;
+ gbc_spSql.gridy = 1;
+ viewPanel.add(spSql, gbc_spSql);
+
+ }
+}
Property changes on: trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/gui/TaskDescriptionComponent.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/sql12/plugins/sqlscript/src/main/resources/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/I18NStrings.properties
===================================================================
--- trunk/sql12/plugins/sqlscript/src/main/resources/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/I18NStrings.properties 2011-08-09 18:44:59 UTC (rev 6351)
+++ trunk/sql12/plugins/sqlscript/src/main/resources/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/I18NStrings.properties 2011-08-09 20:14:20 UTC (rev 6352)
@@ -29,8 +29,9 @@
AbstractDataScriptCommand.notASelect=The selected SQL is not a SELECT statement.
CreateFileOfCurrentSQLCommand.noQuery=No query found to create the script from.
-CreateFileOfCurrentSQLCommand.progress.title=Exporting into a file.
-CreateFileOfCurrentSQLCommand.progress.description=Exporting the SQL {0} into a file.
+CreateFileOfCurrentSQLCommand.progress.title=Exporting into {0}.
+CreateFileOfCurrentSQLCommand.progress.sucessMessage=Export of {0} rows into {1} was done in {2} seconds.
+
AbortController.abortText=Creating script
AbortController.abort=Abort
\ No newline at end of file
Added: trunk/sql12/plugins/sqlscript/src/main/resources/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/gui/I18NStrings.properties
===================================================================
--- trunk/sql12/plugins/sqlscript/src/main/resources/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/gui/I18NStrings.properties (rev 0)
+++ trunk/sql12/plugins/sqlscript/src/main/resources/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/gui/I18NStrings.properties 2011-08-09 20:14:20 UTC (rev 6352)
@@ -0,0 +1,3 @@
+TaskDescriptionComponent.titelInformation=Information
+TaskDescriptionComponent.labelFile=File
+TaskDescriptionComponent.labelSql=SQL
\ No newline at end of file
Property changes on: trunk/sql12/plugins/sqlscript/src/main/resources/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/gui/I18NStrings.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|