thread off sequence fetcher initialisation to make initial alignment window display...
authorjprocter <Jim Procter>
Sun, 19 Sep 2010 16:34:07 +0000 (16:34 +0000)
committerjprocter <Jim Procter>
Sun, 19 Sep 2010 16:34:07 +0000 (16:34 +0000)
src/jalview/gui/AlignFrame.java

index ca4b880..be7908c 100755 (executable)
@@ -3833,129 +3833,141 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
     final AlignFrame me = this;
     buildingMenu = true;
-    new Thread(new Runnable() {
-      public void run() {
-    try
+    new Thread(new Runnable()
     {
-      System.err
-              .println("Building ws menu again " + Thread.currentThread());
-      // TODO: add support for context dependent disabling of services based on
-      // alignment and current selection
-      // TODO: add additional serviceHandle parameter to specify abstract
-      // handler
-      // class independently of AbstractName
-      // TODO: add in rediscovery GUI function to restart discoverer
-      // TODO: group services by location as well as function and/or introduce
-      // object broker mechanism.
-      final Vector wsmenu = new Vector();
-      final IProgressIndicator af = me;
-      if (Cache.getDefault("SHOW_JWS1_SERVICES", true)
-              && Discoverer.services != null
-              && (Discoverer.services.size() > 0))
+      public void run()
       {
-        // TODO: refactor to allow list of AbstractName/Handler bindings to be
-        // stored or retrieved from elsewhere
-        Vector msaws = (Vector) Discoverer.services.get("MsaWS");
-        Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
-        Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch");
-        // TODO: move GUI generation code onto service implementation - so a
-        // client instance attaches itself to the GUI with method call like
-        // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
-        // alignframe)
-        if (msaws != null)
+        try
         {
-          // Add any Multiple Sequence Alignment Services
-          final JMenu msawsmenu = new JMenu("Alignment");
-          for (int i = 0, j = msaws.size(); i < j; i++)
+          System.err.println("Building ws menu again "
+                  + Thread.currentThread());
+          // TODO: add support for context dependent disabling of services based
+          // on
+          // alignment and current selection
+          // TODO: add additional serviceHandle parameter to specify abstract
+          // handler
+          // class independently of AbstractName
+          // TODO: add in rediscovery GUI function to restart discoverer
+          // TODO: group services by location as well as function and/or
+          // introduce
+          // object broker mechanism.
+          final Vector wsmenu = new Vector();
+          final IProgressIndicator af = me;
+          if (Cache.getDefault("SHOW_JWS1_SERVICES", true)
+                  && Discoverer.services != null
+                  && (Discoverer.services.size() > 0))
           {
-            final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
-                    .get(i);
-            jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
-                    .getServiceClient(sh);
-            impl.attachWSMenuEntry(msawsmenu, me);
+            // TODO: refactor to allow list of AbstractName/Handler bindings to
+            // be
+            // stored or retrieved from elsewhere
+            Vector msaws = (Vector) Discoverer.services.get("MsaWS");
+            Vector secstrpr = (Vector) Discoverer.services
+                    .get("SecStrPred");
+            Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch");
+            // TODO: move GUI generation code onto service implementation - so a
+            // client instance attaches itself to the GUI with method call like
+            // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
+            // alignframe)
+            if (msaws != null)
+            {
+              // Add any Multiple Sequence Alignment Services
+              final JMenu msawsmenu = new JMenu("Alignment");
+              for (int i = 0, j = msaws.size(); i < j; i++)
+              {
+                final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
+                        .get(i);
+                jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
+                        .getServiceClient(sh);
+                impl.attachWSMenuEntry(msawsmenu, me);
 
+              }
+              wsmenu.add(msawsmenu);
+            }
+            if (secstrpr != null)
+            {
+              // Add any secondary structure prediction services
+              final JMenu secstrmenu = new JMenu(
+                      "Secondary Structure Prediction");
+              for (int i = 0, j = secstrpr.size(); i < j; i++)
+              {
+                final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
+                        .get(i);
+                jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
+                        .getServiceClient(sh);
+                impl.attachWSMenuEntry(secstrmenu, me);
+              }
+              wsmenu.add(secstrmenu);
+            }
+            if (seqsrch != null)
+            {
+              // Add any sequence search services
+              final JMenu seqsrchmenu = new JMenu(
+                      "Sequence Database Search");
+              for (int i = 0, j = seqsrch.size(); i < j; i++)
+              {
+                final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
+                        .elementAt(i);
+                jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
+                        .getServiceClient(sh);
+                impl.attachWSMenuEntry(seqsrchmenu, me);
+              }
+              wsmenu.add(seqsrchmenu);
+            }
           }
-          wsmenu.add(msawsmenu);
-        }
-        if (secstrpr != null)
-        {
-          // Add any secondary structure prediction services
-          final JMenu secstrmenu = new JMenu(
-                  "Secondary Structure Prediction");
-          for (int i = 0, j = secstrpr.size(); i < j; i++)
-          {
-            final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
-                    .get(i);
-            jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
-                    .getServiceClient(sh);
-            impl.attachWSMenuEntry(secstrmenu, me);
-          }
-          wsmenu.add(secstrmenu);
-        }
-        if (seqsrch != null)
-        {
-          // Add any sequence search services
-          final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
-          for (int i = 0, j = seqsrch.size(); i < j; i++)
+
+          // TODO: move into separate menu builder class.
+          if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
           {
-            final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
-                    .elementAt(i);
-            jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
-                    .getServiceClient(sh);
-            impl.attachWSMenuEntry(seqsrchmenu, me);
+            Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
+            if (jws2servs != null)
+            {
+              if (jws2servs.hasServices())
+              {
+                JMenu jws2men = new JMenu("Jalview 2 Services");
+                jws2servs.attachWSMenuEntry(jws2men, me);
+                for (int i = 0, iSize = jws2men.getMenuComponentCount(); i < iSize; i++)
+                {
+                  wsmenu.add(jws2men.getMenuComponent(i));
+                }
+              }
+            }
           }
-          wsmenu.add(seqsrchmenu);
-        }
-      }
 
-      // TODO: move into separate menu builder class.
-      if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
-      {
-        Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
-        if (jws2servs != null)
-        {
-          if (jws2servs.hasServices())
+          javax.swing.SwingUtilities.invokeLater(new Runnable()
           {
-            JMenu jws2men = new JMenu("Jalview 2 Services");
-            jws2servs.attachWSMenuEntry(jws2men, me);
-            for (int i = 0, iSize = jws2men.getMenuComponentCount(); i < iSize; i++)
+            public void run()
             {
-              wsmenu.add(jws2men.getMenuComponent(i));
+              try
+              {
+
+                resetWebServiceMenu();
+                // finally, add the whole shebang onto the webservices menu
+                if (wsmenu.size() > 0)
+                {
+                  for (int i = 0, j = wsmenu.size(); i < j; i++)
+                  {
+                    webService.add((JMenu) wsmenu.get(i));
+                  }
+                }
+                else
+                {
+                  me.webService.add(me.webServiceNoServices);
+                }
+              } catch (Exception e)
+              {
+              }
+              ;
             }
-          }
-        }
-      }
-      
-        javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() {
-          try {
-            
-      resetWebServiceMenu();
-      // finally, add the whole shebang onto the webservices menu
-      if (wsmenu.size() > 0)
-      {
-        for (int i = 0, j = wsmenu.size(); i < j; i++)
+          });
+        } catch (Exception e)
         {
-          webService.add((JMenu) wsmenu.get(i));
         }
+        ;
+
+        buildingMenu = false;
       }
-      else
-      {
-        me.webService.add(me.webServiceNoServices);
-      }
-          } catch (Exception e)
-          {
-          }
-          ;
-        }
-        });
-    } catch (Exception e)
-    {
-    }
-    ;
-        
-    buildingMenu = false;
-      }}).start();
-    
+    }).start();
+
   }
 
   /**
@@ -4534,7 +4546,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     // TODO We probably want to store a sequence database checklist in
     // preferences and have checkboxes.. rather than individual sources selected
     // here
-    JMenu rfetch = new JMenu("Fetch DB References");
+    final JMenu rfetch = new JMenu("Fetch DB References");
     rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
     webService.add(rfetch);
 
@@ -4560,57 +4572,74 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     });
     rfetch.add(fetchr);
-    JMenu dfetch = new JMenu();
-    rfetch.add(dfetch);
-    jalview.ws.SequenceFetcher sf = SequenceFetcher
-            .getSequenceFetcherSingleton(this);
-    String[] otherdb = sf.getOrderedSupportedSources();
-    // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
-    // jalview.util.QuickSort.sort(otherdb, otherdb);
-    int comp = 0, mcomp = 15;
-    String mname = null;
-    if (otherdb != null && otherdb.length > 0)
-    {
-      for (int i = 0; i < otherdb.length; i++)
+    final AlignFrame me=this;
+    new Thread(new Runnable()
+    {
+      public void run()
       {
-        String dbname = sf.getSourceProxy(otherdb[i]).getDbName();
-        if (mname == null)
+        final jalview.ws.SequenceFetcher sf = SequenceFetcher
+                .getSequenceFetcherSingleton(me);
+        final String[] otherdb = sf.getOrderedSupportedSources();
+        // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
+        // jalview.util.QuickSort.sort(otherdb, otherdb);
+        javax.swing.SwingUtilities.invokeLater(new Runnable()
         {
-          mname = "from '" + dbname + "'";
-        }
-        fetchr = new JMenuItem(otherdb[i]);
-        final String[] dassource = new String[]
-        { otherdb[i] };
-        fetchr.addActionListener(new ActionListener()
-        {
-
-          public void actionPerformed(ActionEvent e)
+          public void run()
           {
-            new Thread(new Runnable()
-            {
 
-              public void run()
+            JMenu dfetch = new JMenu();
+            JMenuItem fetchr;
+            rfetch.add(dfetch);
+            int comp = 0, mcomp = 15;
+            String mname = null;
+            if (otherdb != null && otherdb.length > 0)
+            {
+              for (int i = 0; i < otherdb.length; i++)
               {
-                new jalview.ws.DBRefFetcher(alignPanel.av
-                        .getSequenceSelection(), alignPanel.alignFrame,
-                        dassource).fetchDBRefs(false);
+                String dbname = sf.getSourceProxy(otherdb[i]).getDbName();
+                if (mname == null)
+                {
+                  mname = "from '" + dbname + "'";
+                }
+                fetchr = new JMenuItem(otherdb[i]);
+                final String[] dassource = new String[]
+                { otherdb[i] };
+                fetchr.addActionListener(new ActionListener()
+                {
+
+                  public void actionPerformed(ActionEvent e)
+                  {
+                    new Thread(new Runnable()
+                    {
+
+                      public void run()
+                      {
+                        new jalview.ws.DBRefFetcher(alignPanel.av
+                                .getSequenceSelection(),
+                                alignPanel.alignFrame, dassource)
+                                .fetchDBRefs(false);
+                      }
+                    }).start();
+                  }
+
+                });
+                fetchr.setToolTipText("Retrieve from " + dbname);
+                dfetch.add(fetchr);
+                if (comp++ == mcomp || i == (otherdb.length - 1))
+                {
+                  dfetch.setText(mname + " to '" + dbname + "'");
+                  rfetch.add(dfetch);
+                  dfetch = new JMenu();
+                  mname = null;
+                  comp = 0;
+                }
               }
-            }).start();
+            }
           }
-
         });
-        fetchr.setToolTipText("Retrieve from " + dbname);
-        dfetch.add(fetchr);
-        if (comp++ == mcomp || i == (otherdb.length - 1))
-        {
-          dfetch.setText(mname + " to '" + dbname + "'");
-          rfetch.add(dfetch);
-          dfetch = new JMenu();
-          mname = null;
-          comp = 0;
-        }
       }
-    }
+    }).start();
+
   }
 
   /**