Revision: 5878
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=5878&view=rev
Author: manningr
Date: 2010-09-08 02:48:45 +0000 (Wed, 08 Sep 2010)
Log Message:
-----------
1) Fixed bug# 2998121 (Update doesn't work, settings seem correct). Now, if the local release.xml file
is not found the error dialog states as the cause, rather than merely saying the release.xml file
couldn't be downloaded.
2) Adjusted the way that UpdateController uses JOPtionPane by introducing a service layer that allows for an
implementation that delegates to JOPtionPane (moving the work to EDT if necessary) and allowing the
implementation to swapped out for a mock object during testing.
Modified Paths:
--------------
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/UpdateControllerImpl.java
trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/update/I18NStrings.properties
Added Paths:
-----------
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/IJOptionPaneService.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/JOptionPaneService.java
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/UpdateControllerImpl.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/UpdateControllerImpl.java 2010-09-07 23:19:16 UTC (rev 5877)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/UpdateControllerImpl.java 2010-09-08 02:48:45 UTC (rev 5878)
@@ -48,6 +48,8 @@
import net.sourceforge.squirrel_sql.client.update.gui.UpdateSummaryDialog;
import net.sourceforge.squirrel_sql.client.update.xmlbeans.ChannelXmlBean;
import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
+import net.sourceforge.squirrel_sql.fw.gui.IJOptionPaneService;
+import net.sourceforge.squirrel_sql.fw.gui.JOptionPaneService;
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;
@@ -92,6 +94,8 @@
private ArtifactDownloaderFactory _downloaderFactory = null;
+ private IJOptionPaneService jOptionPaneService = new JOptionPaneService();
+
static interface i18n
{
@@ -128,7 +132,7 @@
// i18n[UpdateControllerImpl.promptToDownloadAvailableUpdatesTitle=Updates Available]
String PROMPT_TO_DOWNLOAD_AVAILABLE_UPDATES_TITLE =
s_stringMgr.getString("UpdateControllerImpl.promptToDownloadAvailableUpdatesTitle");
-
+
}
/**
@@ -172,23 +176,31 @@
*/
public void showUpdateDialog()
{
- JFrame parent = _app.getMainFrame();
- IUpdateSettings settings = getUpdateSettings();
- boolean isRemoteUpdateSite = settings.isRemoteUpdateSite();
- UpdateManagerDialog dialog = new UpdateManagerDialog(parent, isRemoteUpdateSite);
- if (isRemoteUpdateSite)
+ final JFrame parent = _app.getMainFrame();
+ final IUpdateSettings settings = getUpdateSettings();
+ final boolean isRemoteUpdateSite = settings.isRemoteUpdateSite();
+ GUIUtils.processOnSwingEventThread(new Runnable()
{
- dialog.setUpdateServerName(settings.getUpdateServer());
- dialog.setUpdateServerPort(settings.getUpdateServerPort());
- dialog.setUpdateServerPath(settings.getUpdateServerPath());
- dialog.setUpdateServerChannel(settings.getUpdateServerChannel());
- }
- else
- {
- dialog.setLocalUpdatePath(settings.getFileSystemUpdatePath());
- }
- dialog.addCheckUpdateListener(this);
- dialog.setVisible(true);
+
+ @Override
+ public void run()
+ {
+ UpdateManagerDialog dialog = new UpdateManagerDialog(parent, isRemoteUpdateSite);
+ if (isRemoteUpdateSite)
+ {
+ dialog.setUpdateServerName(settings.getUpdateServer());
+ dialog.setUpdateServerPort(settings.getUpdateServerPort());
+ dialog.setUpdateServerPath(settings.getUpdateServerPath());
+ dialog.setUpdateServerChannel(settings.getUpdateServerChannel());
+ }
+ else
+ {
+ dialog.setLocalUpdatePath(settings.getFileSystemUpdatePath());
+ }
+ dialog.addCheckUpdateListener(UpdateControllerImpl.this);
+ dialog.setVisible(true);
+ }
+ });
}
/**
@@ -372,7 +384,7 @@
public boolean showConfirmMessage(String title, String msg)
{
int result =
- JOptionPane.showConfirmDialog(_app.getMainFrame(), msg, title, JOptionPane.YES_NO_OPTION,
+ jOptionPaneService.showConfirmDialog(_app.getMainFrame(), msg, title, JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
return (result == JOptionPane.YES_OPTION);
}
@@ -383,7 +395,7 @@
*/
public void showMessage(String title, String msg)
{
- JOptionPane.showMessageDialog(_app.getMainFrame(), msg, title, JOptionPane.INFORMATION_MESSAGE);
+ jOptionPaneService.showMessageDialog(_app.getMainFrame(), msg, title, JOptionPane.INFORMATION_MESSAGE);
}
@@ -391,10 +403,10 @@
* @see net.sourceforge.squirrel_sql.client.update.UpdateController#showErrorMessage(java.lang.String,
* java.lang.String)
*/
- public void showErrorMessage(String title, String msg, Exception e)
+ public void showErrorMessage(final String title, final String msg, final Exception e)
{
s_log.error(msg, e);
- JOptionPane.showMessageDialog(_app.getMainFrame(), msg, title, JOptionPane.ERROR_MESSAGE);
+ jOptionPaneService.showMessageDialog(_app.getMainFrame(), msg, title, JOptionPane.ERROR_MESSAGE);
}
/**
@@ -477,10 +489,16 @@
public void updateCheckFailed(final Exception e)
{
- if (e == null || e instanceof FileNotFoundException)
+ if (e == null)
{
showErrorMessage(i18n.UPDATE_CHECK_FAILED_TITLE, i18n.RELEASE_FILE_DOWNLOAD_FAILED_MSG);
}
+ else if (e instanceof FileNotFoundException)
+ {
+ String msg = s_stringMgr.getString("UpdateControllerImpl.localReleaseFileNotFound",
+ _util.getSquirrelHomeDir()+"/"+UpdateUtil.LOCAL_UPDATE_DIR_NAME+"/"+RELEASE_XML_FILENAME);
+ showErrorMessage(i18n.UPDATE_CHECK_FAILED_TITLE, msg);
+ }
else
{
showErrorMessage(i18n.UPDATE_CHECK_FAILED_TITLE, i18n.EXCEPTION_MSG + e.getClass().getName()
@@ -576,6 +594,17 @@
_app.getSquirrelPreferences().setUpdateSettings(settings);
}
+ /**
+ * Setter to allow injection of the service implementation.
+ *
+ * @param jOptionPaneService
+ * the non-static service that handles JOptionPane's static calls.
+ */
+ public void setJOptionPaneService(IJOptionPaneService jOptionPaneService)
+ {
+ this.jOptionPaneService = jOptionPaneService;
+ }
+
private class GlobalPrefsListener implements GlobalPreferencesActionListener
{
Modified: trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/update/I18NStrings.properties
===================================================================
--- trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/update/I18NStrings.properties 2010-09-07 23:19:16 UTC (rev 5877)
+++ trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/update/I18NStrings.properties 2010-09-08 02:48:45 UTC (rev 5878)
@@ -18,5 +18,5 @@
UpdateControllerImpl.updateCheckFailedTitle=Update Check Failed
UpdateControllerImpl.updateCheckTitle=Update Check
+UpdateControllerImpl.localReleaseFileNotFound=Local file ({0}) is missing. Update aborted.
-
Added: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/IJOptionPaneService.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/IJOptionPaneService.java (rev 0)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/IJOptionPaneService.java 2010-09-08 02:48:45 UTC (rev 5878)
@@ -0,0 +1,25 @@
+package net.sourceforge.squirrel_sql.fw.gui;
+
+import java.awt.Component;
+import java.awt.HeadlessException;
+
+/**
+ * Interface to allow implementations to be injected depending on runtime environment (e.g. production or
+ * test).
+ */
+public interface IJOptionPaneService
+{
+
+ /**
+ * @see javax.swing.JOptionPane#showMessageDialog(Component, Object, String, int)
+ */
+ public abstract void showMessageDialog(final Component parentComponent, final Object message,
+ final String title, final int messageType);
+
+ /**
+ * @see javax.swing.JOptionPane#showConfirmDialog(Component, Object, String, int, int)
+ */
+ public int showConfirmDialog(final Component parentComponent, final Object message, final String title,
+ final int optionType, final int messageType) throws HeadlessException;
+
+}
\ No newline at end of file
Added: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/JOptionPaneService.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/JOptionPaneService.java (rev 0)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/JOptionPaneService.java 2010-09-08 02:48:45 UTC (rev 5878)
@@ -0,0 +1,67 @@
+package net.sourceforge.squirrel_sql.fw.gui;
+
+import java.awt.Component;
+import java.awt.HeadlessException;
+
+import javax.swing.JOptionPane;
+
+/**
+ * A Service implementation for JOptionPane static methods that allow guarantees they will be invoked on the
+ * event dispatch thread. The interface also allows classes that depend on this implementation in production
+ * to use a mock in unit tests.
+ */
+public class JOptionPaneService implements IJOptionPaneService
+{
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.gui.IJOptionPaneService#showMessageDialog(java.awt.Component,
+ * java.lang.Object, java.lang.String, int)
+ */
+ @Override
+ public void showMessageDialog(final Component parentComponent, final Object message, final String title,
+ final int messageType)
+ {
+ GUIUtils.processOnSwingEventThread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ JOptionPane.showMessageDialog(parentComponent, message, title, messageType);
+ }
+ });
+ }
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.gui.IJOptionPaneService#showConfirmDialog(java.awt.Component,
+ * java.lang.Object, java.lang.String, int, int)
+ */
+ public int showConfirmDialog(final Component parentComponent, final Object message, final String title,
+ final int optionType, final int messageType) throws HeadlessException
+ {
+ final RunnableWithIntResult inputRunner = new RunnableWithIntResult()
+ {
+ private int result = -1;
+
+ @Override
+ public void run()
+ {
+ result = JOptionPane.showConfirmDialog(parentComponent, message, title, optionType, messageType);
+
+ }
+
+ @Override
+ public int getResult()
+ {
+ return result;
+ }
+ };
+
+ GUIUtils.processOnSwingEventThread(inputRunner, true);
+ return inputRunner.getResult();
+ }
+
+ private interface RunnableWithIntResult extends Runnable
+ {
+ public int getResult();
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|