added singleton access method to retrieve the latest shared instance of the jalview...
authorjprocter <Jim Procter>
Tue, 26 Aug 2008 10:07:03 +0000 (10:07 +0000)
committerjprocter <Jim Procter>
Tue, 26 Aug 2008 10:07:03 +0000 (10:07 +0000)
src/jalview/gui/SequenceFetcher.java

index 02bb786..f594554 100755 (executable)
@@ -58,7 +58,37 @@ public class SequenceFetcher extends JPanel implements Runnable
   private static jalview.ws.SequenceFetcher sfetch = null;
 
   private static String dasRegistry = null;
+  /**
+   * Blocking method that initialises and returns the shared instance of the SequenceFetcher client 
+   * @param guiWindow - where the initialisation delay message should be shown
+   * @return the singleton instance of the sequence fetcher client
+   */
+  public static jalview.ws.SequenceFetcher getSequenceFetcherSingleton(final IProgressIndicator guiWindow) {
+    if (sfetch == null
+            || dasRegistry != DasSourceBrowser.getDasRegistryURL())
+    {
+      /**
+       * give a visual indication that sequence fetcher construction is
+       * occuring
+       */
+      if (guiWindow != null)
+      {
+        guiWindow.setProgressBar(
+                "Initialising Sequence Database Fetchers", Thread.currentThread()
+                        .hashCode());
+      }
+      dasRegistry = DasSourceBrowser.getDasRegistryURL();
+      jalview.ws.SequenceFetcher sf = new jalview.ws.SequenceFetcher();
+      if (guiWindow != null)
+      {
+        guiWindow.setProgressBar(
+                "Initialising Sequence Database Fetchers", Thread.currentThread().hashCode());
+      }
+      sfetch = sf;
 
+    }
+    return sfetch;
+  }
   public SequenceFetcher(IProgressIndicator guiIndic)
   {
     final IProgressIndicator guiWindow = guiIndic;
@@ -69,31 +99,22 @@ public class SequenceFetcher extends JPanel implements Runnable
 
       public void run()
       {
-        if (sfetch == null
-                || dasRegistry != DasSourceBrowser.getDasRegistryURL())
+        if (getSequenceFetcherSingleton(guiWindow)!=null)
         {
-          /**
-           * give a visual indication that sequence fetcher construction is
-           * occuring
-           */
-          if (guiWindow != null)
+          us.initGui(guiWindow);
+        } else {
+          javax.swing.SwingUtilities.invokeLater(new Runnable()
           {
-            guiWindow.setProgressBar(
-                    "Initialising Sequence Database Fetchers", this
-                            .hashCode());
-          }
-          dasRegistry = DasSourceBrowser.getDasRegistryURL();
-          jalview.ws.SequenceFetcher sf = new jalview.ws.SequenceFetcher();
-          if (guiWindow != null)
-          {
-            guiWindow.setProgressBar(
-                    "Initialising Sequence Database Fetchers", this
-                            .hashCode());
-          }
-          sfetch = sf;
-
+            public void run()
+            {
+              JOptionPane.showInternalMessageDialog(Desktop.desktop, 
+                      "Could not create the sequence fetcher client. Check error logs for details.",
+                      "Couldn't create SequenceFetcher", JOptionPane.ERROR_MESSAGE);
+            }
+          });
+          
+          // raise warning dialog
         }
-        us.initGui(guiWindow);
       }
     });
     sf.start();