+
+ private static jalview.ws.SequenceFetcher sfetch = null;
+
+ private static long lastDasSourceRegistry = -3;
+
+ private static DasSourceRegistryI dasRegistry = null;
+
+ private static boolean _initingFetcher = false;
+
+ private static Thread initingThread = null;
+
+ int debounceTrap = 0;
+
+ public JTextArea getTextArea()
+ {
+ return textArea;
+ }
+
+ /**
+ * Blocking method that initialises and returns the shared instance of the
+ * SequenceFetcher client
+ *
+ * @param guiWindow
+ * - where the initialisation delay message should be shown
+ * @return the singleton instance of the sequence fetcher client
+ */
+ public static jalview.ws.SequenceFetcher getSequenceFetcherSingleton(
+ final IProgressIndicator guiWindow)
+ {
+ if (_initingFetcher && initingThread != null && initingThread.isAlive())
+ {
+ if (guiWindow != null)
+ {
+ guiWindow
+ .setProgressBar(
+ MessageManager
+ .getString("status.waiting_sequence_database_fetchers_init"),
+ Thread.currentThread().hashCode());
+ }
+ // initting happening on another thread - so wait around to see if it
+ // finishes.
+ while (_initingFetcher && initingThread != null
+ && initingThread.isAlive())
+ {
+ try
+ {
+ Thread.sleep(10);
+ } catch (Exception e)
+ {
+ }
+ ;
+ }
+ if (guiWindow != null)
+ {
+ guiWindow
+ .setProgressBar(
+ MessageManager
+ .getString("status.waiting_sequence_database_fetchers_init"),
+ Thread.currentThread().hashCode());
+ }
+ }
+ if (sfetch == null
+ || dasRegistry != Cache.getDasSourceRegistry()
+ || lastDasSourceRegistry != (Cache.getDasSourceRegistry()
+ .getDasRegistryURL() + Cache
+ .getDasSourceRegistry().getLocalSourceString())
+ .hashCode())
+ {
+ _initingFetcher = true;
+ initingThread = Thread.currentThread();
+ /**
+ * give a visual indication that sequence fetcher construction is occuring
+ */
+ if (guiWindow != null)
+ {
+ guiWindow.setProgressBar(MessageManager
+ .getString("status.init_sequence_database_fetchers"),
+ Thread.currentThread().hashCode());
+ }
+ dasRegistry = Cache.getDasSourceRegistry();
+ dasRegistry.refreshSources();
+
+ jalview.ws.SequenceFetcher sf = new jalview.ws.SequenceFetcher();
+ if (guiWindow != null)
+ {
+ guiWindow.setProgressBar(null, Thread.currentThread().hashCode());
+ }
+ lastDasSourceRegistry = (dasRegistry.getDasRegistryURL() + dasRegistry
+ .getLocalSourceString()).hashCode();
+ sfetch = sf;
+ _initingFetcher = false;
+ initingThread = null;
+ }
+ return sfetch;
+ }
+
+ private IProgressIndicator progressIndicator;
+
+ public SequenceFetcher(IProgressIndicator guiIndic)
+ {
+ this.progressIndicator = guiIndic;
+ final SequenceFetcher us = this;
+ // launch initialiser thread
+ Thread sf = new Thread(new Runnable()
+ {
+
+ @Override
+ public void run()
+ {
+ if (getSequenceFetcherSingleton(progressIndicator) != null)
+ {
+ us.initGui(progressIndicator);
+ }
+ else
+ {
+ javax.swing.SwingUtilities.invokeLater(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ JOptionPane
+ .showInternalMessageDialog(
+ Desktop.desktop,
+ MessageManager
+ .getString("warn.couldnt_create_sequence_fetcher_client"),
+ MessageManager
+ .getString("label.couldnt_create_sequence_fetcher"),
+ JOptionPane.ERROR_MESSAGE);
+ }
+ });
+
+ // raise warning dialog
+ }
+ }
+ });
+ sf.start();
+ }
+
+ private class DatabaseAuthority extends DefaultMutableTreeNode
+ {
+
+ };
+
+ private class DatabaseSource extends DefaultMutableTreeNode