X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSequenceFetcher.java;h=bf0ab7008481e59a59720b9605dd4fdd3f07b50e;hb=b59839dfda0a767318fc3c89d9604c39ff298d83;hp=d5a04a907deede86176d0059aafdb384196c79f2;hpb=97de0fe6133095ff42dccdbf3a5c3c02d5a91e4d;p=jalview.git diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index d5a04a9..bf0ab70 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -28,9 +28,11 @@ import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.fts.service.pdb.PDBFTSPanel; import jalview.fts.service.uniprot.UniprotFTSPanel; +import jalview.io.FileFormatI; import jalview.io.gff.SequenceOntologyI; import jalview.util.DBRefUtils; import jalview.util.MessageManager; +import jalview.util.Platform; import jalview.ws.dbsources.das.api.DasSourceRegistryI; import jalview.ws.seqfetcher.DbSourceProxy; @@ -42,6 +44,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; @@ -49,7 +52,6 @@ import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JInternalFrame; import javax.swing.JLabel; -import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; @@ -114,8 +116,6 @@ public class SequenceFetcher extends JPanel implements Runnable private static Thread initingThread = null; - int debounceTrap = 0; - public JTextArea getTextArea() { return textArea; @@ -167,9 +167,8 @@ public class SequenceFetcher extends JPanel implements Runnable if (sfetch == null || dasRegistry != Cache.getDasSourceRegistry() || lastDasSourceRegistry != (Cache.getDasSourceRegistry() - .getDasRegistryURL() + Cache - .getDasSourceRegistry().getLocalSourceString()) - .hashCode()) + .getDasRegistryURL() + Cache.getDasSourceRegistry() + .getLocalSourceString()).hashCode()) { _initingFetcher = true; initingThread = Thread.currentThread(); @@ -201,8 +200,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 @@ -214,7 +224,8 @@ public class SequenceFetcher extends JPanel implements Runnable { if (getSequenceFetcherSingleton(progressIndicator) != null) { - us.initGui(progressIndicator); + us.initGui(progressIndicator, selectedDb, queryString); + us._isConstructing = false; } else { @@ -223,14 +234,14 @@ public class SequenceFetcher extends JPanel implements Runnable @Override public void run() { - JOptionPane + JvOptionPane .showInternalMessageDialog( Desktop.desktop, MessageManager .getString("warn.couldnt_create_sequence_fetcher_client"), MessageManager .getString("label.couldnt_create_sequence_fetcher"), - JOptionPane.ERROR_MESSAGE); + JvOptionPane.ERROR_MESSAGE); } }); @@ -241,6 +252,32 @@ 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 { @@ -252,11 +289,57 @@ 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) @@ -267,6 +350,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(); @@ -274,13 +367,13 @@ public class SequenceFetcher extends JPanel implements Runnable frame = new JInternalFrame(); frame.setContentPane(this); - if (new jalview.util.Platform().isAMac()) + if (Platform.isAMac()) { - Desktop.addInternalFrame(frame, getFrameTitle(), 400, 240); + Desktop.addInternalFrame(frame, getFrameTitle(), false, 400, 240); } else { - Desktop.addInternalFrame(frame, getFrameTitle(), 400, 180); + Desktop.addInternalFrame(frame, getFrameTitle(), false, 400, 180); } } @@ -363,25 +456,39 @@ public class SequenceFetcher extends JPanel implements Runnable jPanel1.add(example); jPanel1.add(clear); jPanel1.add(close); - jPanel3.add(jPanel2, java.awt.BorderLayout.CENTER); jPanel2.setLayout(borderLayout3); - databaseButt = database.getDatabaseSelectorButton(); + databaseButt = /*database.getDatabaseSelectorButton(); + final JButton viewdbs =*/new JButton( + MessageManager.getString("action.select_ddbb")); + databaseButt.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent arg0) + { + hidePanel(); + database.showDialog(); + } + }); databaseButt.setFont(JvSwingUtils.getLabelFont()); database.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - debounceTrap++; String currentSelection = database.getSelectedItem(); + if (currentSelection == null) + { + close_actionPerformed(null); + } - if (currentSelection.equalsIgnoreCase("pdb") - && (database.action == KeyEvent.VK_ENTER || ((debounceTrap % 2) == 0))) + showPanel(); + + if ("pdb".equalsIgnoreCase(currentSelection)) { pdbSourceAction(); } - else if (currentSelection.equalsIgnoreCase("uniprot") - && (database.action == KeyEvent.VK_ENTER || ((debounceTrap % 2) == 0))) + else if ("uniprot".equalsIgnoreCase(currentSelection)) { uniprotSourceAction(); } @@ -406,7 +513,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); - } private void pdbSourceAction() @@ -422,6 +528,7 @@ public class SequenceFetcher extends JPanel implements Runnable new UniprotFTSPanel(this); frame.dispose(); } + private void otherSourceAction() { try @@ -811,12 +918,10 @@ public class SequenceFetcher extends JPanel implements Runnable } catch (Exception e) { Cache.log.info( - "Error retrieving " + accession - + " from " + proxy.getDbName(), e); - } finally - { - return success; + "Error retrieving " + accession + " from " + + proxy.getDbName(), e); } + return success; } /** @@ -836,7 +941,6 @@ public class SequenceFetcher extends JPanel implements Runnable for (String q : queries) { - DBRefEntry[] found = null; DBRefEntry dbr = new DBRefEntry(); dbr.setSource(proxy.getDbSource()); dbr.setVersion(null); @@ -847,8 +951,9 @@ public class SequenceFetcher extends JPanel implements Runnable { if (rs[r] != null) { - found = DBRefUtils.searchRefs(rs[r].getDBRefs(), accId); - if (found != null && found.length > 0) + List found = DBRefUtils.searchRefs(rs[r].getDBRefs(), + accId); + if (!found.isEmpty()) { rfound = true; break; @@ -873,7 +978,7 @@ public class SequenceFetcher extends JPanel implements Runnable } AlignmentI parseResult(AlignmentI al, String title, - String currentFileFormat, + FileFormatI currentFileFormat, FeatureSettingsModelI preferredFeatureColours) { @@ -919,9 +1024,12 @@ public class SequenceFetcher extends JPanel implements Runnable } if (Cache.getDefault("HIDE_INTRONS", true)) { - hideIntronsIfPresent(af); + af.hideFeatureColumns(SequenceOntologyI.EXON, false); + } + if (newAlframes != null) + { + newAlframes.add(af); } - Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); @@ -930,8 +1038,7 @@ public class SequenceFetcher extends JPanel implements Runnable try { - af.setMaximum(Cache.getDefault("SHOW_FULLSCREEN", - false)); + af.setMaximum(Cache.getDefault("SHOW_FULLSCREEN", false)); } catch (Exception ex) { } @@ -944,25 +1051,6 @@ public class SequenceFetcher extends JPanel implements Runnable return al; } - /** - * Hide columns not containing 'exon' features, provided there are exon - * features on the alignment - * - * @param af - */ - public void hideIntronsIfPresent(AlignFrame af) - { - boolean hasExons = af.avc.markColumnsContainingFeatures(false, false, - false, - SequenceOntologyI.EXON); - if (hasExons) - { - af.avc.markColumnsContainingFeatures(true, false, true, - SequenceOntologyI.EXON); - af.getViewport().hideSelectedColumns(); - } - } - void showErrorMessage(final String error) { resetDialog(); @@ -971,9 +1059,9 @@ public class SequenceFetcher extends JPanel implements Runnable @Override public void run() { - JOptionPane.showInternalMessageDialog(Desktop.desktop, error, + JvOptionPane.showInternalMessageDialog(Desktop.desktop, error, MessageManager.getString("label.error_retrieving_data"), - JOptionPane.WARNING_MESSAGE); + JvOptionPane.WARNING_MESSAGE); } }); } @@ -987,4 +1075,22 @@ public class SequenceFetcher extends JPanel implements Runnable { this.progressIndicator = progressIndicator; } + + /** + * Make this panel visible (after a selection has been made in the database + * chooser) + */ + void showPanel() + { + frame.setVisible(true); + } + + /** + * Hide this panel (on clicking the database button to open the database + * chooser) + */ + void hidePanel() + { + frame.setVisible(false); + } }