JAL-2036 update AlignFrame menus when dbreffetcher is complete
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 28 Mar 2016 08:47:54 +0000 (09:47 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 28 Mar 2016 08:47:54 +0000 (09:47 +0100)
src/jalview/gui/AlignFrame.java
src/jalview/ws/DBRefFetcher.java

index 9e52fa3..fc145ed 100644 (file)
@@ -96,6 +96,8 @@ import jalview.schemes.ZappoColourScheme;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.MessageManager;
 import jalview.viewmodel.AlignmentViewport;
+import jalview.ws.DBRefFetcher;
+import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
 import jalview.ws.SequenceFetcher;
 import jalview.ws.jws1.Discoverer;
 import jalview.ws.jws2.Jws2Discoverer;
@@ -5581,15 +5583,23 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       {
         new Thread(new Runnable()
         {
-
           @Override
           public void run()
           {
-            boolean isNuclueotide = alignPanel.alignFrame.getViewport()
+            boolean isNucleotide = alignPanel.alignFrame.getViewport()
                     .getAlignment().isNucleotide();
-            new jalview.ws.DBRefFetcher(alignPanel.av
+            DBRefFetcher dbRefFetcher = new DBRefFetcher(alignPanel.av
                     .getSequenceSelection(), alignPanel.alignFrame, null,
-                    alignPanel.alignFrame.featureSettings, isNuclueotide)
+                    alignPanel.alignFrame.featureSettings, isNucleotide);
+            dbRefFetcher.addListener(new FetchFinishedListenerI()
+            {
+              @Override
+              public void finished()
+              {
+                AlignFrame.this.setMenusForViewport();
+              }
+            });
+            dbRefFetcher
                     .fetchDBRefs(false);
           }
         }).start();
@@ -5658,14 +5668,24 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                       @Override
                       public void run()
                       {
-                        boolean isNuclueotide = alignPanel.alignFrame
+                        boolean isNucleotide = alignPanel.alignFrame
                                 .getViewport().getAlignment()
                                 .isNucleotide();
-                        new jalview.ws.DBRefFetcher(alignPanel.av
-                                .getSequenceSelection(),
+                        DBRefFetcher dbRefFetcher = new DBRefFetcher(
+                                alignPanel.av.getSequenceSelection(),
                                 alignPanel.alignFrame, dassource,
                                 alignPanel.alignFrame.featureSettings,
-                                isNuclueotide).fetchDBRefs(false);
+                                isNucleotide);
+                        dbRefFetcher
+                                .addListener(new FetchFinishedListenerI()
+                                {
+                                  @Override
+                                  public void finished()
+                                  {
+                                    AlignFrame.this.setMenusForViewport();
+                                  }
+                                });
+                        dbRefFetcher.fetchDBRefs(false);
                       }
                     }).start();
                   }
@@ -5698,14 +5718,24 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                       @Override
                       public void run()
                       {
-                        boolean isNuclueotide = alignPanel.alignFrame
+                        boolean isNucleotide = alignPanel.alignFrame
                                 .getViewport().getAlignment()
                                 .isNucleotide();
-                        new jalview.ws.DBRefFetcher(alignPanel.av
-                                .getSequenceSelection(),
+                        DBRefFetcher dbRefFetcher = new DBRefFetcher(
+                                alignPanel.av.getSequenceSelection(),
                                 alignPanel.alignFrame, dassource,
                                 alignPanel.alignFrame.featureSettings,
-                                isNuclueotide).fetchDBRefs(false);
+                                isNucleotide);
+                        dbRefFetcher
+                                .addListener(new FetchFinishedListenerI()
+                                {
+                                  @Override
+                                  public void finished()
+                                  {
+                                    AlignFrame.this.setMenusForViewport();
+                                  }
+                                });
+                        dbRefFetcher.fetchDBRefs(false);
                       }
                     }).start();
                   }
@@ -5753,14 +5783,24 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                         @Override
                         public void run()
                         {
-                          boolean isNuclueotide = alignPanel.alignFrame
+                          boolean isNucleotide = alignPanel.alignFrame
                                   .getViewport().getAlignment()
                                   .isNucleotide();
-                          new jalview.ws.DBRefFetcher(alignPanel.av
-                                  .getSequenceSelection(),
+                          DBRefFetcher dbRefFetcher = new DBRefFetcher(
+                                  alignPanel.av.getSequenceSelection(),
                                   alignPanel.alignFrame, dassrc,
                                   alignPanel.alignFrame.featureSettings,
-                                  isNuclueotide).fetchDBRefs(false);
+                                  isNucleotide);
+                          dbRefFetcher
+                                  .addListener(new FetchFinishedListenerI()
+                                  {
+                                    @Override
+                                    public void finished()
+                                    {
+                                      AlignFrame.this.setMenusForViewport();
+                                    }
+                                  });
+                          dbRefFetcher.fetchDBRefs(false);
                         }
                       }).start();
                     }
index dff1b98..40c88c1 100644 (file)
@@ -55,6 +55,13 @@ import uk.ac.ebi.picr.model.UPEntry;
  */
 public class DBRefFetcher implements Runnable
 {
+  public interface FetchFinishedListenerI
+  {
+    void finished();
+  }
+
+  private List<FetchFinishedListenerI> listeners;
+
   SequenceI[] dataset;
 
   IProgressIndicator progressWindow;
@@ -86,10 +93,6 @@ public class DBRefFetcher implements Runnable
    */
   private boolean trimDsSeqs = true;
 
-  public DBRefFetcher()
-  {
-  }
-
   /**
    * Creates a new DBRefFetcher object and fetches from the currently selected
    * set of databases, if this is null then it fetches based on feature settings
@@ -109,6 +112,7 @@ public class DBRefFetcher implements Runnable
           IProgressIndicator progressIndicatorFrame,
           DbSourceProxy[] sources, FeatureSettings featureSettings, boolean isNucleotide)
   {
+    listeners = new ArrayList<FetchFinishedListenerI>();
     this.progressWindow = progressIndicatorFrame;
     alseqs = new SequenceI[seqs.length];
     SequenceI[] ds = new SequenceI[seqs.length];
@@ -186,6 +190,16 @@ public class DBRefFetcher implements Runnable
   }
 
   /**
+   * Add a listener to be notified when sequence fetching is complete
+   * 
+   * @param l
+   */
+  public void addListener(FetchFinishedListenerI l)
+  {
+    listeners.add(l);
+  }
+
+  /**
    * retrieve all the das sequence sources and add them to the list of db
    * sources to retrieve from
    */
@@ -473,12 +487,13 @@ public class DBRefFetcher implements Runnable
       progressWindow.setProgressBar(
               MessageManager.getString("label.dbref_search_completed"),
               startTime);
-      // promptBeforeBlast();
-
     }
 
+    for (FetchFinishedListenerI listener : listeners)
+    {
+      listener.finished();
+    }
     running = false;
-
   }
 
   /**