2004761973490dfe901dda8107db595988b2552f
[jalview.git] / src / jalview / gui / SequenceFetcher.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.gui;
22
23 import jalview.datamodel.AlignmentI;
24 import jalview.datamodel.DBRefEntry;
25 import jalview.datamodel.SequenceFeature;
26 import jalview.datamodel.SequenceI;
27 import jalview.io.FormatAdapter;
28 import jalview.io.IdentifyFile;
29 import jalview.util.DBRefUtils;
30 import jalview.util.MessageManager;
31 import jalview.ws.dbsources.das.api.DasSourceRegistryI;
32 import jalview.ws.seqfetcher.DbSourceProxy;
33
34 import java.awt.BorderLayout;
35 import java.awt.Font;
36 import java.awt.event.ActionEvent;
37 import java.awt.event.ActionListener;
38 import java.awt.event.KeyAdapter;
39 import java.awt.event.KeyEvent;
40 import java.util.ArrayList;
41 import java.util.Arrays;
42 import java.util.Iterator;
43 import java.util.List;
44
45 import javax.swing.JButton;
46 import javax.swing.JCheckBox;
47 import javax.swing.JInternalFrame;
48 import javax.swing.JLabel;
49 import javax.swing.JOptionPane;
50 import javax.swing.JPanel;
51 import javax.swing.JScrollPane;
52 import javax.swing.JTextArea;
53 import javax.swing.SwingConstants;
54 import javax.swing.tree.DefaultMutableTreeNode;
55
56 public class SequenceFetcher extends JPanel implements Runnable
57 {
58   JLabel dbeg = new JLabel();
59
60   JDatabaseTree database;
61
62   JButton databaseButt;
63
64   JLabel jLabel1 = new JLabel();
65
66   JCheckBox replacePunctuation = new JCheckBox();
67
68   JButton ok = new JButton();
69
70   JButton clear = new JButton();
71
72   JButton example = new JButton();
73
74   JButton close = new JButton();
75
76   JPanel jPanel1 = new JPanel();
77
78   JTextArea textArea = new JTextArea();
79
80   JScrollPane jScrollPane1 = new JScrollPane();
81
82   JPanel jPanel2 = new JPanel();
83
84   JPanel jPanel3 = new JPanel();
85
86   JPanel jPanel4 = new JPanel();
87
88   BorderLayout borderLayout1 = new BorderLayout();
89
90   BorderLayout borderLayout2 = new BorderLayout();
91
92   BorderLayout borderLayout3 = new BorderLayout();
93
94   JInternalFrame frame;
95
96   IProgressIndicator guiWindow;
97
98   AlignFrame alignFrame;
99
100   StringBuffer result;
101
102   final String noDbSelected = "-- Select Database --";
103
104   private static jalview.ws.SequenceFetcher sfetch = null;
105
106   private static long lastDasSourceRegistry = -3;
107
108   private static DasSourceRegistryI dasRegistry = null;
109
110   private static boolean _initingFetcher = false;
111
112   private static Thread initingThread = null;
113
114   int debounceTrap = 0;
115
116   /**
117    * Blocking method that initialises and returns the shared instance of the
118    * SequenceFetcher client
119    * 
120    * @param guiWindow
121    *          - where the initialisation delay message should be shown
122    * @return the singleton instance of the sequence fetcher client
123    */
124   public static jalview.ws.SequenceFetcher getSequenceFetcherSingleton(
125           final IProgressIndicator guiWindow)
126   {
127     if (_initingFetcher && initingThread != null && initingThread.isAlive())
128     {
129       if (guiWindow != null)
130       {
131         guiWindow
132                 .setProgressBar(
133                         MessageManager
134                                 .getString("status.waiting_sequence_database_fetchers_init"),
135                         Thread.currentThread().hashCode());
136       }
137       // initting happening on another thread - so wait around to see if it
138       // finishes.
139       while (_initingFetcher && initingThread != null
140               && initingThread.isAlive())
141       {
142         try
143         {
144           Thread.sleep(10);
145         } catch (Exception e)
146         {
147         }
148         ;
149       }
150       if (guiWindow != null)
151       {
152         guiWindow
153                 .setProgressBar(
154                         MessageManager
155                                 .getString("status.waiting_sequence_database_fetchers_init"),
156                         Thread.currentThread().hashCode());
157       }
158     }
159     if (sfetch == null
160             || dasRegistry != jalview.bin.Cache.getDasSourceRegistry()
161             || lastDasSourceRegistry != (jalview.bin.Cache
162                     .getDasSourceRegistry().getDasRegistryURL() + jalview.bin.Cache
163                     .getDasSourceRegistry().getLocalSourceString())
164                     .hashCode())
165     {
166       _initingFetcher = true;
167       initingThread = Thread.currentThread();
168       /**
169        * give a visual indication that sequence fetcher construction is occuring
170        */
171       if (guiWindow != null)
172       {
173         guiWindow.setProgressBar(MessageManager
174                 .getString("status.init_sequence_database_fetchers"),
175                 Thread.currentThread().hashCode());
176       }
177       dasRegistry = jalview.bin.Cache.getDasSourceRegistry();
178       dasRegistry.refreshSources();
179
180       jalview.ws.SequenceFetcher sf = new jalview.ws.SequenceFetcher();
181       if (guiWindow != null)
182       {
183         guiWindow.setProgressBar(null, Thread.currentThread().hashCode());
184       }
185       lastDasSourceRegistry = (dasRegistry.getDasRegistryURL() + dasRegistry
186               .getLocalSourceString()).hashCode();
187       sfetch = sf;
188       _initingFetcher = false;
189       initingThread = null;
190     }
191     return sfetch;
192   }
193
194   private IProgressIndicator progressIndicator;
195
196   public SequenceFetcher(IProgressIndicator guiIndic)
197   {
198     this.progressIndicator = guiIndic;
199     final SequenceFetcher us = this;
200     // launch initialiser thread
201     Thread sf = new Thread(new Runnable()
202     {
203
204       @Override
205       public void run()
206       {
207         if (getSequenceFetcherSingleton(progressIndicator) != null)
208         {
209           us.initGui(progressIndicator);
210         }
211         else
212         {
213           javax.swing.SwingUtilities.invokeLater(new Runnable()
214           {
215             @Override
216             public void run()
217             {
218               JOptionPane
219                       .showInternalMessageDialog(
220                               Desktop.desktop,
221                               MessageManager
222                                       .getString("warn.couldnt_create_sequence_fetcher_client"),
223                               MessageManager
224                                       .getString("label.couldnt_create_sequence_fetcher"),
225                               JOptionPane.ERROR_MESSAGE);
226             }
227           });
228
229           // raise warning dialog
230         }
231       }
232     });
233     sf.start();
234   }
235
236   private class DatabaseAuthority extends DefaultMutableTreeNode
237   {
238
239   };
240
241   private class DatabaseSource extends DefaultMutableTreeNode
242   {
243
244   };
245
246   /**
247    * called by thread spawned by constructor
248    * 
249    * @param guiWindow
250    */
251   private void initGui(IProgressIndicator guiWindow)
252   {
253     this.guiWindow = guiWindow;
254     if (guiWindow instanceof AlignFrame)
255     {
256       alignFrame = (AlignFrame) guiWindow;
257     }
258     database = new JDatabaseTree(sfetch);
259     try
260     {
261       jbInit();
262     } catch (Exception ex)
263     {
264       ex.printStackTrace();
265     }
266
267     frame = new JInternalFrame();
268     frame.setContentPane(this);
269     if (new jalview.util.Platform().isAMac())
270     {
271       Desktop.addInternalFrame(frame, getFrameTitle(), 400, 240);
272     }
273     else
274     {
275       Desktop.addInternalFrame(frame, getFrameTitle(), 400, 180);
276     }
277   }
278
279   private String getFrameTitle()
280   {
281     return ((alignFrame == null) ? MessageManager
282             .getString("label.new_sequence_fetcher") : MessageManager
283             .getString("label.additional_sequence_fetcher"));
284   }
285
286   private void jbInit() throws Exception
287   {
288     this.setLayout(borderLayout2);
289
290     database.setFont(JvSwingUtils.getLabelFont());
291     dbeg.setFont(new java.awt.Font("Verdana", Font.BOLD, 11));
292     jLabel1.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
293     jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
294     jLabel1.setText(MessageManager
295             .getString("label.separate_multiple_accession_ids"));
296
297     replacePunctuation.setHorizontalAlignment(SwingConstants.CENTER);
298     replacePunctuation
299             .setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
300     replacePunctuation.setText(MessageManager
301             .getString("label.replace_commas_semicolons"));
302     ok.setText(MessageManager.getString("action.ok"));
303     ok.addActionListener(new ActionListener()
304     {
305       @Override
306       public void actionPerformed(ActionEvent e)
307       {
308         ok_actionPerformed();
309       }
310     });
311     clear.setText(MessageManager.getString("action.clear"));
312     clear.addActionListener(new ActionListener()
313     {
314       @Override
315       public void actionPerformed(ActionEvent e)
316       {
317         clear_actionPerformed();
318       }
319     });
320
321     example.setText(MessageManager.getString("label.example"));
322     example.addActionListener(new ActionListener()
323     {
324       @Override
325       public void actionPerformed(ActionEvent e)
326       {
327         example_actionPerformed();
328       }
329     });
330     close.setText(MessageManager.getString("action.close"));
331     close.addActionListener(new ActionListener()
332     {
333       @Override
334       public void actionPerformed(ActionEvent e)
335       {
336         close_actionPerformed(e);
337       }
338     });
339     textArea.setFont(JvSwingUtils.getLabelFont());
340     textArea.setLineWrap(true);
341     textArea.addKeyListener(new KeyAdapter()
342     {
343       @Override
344       public void keyPressed(KeyEvent e)
345       {
346         if (e.getKeyCode() == KeyEvent.VK_ENTER)
347         {
348           ok_actionPerformed();
349         }
350       }
351     });
352     jPanel3.setLayout(borderLayout1);
353     borderLayout1.setVgap(5);
354     jPanel1.add(ok);
355     jPanel1.add(example);
356     jPanel1.add(clear);
357     jPanel1.add(close);
358     jPanel3.add(jPanel2, java.awt.BorderLayout.CENTER);
359     jPanel2.setLayout(borderLayout3);
360     databaseButt = database.getDatabaseSelectorButton();
361     databaseButt.setFont(JvSwingUtils.getLabelFont());
362     database.addActionListener(new ActionListener()
363     {
364       @Override
365       public void actionPerformed(ActionEvent e)
366       {
367         debounceTrap++;
368         String currentSelection = database.getSelectedItem();
369         if (!currentSelection.equalsIgnoreCase("pdb"))
370         {
371           otherSourceAction();
372         }
373         if (currentSelection.equalsIgnoreCase("pdb")
374                 && (database.action == KeyEvent.VK_ENTER || ((debounceTrap % 2) == 0)))
375         {
376           pdbSourceAction();
377         }
378         database.action = -1;
379       }
380     });
381
382     dbeg.setText("");
383     jPanel2.add(databaseButt, java.awt.BorderLayout.NORTH);
384     jPanel2.add(dbeg, java.awt.BorderLayout.CENTER);
385     JPanel jPanel2a = new JPanel(new BorderLayout());
386     jPanel2a.add(jLabel1, java.awt.BorderLayout.NORTH);
387     jPanel2a.add(replacePunctuation, java.awt.BorderLayout.SOUTH);
388     jPanel2.add(jPanel2a, java.awt.BorderLayout.SOUTH);
389     // jPanel2.setPreferredSize(new Dimension())
390     jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER);
391     this.add(jPanel1, java.awt.BorderLayout.SOUTH);
392     this.add(jPanel3, java.awt.BorderLayout.CENTER);
393     this.add(jPanel2, java.awt.BorderLayout.NORTH);
394     jScrollPane1.getViewport().add(textArea);
395
396   }
397
398   private void pdbSourceAction()
399   {
400     databaseButt.setText(database.getSelectedItem());
401     new PDBSearchPanel(this);
402     frame.dispose();
403   }
404
405   private void otherSourceAction()
406   {
407     try
408     {
409       databaseButt.setText(database.getSelectedItem()
410               + (database.getSelectedSources().size() > 1 ? " (and "
411                       + database.getSelectedSources().size() + " others)"
412                       : ""));
413       String eq = database.getExampleQueries();
414       dbeg.setText(MessageManager.formatMessage(
415               "label.example_query_param", new String[] { eq }));
416       boolean enablePunct = !(eq != null && eq.indexOf(",") > -1);
417       for (DbSourceProxy dbs : database.getSelectedSources())
418       {
419         if (dbs instanceof jalview.ws.dbsources.das.datamodel.DasSequenceSource)
420         {
421           enablePunct = false;
422           break;
423         }
424       }
425       replacePunctuation.setEnabled(enablePunct);
426
427     } catch (Exception ex)
428     {
429       dbeg.setText("");
430       replacePunctuation.setEnabled(true);
431     }
432     jPanel2.repaint();
433   }
434
435   protected void example_actionPerformed()
436   {
437     DbSourceProxy db = null;
438     try
439     {
440       textArea.setText(database.getExampleQueries());
441     } catch (Exception ex)
442     {
443     }
444     jPanel3.repaint();
445   }
446
447   protected void clear_actionPerformed()
448   {
449     textArea.setText("");
450     jPanel3.repaint();
451   }
452
453   public void close_actionPerformed(ActionEvent e)
454   {
455     try
456     {
457       frame.setClosed(true);
458     } catch (Exception ex)
459     {
460     }
461   }
462
463   public void ok_actionPerformed()
464   {
465     databaseButt.setEnabled(false);
466     example.setEnabled(false);
467     textArea.setEnabled(false);
468     ok.setEnabled(false);
469     close.setEnabled(false);
470
471     Thread worker = new Thread(this);
472     worker.start();
473   }
474
475   private void resetDialog()
476   {
477     databaseButt.setEnabled(true);
478     example.setEnabled(true);
479     textArea.setEnabled(true);
480     ok.setEnabled(true);
481     close.setEnabled(true);
482   }
483
484   @Override
485   public void run()
486   {
487     String error = "";
488     if (!database.hasSelection())
489     {
490       error += "Please select the source database\n";
491     }
492     // TODO: make this transformation more configurable
493     com.stevesoft.pat.Regex empty;
494     if (replacePunctuation.isEnabled() && replacePunctuation.isSelected())
495     {
496       empty = new com.stevesoft.pat.Regex(
497       // replace commas and spaces with a semicolon
498               "(\\s|[,; ])+", ";");
499     }
500     else
501     {
502       // just turn spaces and semicolons into single semicolons
503       empty = new com.stevesoft.pat.Regex("(\\s|[; ])+", ";");
504     }
505     textArea.setText(empty.replaceAll(textArea.getText()));
506     // see if there's anthing to search with
507     if (!new com.stevesoft.pat.Regex("[A-Za-z0-9_.]").search(textArea
508             .getText()))
509     {
510       error += "Please enter a (semi-colon separated list of) database id(s)";
511     }
512     if (error.length() > 0)
513     {
514       showErrorMessage(error);
515       resetDialog();
516       return;
517     }
518     // TODO: Refactor to GUI independent code and write tests.
519     // indicate if successive sources should be merged into one alignment.
520     boolean addToLast = false;
521     ArrayList<String> aresultq = new ArrayList<String>(), presultTitle = new ArrayList<String>();
522     ArrayList<AlignmentI> presult = new ArrayList<AlignmentI>(), aresult = new ArrayList<AlignmentI>();
523     Iterator<DbSourceProxy> proxies = database.getSelectedSources()
524             .iterator();
525     String[] qries;
526     List<String> nextfetch = Arrays.asList(qries = textArea.getText()
527             .split(";"));
528     Iterator<String> en = Arrays.asList(new String[0]).iterator();
529     int nqueries = qries.length;
530     while (proxies.hasNext() && (en.hasNext() || nextfetch.size() > 0))
531     {
532       if (!en.hasNext() && nextfetch.size() > 0)
533       {
534         en = nextfetch.iterator();
535         nqueries = nextfetch.size();
536         // save the remaining queries in the original array
537         qries = nextfetch.toArray(new String[nqueries]);
538         nextfetch = new ArrayList<String>();
539       }
540
541       DbSourceProxy proxy = proxies.next();
542       boolean isAliSource = false;
543       try
544       {
545         // update status
546         guiWindow
547                 .setProgressBar(MessageManager.formatMessage(
548                         "status.fetching_sequence_queries_from",
549                         new String[] {
550                             Integer.valueOf(nqueries).toString(),
551                             proxy.getDbName() }), Thread.currentThread()
552                         .hashCode());
553         isAliSource = proxy.isAlignmentSource();
554         if (proxy.getAccessionSeparator() == null)
555         {
556           while (en.hasNext())
557           {
558             String item = en.next();
559             try
560             {
561               if (aresult != null)
562               {
563                 try
564                 {
565                   // give the server a chance to breathe
566                   Thread.sleep(5);
567                 } catch (Exception e)
568                 {
569                   //
570                 }
571
572               }
573
574               AlignmentI indres = null;
575               try
576               {
577                 indres = proxy.getSequenceRecords(item);
578               } catch (OutOfMemoryError oome)
579               {
580                 new OOMWarning("fetching " + item + " from "
581                         + proxy.getDbName(), oome, this);
582               }
583               if (indres != null)
584               {
585                 aresultq.add(item);
586                 aresult.add(indres);
587               }
588               else
589               {
590                 nextfetch.add(item);
591               }
592             } catch (Exception e)
593             {
594               jalview.bin.Cache.log.info("Error retrieving " + item
595                       + " from " + proxy.getDbName(), e);
596               nextfetch.add(item);
597             }
598           }
599         }
600         else
601         {
602           StringBuffer multiacc = new StringBuffer();
603           ArrayList<String> tosend = new ArrayList<String>();
604           while (en.hasNext())
605           {
606             String nel = en.next();
607             tosend.add(nel);
608             multiacc.append(nel);
609             if (en.hasNext())
610             {
611               multiacc.append(proxy.getAccessionSeparator());
612             }
613           }
614           try
615           {
616             AlignmentI rslt;
617             SequenceI[] rs;
618             List<String> nores = new ArrayList<String>();
619             rslt = proxy.getSequenceRecords(multiacc.toString());
620             if (rslt == null || rslt.getHeight() == 0)
621             {
622               // no results - pass on all queries to next source
623               nextfetch.addAll(tosend);
624             }
625             else
626             {
627               aresultq.add(multiacc.toString());
628               aresult.add(rslt);
629
630               rs = rslt.getSequencesArray();
631               // search for each query in the dbrefs associated with each
632               // sequence
633               // returned.
634               // ones we do not find will be used to query next source (if any)
635               for (String q : tosend)
636               {
637                 DBRefEntry dbr = new DBRefEntry(), found[] = null;
638                 dbr.setSource(proxy.getDbSource());
639                 dbr.setVersion(null);
640                 String accId = proxy.getAccessionIdFromQuery(q);
641                 dbr.setAccessionId(accId);
642                 boolean rfound = false;
643                 for (int r = 0; r < rs.length; r++)
644                 {
645                   if (rs[r] != null
646                           && (found = DBRefUtils.searchRefs(
647                                   rs[r].getDBRefs(), dbr)) != null
648                           && found.length > 0)
649                   {
650                     rfound = true;
651                     rs[r] = null;
652                     continue;
653                   }
654                 }
655                 if (!rfound)
656                 {
657                   nextfetch.add(q);
658                 }
659               }
660             }
661           } catch (OutOfMemoryError oome)
662           {
663             new OOMWarning("fetching " + multiacc + " from "
664                     + database.getSelectedItem(), oome, this);
665           }
666         }
667
668       } catch (Exception e)
669       {
670         showErrorMessage("Error retrieving " + textArea.getText()
671                 + " from " + database.getSelectedItem());
672         // error
673         // +="Couldn't retrieve sequences from "+database.getSelectedItem();
674         System.err.println("Retrieval failed for source ='"
675                 + database.getSelectedItem() + "' and query\n'"
676                 + textArea.getText() + "'\n");
677         e.printStackTrace();
678       } catch (OutOfMemoryError e)
679       {
680         // resets dialog box - so we don't use OOMwarning here.
681         showErrorMessage("Out of Memory when retrieving "
682                 + textArea.getText()
683                 + " from "
684                 + database.getSelectedItem()
685                 + "\nPlease see the Jalview FAQ for instructions for increasing the memory available to Jalview.\n");
686         e.printStackTrace();
687       } catch (Error e)
688       {
689         showErrorMessage("Serious Error retrieving " + textArea.getText()
690                 + " from " + database.getSelectedItem());
691         e.printStackTrace();
692       }
693       // Stack results ready for opening in alignment windows
694       if (aresult != null && aresult.size() > 0)
695       {
696         AlignmentI ar = null;
697         if (isAliSource)
698         {
699           addToLast = false;
700           // new window for each result
701           while (aresult.size() > 0)
702           {
703             presult.add(aresult.remove(0));
704             presultTitle.add(aresultq.remove(0) + " "
705                     + getDefaultRetrievalTitle());
706           }
707         }
708         else
709         {
710           String titl = null;
711           if (addToLast && presult.size() > 0)
712           {
713             ar = presult.remove(presult.size() - 1);
714             titl = presultTitle.remove(presultTitle.size() - 1);
715           }
716           // concatenate all results in one window
717           while (aresult.size() > 0)
718           {
719             if (ar == null)
720             {
721               ar = aresult.remove(0);
722             }
723             else
724             {
725               ar.append(aresult.remove(0));
726             }
727             ;
728           }
729           addToLast = true;
730           presult.add(ar);
731           presultTitle.add(titl);
732         }
733       }
734       guiWindow.setProgressBar(MessageManager
735               .getString("status.finshed_querying"), Thread.currentThread()
736               .hashCode());
737     }
738     guiWindow.setProgressBar(
739             (presult.size() > 0) ? MessageManager
740                     .getString("status.parsing_results") : MessageManager
741                     .getString("status.processing"), Thread.currentThread()
742                     .hashCode());
743     // process results
744     while (presult.size() > 0)
745     {
746       parseResult(presult.remove(0), presultTitle.remove(0), null);
747     }
748     // only remove visual delay after we finished parsing.
749     guiWindow.setProgressBar(null, Thread.currentThread().hashCode());
750     if (nextfetch.size() > 0)
751     {
752       StringBuffer sb = new StringBuffer();
753       sb.append("Didn't retrieve the following "
754               + (nextfetch.size() == 1 ? "query" : nextfetch.size()
755                       + " queries") + ": \n");
756       int l = sb.length(), lr = 0;
757       for (String s : nextfetch)
758       {
759         if (l != sb.length())
760         {
761           sb.append("; ");
762         }
763         if (lr - sb.length() > 40)
764         {
765           sb.append("\n");
766         }
767         sb.append(s);
768       }
769       showErrorMessage(sb.toString());
770     }
771     resetDialog();
772   }
773
774   AlignmentI parseResult(String result, String title)
775   {
776     String format = new IdentifyFile().identify(result, "Paste");
777     AlignmentI sequences = null;
778     if (FormatAdapter.isValidFormat(format))
779     {
780       sequences = null;
781       try
782       {
783         sequences = new FormatAdapter().readFile(result.toString(),
784                 "Paste", format);
785       } catch (Exception ex)
786       {
787       }
788
789       if (sequences != null)
790       {
791         return parseResult(sequences, title, format);
792       }
793     }
794     else
795     {
796       showErrorMessage("Error retrieving " + textArea.getText() + " from "
797               + database.getSelectedItem());
798     }
799
800     return null;
801   }
802
803   /**
804    * 
805    * @return a standard title for any results retrieved using the currently
806    *         selected source and settings
807    */
808   public String getDefaultRetrievalTitle()
809   {
810     return "Retrieved from " + database.getSelectedItem();
811   }
812
813   AlignmentI parseResult(AlignmentI al, String title,
814           String currentFileFormat)
815   {
816
817     if (al != null && al.getHeight() > 0)
818     {
819       if (title == null)
820       {
821         title = getDefaultRetrievalTitle();
822       }
823       if (alignFrame == null)
824       {
825         AlignFrame af = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
826                 AlignFrame.DEFAULT_HEIGHT);
827         if (currentFileFormat != null)
828         {
829           af.currentFileFormat = currentFileFormat; // WHAT IS THE DEFAULT
830           // FORMAT FOR
831           // NON-FormatAdapter Sourced
832           // Alignments?
833         }
834
835         SequenceFeature[] sfs = null;
836         List<SequenceI> alsqs;
837         synchronized (alsqs = al.getSequences())
838         {
839           for (SequenceI sq : alsqs)
840           {
841             if ((sfs = sq.getSequenceFeatures()) != null)
842             {
843               if (sfs.length > 0)
844               {
845                 af.setShowSeqFeatures(true);
846                 break;
847               }
848             }
849
850           }
851         }
852         Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH,
853                 AlignFrame.DEFAULT_HEIGHT);
854
855         af.statusBar.setText(MessageManager
856                 .getString("label.successfully_pasted_alignment_file"));
857
858         try
859         {
860           af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN",
861                   false));
862         } catch (Exception ex)
863         {
864         }
865       }
866       else
867       {
868         alignFrame.viewport.addAlignment(al, title);
869       }
870     }
871     return al;
872   }
873
874   void showErrorMessage(final String error)
875   {
876     resetDialog();
877     javax.swing.SwingUtilities.invokeLater(new Runnable()
878     {
879       @Override
880       public void run()
881       {
882         JOptionPane.showInternalMessageDialog(Desktop.desktop, error,
883                 MessageManager.getString("label.error_retrieving_data"),
884                 JOptionPane.WARNING_MESSAGE);
885       }
886     });
887   }
888
889   public IProgressIndicator getProgressIndicator()
890   {
891     return progressIndicator;
892   }
893
894   public void setProgressIndicator(IProgressIndicator progressIndicator)
895   {
896     this.progressIndicator = progressIndicator;
897   }
898 }