From 180082dbd4d7126bc8368dcd4cab2459e99f6f5f Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 28 Mar 2016 09:47:54 +0100 Subject: [PATCH] JAL-2036 update AlignFrame menus when dbreffetcher is complete --- src/jalview/gui/AlignFrame.java | 72 +++++++++++++++++++++++++++++--------- src/jalview/ws/DBRefFetcher.java | 29 +++++++++++---- 2 files changed, 78 insertions(+), 23 deletions(-) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 9e52fa3..fc145ed 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -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(); } diff --git a/src/jalview/ws/DBRefFetcher.java b/src/jalview/ws/DBRefFetcher.java index dff1b98..40c88c1 100644 --- a/src/jalview/ws/DBRefFetcher.java +++ b/src/jalview/ws/DBRefFetcher.java @@ -55,6 +55,13 @@ import uk.ac.ebi.picr.model.UPEntry; */ public class DBRefFetcher implements Runnable { + public interface FetchFinishedListenerI + { + void finished(); + } + + private List 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(); 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; - } /** -- 1.7.10.2