From 5f100f37552bcadfee0bf79453b43f37e102c86b Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Tue, 21 Sep 2021 13:54:23 +0100 Subject: [PATCH] JAL-3829 - callback finessing - leave DBRefFetcher to do progress updates itself --- src/jalview/gui/StructureChooser.java | 49 ++++++++++++++------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index ae7971c..849c278 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -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() { -- 1.7.10.2