Revision: 6342
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6342&view=rev
Author: wis775
Date: 2011-08-06 20:30:55 +0000 (Sat, 06 Aug 2011)
Log Message:
-----------
Store result of SQL in file: Some cleanups, externalized messages, small improvement to the UI of the progress monitor.
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/exportData/AbstractDataExportFileWriter.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/ProgressAbortCallback.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/squirrelsql-plugins-parent-pom/pom.xml
Added Paths:
-----------
trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/exportData/
trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/exportData/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-05 17:54:59 UTC (rev 6341)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressAbortDialog.java 2011-08-06 20:30:55 UTC (rev 6342)
@@ -39,6 +39,8 @@
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
+import org.apache.commons.lang.StringUtils;
+
import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
import net.sourceforge.squirrel_sql.fw.sql.ProgressAbortCallback;
import net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack;
@@ -101,6 +103,11 @@
* The place to show the current task
*/
private JLabel statusLabel = null;
+
+ /**
+ * The place to show additional information about the current task
+ */
+ private JLabel additionalStatusLabel = null;
private String _loadingPrefix = i18n.DEFAULT_LOADING_PREFIX;
@@ -132,7 +139,13 @@
*/
private boolean canceled;
+
/**
+ * Someone told us, that all tasks are done.
+ */
+ private boolean finished;
+
+ /**
* Constructor which accepts a Dialog owner
*
* @param owner
@@ -216,6 +229,7 @@
public void run()
{
statusLabel.setText(statusText.toString());
+ setTaskStatus(null);
progressBar.setValue(progressBar.getValue() + 1);
if (finishedLoading())
@@ -231,7 +245,36 @@
s_log.error("Unexpected exception: " + e.getMessage(), e);
}
}
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.sql.ProgressAbortCallback#setTaskStatus(java.lang.String)
+ */
+ @Override
+ public void setTaskStatus(final String status)
+ {
+ final StringBuilder statusText = new StringBuilder();
+
+ if(StringUtils.isNotBlank(status)){
+ statusText.append(status);
+ }
+
+ try
+ {
+ GUIUtils.processOnSwingEventThread(new Runnable()
+ {
+ public void run()
+ {
+ additionalStatusLabel.setText(statusText.toString());
+ }
+ });
+ }
+ catch (Exception e)
+ {
+ s_log.error("Unexpected exception: " + e.getMessage(), e);
+ }
+ }
+
/**
* @param string
*/
@@ -256,6 +299,11 @@
@Override
public boolean finishedLoading()
{
+ if(finished){
+ progressBar.setIndeterminate(false);
+ return true;
+ }
+
if(this.indeterminate){
return false;
}
@@ -345,6 +393,11 @@
dialogPanel.add(statusLabel, c);
c.gridy++;
+ c.insets = new Insets(4, 10, 4, 10);
+ additionalStatusLabel = new JLabel();
+ dialogPanel.add(additionalStatusLabel, c);
+
+ c.gridy++;
c.weightx = 1.0;
progressBar = new JProgressBar(0, itemCount);
progressBar.setIndeterminate(indeterminate);
@@ -427,4 +480,12 @@
public boolean isVisble() {
return super.isVisible();
}
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.sql.ProgressAbortCallback#setFinished()
+ */
+ @Override
+ public void setFinished() {
+ this.finished = true;
+ }
}
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-05 17:54:59 UTC (rev 6341)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/AbstractExportCommand.java 2011-08-06 20:30:55 UTC (rev 6342)
@@ -49,7 +49,7 @@
* Independent, if the source of the data is a JTable, a result set or whatever. Its only important, that the data is tabulated. This is ensured by the
* interface {@link IExportData}. There are existing some DataExportWriters for various target formats.
*
- * <b>Note:</b> This class is the result of a refactoring task. The code was taken from TableExportCsvCommand.
+ * <b>Note:</b> This class is the result of a re-factoring task. The code was taken from TableExportCsvCommand.
* @see DataExportCSVWriter
* @see DataExportXMLWriter
* @see DataExportExcelWriter
@@ -60,8 +60,12 @@
public abstract class AbstractExportCommand {
static final StringManager s_stringMgr = StringManagerFactory
.getStringManager(AbstractExportCommand.class);
+
+
+
+
+
static ILogger s_log = LoggerController.createLogger(AbstractExportCommand.class);
- private boolean cancel;
private ProgressAbortCallback progressController = null;
/**
@@ -169,7 +173,7 @@
}
boolean writeFileSuccess = writeFile(ctrl, createExportData(ctrl));
- progress("Done");
+
if(writeFileSuccess)
{
String command = ctrl.getCommand();
@@ -210,11 +214,6 @@
*/
protected abstract IExportData createExportData(TableExportCsvController ctrl);
-
- public void cancel(){
- this.cancel=true;
- }
-
/**
* @return the progressController
*/
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-05 17:54:59 UTC (rev 6341)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/AbstractDataExportFileWriter.java 2011-08-06 20:30:55 UTC (rev 6342)
@@ -19,11 +19,13 @@
package net.sourceforge.squirrel_sql.fw.gui.action.exportData;
import java.io.File;
-import java.io.IOException;
+import java.text.NumberFormat;
import java.util.Iterator;
import net.sourceforge.squirrel_sql.fw.gui.action.TableExportCsvController;
import net.sourceforge.squirrel_sql.fw.sql.ProgressAbortCallback;
+import net.sourceforge.squirrel_sql.fw.util.StringManager;
+import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
/**
* Exports a data structure into a file.
@@ -38,10 +40,35 @@
*/
public abstract class AbstractDataExportFileWriter implements IDataExportWriter{
+ /** Internationalized strings for this class */
+ private static final StringManager s_stringMgr =
+ StringManagerFactory.getStringManager(AbstractDataExportFileWriter.class);
+
+ static interface i18n
+ {
+ // i18n[AbstractDataExportFileWriter.beginWriting=Begin writing]
+ String BEGIN_WRITING = s_stringMgr.getString("AbstractDataExportFileWriter.beginWriting");
+
+ // i18n[AbstractDataExportFileWriter.NUMBER_OF_ROWS_COMPLETED=100 rows completed]
+ String KEY_NUMBER_OF_ROWS_COMPLETED = "AbstractDataExportFileWriter.numberOfRowsCompleted";
+
+
+ // i18n[AbstractDataExportFileWriter.NUMBER_OF_ROWS_COMPLETED=Finished with 100 rows]
+ String KEY_FINISHED_LOADING = "AbstractDataExportFileWriter.finishedLoading";
+
+ // i18n[AbstractDataExportFileWriter.NUMBER_OF_ROWS_COMPLETED=Closing the file]
+ String CLOSING_THE_FILE = s_stringMgr.getString("AbstractDataExportFileWriter.closingTheFile");
+
+ // i18n[AbstractDataExportFileWriter.DONE=Done]
+ String DONE = s_stringMgr.getString("AbstractDataExportFileWriter.done");
+ }
+
+
+
/**
- * Constant, for updating the progress bar each x rows.
+ * Constant, for updating the progress bar each x seconds.
*/
- private static final int FEEDBACK_EVRY_N_LINE = 1000;
+ private static final int FEEDBACK_EVRY_N_SECONDS = 5;
/**
* The target file.
*/
@@ -59,8 +86,14 @@
* Progress controller with the opportunity to abort the operation.
*/
private ProgressAbortCallback progressController;
+
+ /**
+ * Timestamp of the last update of the progress status.
+ */
+ private long timeOfLastStatusUpdate = 0;
- /**
+ /**"Begin writing");
+ beforeRows();
* Construct this one.
* @param file The target file.
* @param ctrl The controller to use
@@ -96,13 +129,17 @@
Iterator<IExportDataRow> rows = data.getRows();
- progress("Begin writing");
+ progress(i18n.BEGIN_WRITING);
beforeRows();
long rowsCount = 1;
+ NumberFormat nfRowCount = NumberFormat.getInstance();
+
+
while (rows.hasNext() && isStop() == false) {
IExportDataRow aRow = rows.next();
- if((rowsCount) % FEEDBACK_EVRY_N_LINE == 0){
- progress(rowsCount + "Rows completed");
+ Thread.sleep(1000);
+ if(isStatusUpdateNecessary()){
+ taskStatus(s_stringMgr.getString(i18n.KEY_NUMBER_OF_ROWS_COMPLETED, nfRowCount.format(rowsCount)));
}
beforeRow(aRow.getRowIndex());
@@ -114,12 +151,18 @@
afterRow();
rowsCount++;
}
+ progress(s_stringMgr.getString(i18n.KEY_FINISHED_LOADING, nfRowCount.format(rowsCount)));
afterRows();
- progress("Finished with " + rowsCount + "Rows");
- progress("Closing the file");
+ progress(i18n.CLOSING_THE_FILE);
// All sheets and cells added. Now write out the workbook
afterWorking();
-
+
+ progress(i18n.DONE);
+
+ if(progressController != null){
+ progressController.setFinished();
+ }
+
if (isStop()) {
return false;
} else {
@@ -129,6 +172,19 @@
}
/**
+ * @return
+ */
+ private boolean isStatusUpdateNecessary() {
+ long time = System.currentTimeMillis();
+ if((timeOfLastStatusUpdate + FEEDBACK_EVRY_N_SECONDS*1000) < time){
+ timeOfLastStatusUpdate = time;
+ return true;
+ }else{
+ return false;
+ }
+ }
+
+ /**
* Callback before processing the first row.
*/
public void beforeRows() {
@@ -259,6 +315,17 @@
}
/**
+ * Tells the progress controller the status of the current task.
+ * @param status Status of a task to be added to the progress controller.
+ */
+ protected void taskStatus(String status){
+ if(progressController != null){
+ progressController.setTaskStatus(status);
+ }
+ }
+
+
+ /**
* Checks, if the work should be stopped.
* @return true, if the work should be stopped, otherwise false.
*/
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/ProgressAbortCallback.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/ProgressAbortCallback.java 2011-08-05 17:54:59 UTC (rev 6341)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/ProgressAbortCallback.java 2011-08-06 20:30:55 UTC (rev 6342)
@@ -20,13 +20,22 @@
/**
* A monitor for long running operations.
- * The scope of this monitor is to give feedback to the user and provide the oportunity to abort the operation.
+ * The scope of this monitor is to give feedback to the user and provide the opportunity to abort the operation.
* This interface is a conjunction of {@link ProgressCallBack} and {@link IAbortController}
* @author Stefan Willinger
* @see ProgressCallBack
* @see IAbortController
*/
public interface ProgressAbortCallback extends ProgressCallBack, IAbortController {
+ /**
+ * Display the status of the current running sub-task.
+ * @param status status to display.
+ */
+ void setTaskStatus(String status);
-
+ /**
+ * Tells the progress bar, that the operation is finished.
+ * Unnoticed, how many tasks are realy done.
+ */
+ void setFinished();
}
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-05 17:54:59 UTC (rev 6341)
+++ trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/I18NStrings.properties 2011-08-06 20:30:55 UTC (rev 6342)
@@ -49,4 +49,4 @@
TableExportCsvDlg.formatXLS=Export MS Excel (XLS) file
TableExportCsvDlg.formatXML=Export XML file
-TableExportCsvDlg.useGlobalPrefsFormatingExcel=Use formatting as configured in Global Prefs (recommended for MS Excel)
\ No newline at end of file
+TableExportCsvDlg.useGlobalPrefsFormatingExcel=Use formatting as configured in Global Prefs (recommended for MS Excel)
Added: trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/exportData/I18NStrings.properties
===================================================================
--- trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/exportData/I18NStrings.properties (rev 0)
+++ trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/exportData/I18NStrings.properties 2011-08-06 20:30:55 UTC (rev 6342)
@@ -0,0 +1,5 @@
+AbstractDataExportFileWriter.beginWriting=Begin writing.
+AbstractDataExportFileWriter.numberOfRowsCompleted={0} rows completed.
+AbstractDataExportFileWriter.finishedLoading=Finished with {0} rows.
+AbstractDataExportFileWriter.closingTheFile=Closing the file.
+AbstractDataExportFileWriter.done=Done.
Property changes on: trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/exportData/I18NStrings.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
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-05 17:54:59 UTC (rev 6341)
+++ trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/CreateFileOfCurrentSQLCommand.java 2011-08-06 20:30:55 UTC (rev 6342)
@@ -173,6 +173,9 @@
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();
@@ -180,10 +183,6 @@
// nothing todo
}
}
-
- if(resultSetExportCommand != null){
- resultSetExportCommand.cancel();
- }
}
});
Modified: trunk/sql12/plugins/squirrelsql-plugins-parent-pom/pom.xml
===================================================================
--- trunk/sql12/plugins/squirrelsql-plugins-parent-pom/pom.xml 2011-08-05 17:54:59 UTC (rev 6341)
+++ trunk/sql12/plugins/squirrelsql-plugins-parent-pom/pom.xml 2011-08-06 20:30:55 UTC (rev 6342)
@@ -53,10 +53,8 @@
<url>https://www.squirrel-sql.org/hudson/</url>
</ciManagement>
<dependencyManagement>
- <!--
- None of the dependencies below should use ${project.version} since this pom is inherited by the
- plugin archetype projects prototype pom.
- -->
+ <!-- None of the dependencies below should use ${project.version} since
+ this pom is inherited by the plugin archetype projects prototype pom. -->
<dependencies>
<dependency>
<groupId>net.sf.squirrel-sql</groupId>
@@ -145,11 +143,10 @@
<outputDirectory>target</outputDirectory>
<finalName>${project.artifactId}</finalName>
<includePom>true</includePom>
- <!--
- We exclude docs from the source jar, because the assembly has to have them for the plugin
- install to work; and we don't want the source jar to contain them as well as the assembly jar
- as that just makes the assembly jar bigger.
- -->
+ <!-- We exclude docs from the source jar, because the assembly has
+ to have them for the plugin install to work; and we don't want the source
+ jar to contain them as well as the assembly jar as that just makes the assembly
+ jar bigger. -->
<excludes>
<exclude>**/doc/**</exclude>
<exclude>**/doc</exclude>
@@ -174,10 +171,7 @@
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
<finalName>${project.artifactId}</finalName>
- <!--
- We exclude docs from the classes jar, for the same reason as
- above
- -->
+ <!-- We exclude docs from the classes jar, for the same reason as above -->
<excludes>
<exclude>**/doc/**</exclude>
<exclude>**/doc</exclude>
@@ -246,10 +240,8 @@
<descriptors>
<descriptor>${project.build.directory}/assemblies/squirrelsql-plugin-assembly.xml</descriptor>
</descriptors>
- <!--
- This must be true, or else it will cause this to become the main artifact for each plugin
- project
- -->
+ <!-- This must be true, or else it will cause this to become the
+ main artifact for each plugin project -->
<appendAssemblyId>true</appendAssemblyId>
<finalName>${project.artifactId}</finalName>
</configuration>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|