+ /**
+ * 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;
+
+ private volatile boolean _isConstructing = false;
+
+ private List<AlignFrame> newAlframes = null;
+
+ public SequenceFetcher(IProgressIndicator guiIndic)
+ {
+ this(guiIndic, null, null);
+ }
+
+ public SequenceFetcher(IProgressIndicator guiIndic,
+ final String selectedDb, final String queryString)
+ {
+ this._isConstructing=true;
+ 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, selectedDb, queryString);
+ us._isConstructing=false;
+ }
+ 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();
+ }
+ /**
+ * blocking call which creates a new sequence fetcher panel, configures it and presses the OK button with the given database and query.
+ * @param database
+ * @param query
+ */
+ public static List<AlignFrame> fetchAndShow(String database, String query)
+ {
+ final SequenceFetcher sf = new SequenceFetcher(Desktop.instance, database, query);
+ while (sf._isConstructing)
+ {
+ try { Thread.sleep(50);
+ } catch (Exception q)
+ {
+ return Collections.emptyList();
+ }
+ }
+ sf.newAlframes = new ArrayList<AlignFrame>();
+ sf.run();
+ return sf.newAlframes;
+ }
+
+ private class DatabaseAuthority extends DefaultMutableTreeNode
+ {
+
+ };
+
+ private class DatabaseSource extends DefaultMutableTreeNode
+ {
+
+ };
+
+ /**
+ * initialise the database and query for this fetcher panel
+ *
+ * @param selectedDb
+ * - string that should correspond to a sequence fetcher
+ * @param queryString
+ * - string that will be entered in the query dialog
+ * @return true if UI was configured with valid database and query string
+ */
+ protected boolean setInitialQuery(String selectedDb, String queryString)
+ {
+ if (selectedDb == null || selectedDb.trim().length() == 0)
+ {
+ return false;
+ }