JAL-3829 - callback finessing - leave DBRefFetcher to do progress updates itself
authorJim Procter <j.procter@dundee.ac.uk>
Tue, 21 Sep 2021 12:54:23 +0000 (13:54 +0100)
committerJim Procter <j.procter@dundee.ac.uk>
Tue, 21 Sep 2021 12:54:33 +0000 (13:54 +0100)
src/jalview/gui/StructureChooser.java

index ae7971c..849c278 100644 (file)
@@ -58,6 +58,7 @@ import jalview.structure.StructureMapping;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.MessageManager;
 import jalview.ws.DBRefFetcher;
+import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
 import jalview.ws.seqfetcher.DbSourceProxy;
 import jalview.ws.sifts.SiftsSettings;
 
@@ -249,8 +250,22 @@ public class StructureChooser extends GStructureChooser
       }
     };
 
+    final FetchFinishedListenerI afterDbRefFetch = new FetchFinishedListenerI()
+    {
+      
+      @Override
+      public void finished()
+      {
+        // filter has been selected, so we set flag to remove ourselves
+        notQueriedTDBYet = false;
+        // new thread to discover structures - via 3d beacons
+        Executors.defaultThreadFactory().newThread(strucDiscovery).start();
+        
+      }
+    };
+    
     // fetch db refs if OK pressed
-    final Runnable discoverCanonicalDBrefs = new Runnable()
+    final Runnable discoverCanonicalDBrefs = new Runnable() 
     {
       @Override
       public void run()
@@ -260,42 +275,20 @@ public class StructureChooser extends GStructureChooser
         final int y = seqsWithoutSourceDBRef.size();
         if (y > 0)
         {
-          SwingUtilities.invokeLater(new Runnable() {
-            @Override
-            public void run()
-            {
-              updateProgressIndicator(MessageManager.formatMessage(
-                      "status.fetching_dbrefs_for_sequences_without_valid_refs",
-                      y), progressId);
-              
-            }
-          });
-          
           final SequenceI[] seqWithoutSrcDBRef = seqsWithoutSourceDBRef
                   .toArray(new SequenceI[y]);
           DBRefFetcher dbRefFetcher = new DBRefFetcher(seqWithoutSrcDBRef,
                   progressBar, new DbSourceProxy[]
                   { new jalview.ws.dbsources.Uniprot() }, null, false);
-
+          dbRefFetcher.addListener(afterDbRefFetch);
           // ideally this would also gracefully run with callbacks
           dbRefFetcher.fetchDBRefs(true);
+        } else {
+          // call finished action directly
+          afterDbRefFetch.finished();
         }
-        SwingUtilities.invokeLater(new Runnable() {
-          @Override
-          public void run()
-          {
-            if (y>0) {
-              updateProgressIndicator("Fetch complete.", progressId); // todo i18n
-            }
-            // filter has been selected, so we set flag to remove ourselves
-            notQueriedTDBYet = false;
-
-            Executors.defaultThreadFactory().newThread(strucDiscovery).start();
-
-          }
-        });
-        
       }
+
     };
     final Runnable revertview = new Runnable() {
       public void run() {