X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSequenceFetcher.java;h=5d4ea68a863e834bc0555547eb94f40354330b6d;hb=d2164f857e0729b86b1e0ffa4c858487f0a3298f;hp=afe6754f913391ce94597aef803d020763cd3980;hpb=ba7cba06e47fd8f46aafb04c5f2b33718db4f320;p=jalview.git diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index afe6754..5d4ea68 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -43,6 +43,7 @@ import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -200,8 +201,19 @@ public class SequenceFetcher extends JPanel implements Runnable private IProgressIndicator progressIndicator; + private volatile boolean _isConstructing = false; + + private List 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 @@ -213,7 +225,8 @@ public class SequenceFetcher extends JPanel implements Runnable { if (getSequenceFetcherSingleton(progressIndicator) != null) { - us.initGui(progressIndicator); + us.initGui(progressIndicator, selectedDb, queryString); + us._isConstructing=false; } else { @@ -239,6 +252,26 @@ public class SequenceFetcher extends JPanel implements Runnable }); 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 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(); + sf.run(); + return sf.newAlframes; + } private class DatabaseAuthority extends DefaultMutableTreeNode { @@ -249,13 +282,59 @@ public class SequenceFetcher extends JPanel implements Runnable { }; + + /** + * 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; + } + try + { + List sp = sfetch.getSourceProxy(selectedDb); + for (DbSourceProxy sourcep : sp) + { + if (sourcep.getTier() == 0) + { + database.selection = Arrays + .asList(new DbSourceProxy[] { sourcep }); + break; + } + } + if (database.selection == null || database.selection.size() == 0) + { + System.err.println("Ignoring fetch parameter db='" + selectedDb + + "'"); + return false; + } + textArea.setText(queryString); + } catch (Exception q) + { + System.err.println("Ignoring fetch parameter db='" + selectedDb + + "' and query='" + queryString + "'"); + return false; + } + return true; + } /** * called by thread spawned by constructor * * @param guiWindow + * @param queryString + * @param selectedDb */ - private void initGui(IProgressIndicator guiWindow) + private void initGui(IProgressIndicator guiWindow, String selectedDb, + String queryString) { this.guiWindow = guiWindow; if (guiWindow instanceof AlignFrame) @@ -266,6 +345,16 @@ public class SequenceFetcher extends JPanel implements Runnable try { jbInit(); + /* + * configure the UI with any query parameters we were called with + */ + if (!setInitialQuery(selectedDb, queryString)) + { + /* + * none provided, so show the database chooser + */ + database.waitForInput(); + } } catch (Exception ex) { ex.printStackTrace(); @@ -419,11 +508,6 @@ public class SequenceFetcher extends JPanel implements Runnable this.add(jPanel3, java.awt.BorderLayout.CENTER); this.add(jPanel2, java.awt.BorderLayout.NORTH); jScrollPane1.getViewport().add(textArea); - - /* - * open the database tree - */ - database.waitForInput(); } private void pdbSourceAction() @@ -936,7 +1020,10 @@ public class SequenceFetcher extends JPanel implements Runnable { af.hideFeatureColumns(SequenceOntologyI.EXON, false); } - + if (newAlframes != null) + { + newAlframes.add(af); + } Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);