742a10940d73a7ac8b753eb6ae23f2d9798784d4
[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                   }
653                 }
654                 if (!rfound)
655                 {
656                   nextfetch.add(q);
657                 }
658               }
659             }
660           } catch (OutOfMemoryError oome)
661           {
662             new OOMWarning("fetching " + multiacc + " from "
663                     + database.getSelectedItem(), oome, this);
664           }
665         }
666
667       } catch (Exception e)
668       {
669         showErrorMessage("Error retrieving " + textArea.getText()
670                 + " from " + database.getSelectedItem());
671         // error
672         // +="Couldn't retrieve sequences from "+database.getSelectedItem();
673         System.err.println("Retrieval failed for source ='"
674                 + database.getSelectedItem() + "' and query\n'"
675                 + textArea.getText() + "'\n");
676         e.printStackTrace();
677       } catch (OutOfMemoryError e)
678       {
679         // resets dialog box - so we don't use OOMwarning here.
680         showErrorMessage("Out of Memory when retrieving "
681                 + textArea.getText()
682                 + " from "
683                 + database.getSelectedItem()
684                 + "\nPlease see the Jalview FAQ for instructions for increasing the memory available to Jalview.\n");
685         e.printStackTrace();
686       } catch (Error e)
687       {
688         showErrorMessage("Serious Error retrieving " + textArea.getText()
689                 + " from " + database.getSelectedItem());
690         e.printStackTrace();
691       }
692       // Stack results ready for opening in alignment windows
693       if (aresult != null && aresult.size() > 0)
694       {
695         AlignmentI ar = null;
696         if (isAliSource)
697         {
698           addToLast = false;
699           // new window for each result
700           while (aresult.size() > 0)
701           {
702             presult.add(aresult.remove(0));
703             presultTitle.add(aresultq.remove(0) + " "
704                     + getDefaultRetrievalTitle());
705           }
706         }
707         else
708         {
709           String titl = null;
710           if (addToLast && presult.size() > 0)
711           {
712             ar = presult.remove(presult.size() - 1);
713             titl = presultTitle.remove(presultTitle.size() - 1);
714           }
715           // concatenate all results in one window
716           while (aresult.size() > 0)
717           {
718             if (ar == null)
719             {
720               ar = aresult.remove(0);
721             }
722             else
723             {
724               ar.append(aresult.remove(0));
725             }
726             ;
727           }
728           addToLast = true;
729           presult.add(ar);
730           presultTitle.add(titl);
731         }
732       }
733       guiWindow.setProgressBar(MessageManager
734               .getString("status.finshed_querying"), Thread.currentThread()
735               .hashCode());
736     }
737     guiWindow.setProgressBar(
738             (presult.size() > 0) ? MessageManager
739                     .getString("status.parsing_results") : MessageManager
740                     .getString("status.processing"), Thread.currentThread()
741                     .hashCode());
742     // process results
743     while (presult.size() > 0)
744     {
745       parseResult(presult.remove(0), presultTitle.remove(0), null);
746     }
747     // only remove visual delay after we finished parsing.
748     guiWindow.setProgressBar(null, Thread.currentThread().hashCode());
749     if (nextfetch.size() > 0)
750     {
751       StringBuffer sb = new StringBuffer();
752       sb.append("Didn't retrieve the following "
753               + (nextfetch.size() == 1 ? "query" : nextfetch.size()
754                       + " queries") + ": \n");
755       int l = sb.length(), lr = 0;
756       for (String s : nextfetch)
757       {
758         if (l != sb.length())
759         {
760           sb.append("; ");
761         }
762         if (lr - sb.length() > 40)
763         {
764           sb.append("\n");
765         }
766         sb.append(s);
767       }
768       showErrorMessage(sb.toString());
769     }
770     resetDialog();
771   }
772
773   AlignmentI parseResult(String result, String title)
774   {
775     String format = new IdentifyFile().identify(result, "Paste");
776     AlignmentI sequences = null;
777     if (FormatAdapter.isValidFormat(format))
778     {
779       sequences = null;
780       try
781       {
782         sequences = new FormatAdapter().readFile(result.toString(),
783                 "Paste", format);
784       } catch (Exception ex)
785       {
786       }
787
788       if (sequences != null)
789       {
790         return parseResult(sequences, title, format);
791       }
792     }
793     else
794     {
795       showErrorMessage("Error retrieving " + textArea.getText() + " from "
796               + database.getSelectedItem());
797     }
798
799     return null;
800   }
801
802   /**
803    * 
804    * @return a standard title for any results retrieved using the currently
805    *         selected source and settings
806    */
807   public String getDefaultRetrievalTitle()
808   {
809     return "Retrieved from " + database.getSelectedItem();
810   }
811
812   AlignmentI parseResult(AlignmentI al, String title,
813           String currentFileFormat)
814   {
815
816     if (al != null && al.getHeight() > 0)
817     {
818       if (title == null)
819       {
820         title = getDefaultRetrievalTitle();
821       }
822       if (alignFrame == null)
823       {
824         AlignFrame af = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
825                 AlignFrame.DEFAULT_HEIGHT);
826         if (currentFileFormat != null)
827         {
828           af.currentFileFormat = currentFileFormat; // WHAT IS THE DEFAULT
829           // FORMAT FOR
830           // NON-FormatAdapter Sourced
831           // Alignments?
832         }
833
834         SequenceFeature[] sfs = null;
835         List<SequenceI> alsqs;
836         synchronized (alsqs = al.getSequences())
837         {
838           for (SequenceI sq : alsqs)
839           {
840             if ((sfs = sq.getSequenceFeatures()) != null)
841             {
842               if (sfs.length > 0)
843               {
844                 af.setShowSeqFeatures(true);
845                 break;
846               }
847             }
848
849           }
850         }
851         Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH,
852                 AlignFrame.DEFAULT_HEIGHT);
853
854         af.statusBar.setText(MessageManager
855                 .getString("label.successfully_pasted_alignment_file"));
856
857         try
858         {
859           af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN",
860                   false));
861         } catch (Exception ex)
862         {
863         }
864       }
865       else
866       {
867         alignFrame.viewport.addAlignment(al, title);
868       }
869     }
870     return al;
871   }
872
873   void showErrorMessage(final String error)
874   {
875     resetDialog();
876     javax.swing.SwingUtilities.invokeLater(new Runnable()
877     {
878       @Override
879       public void run()
880       {
881         JOptionPane.showInternalMessageDialog(Desktop.desktop, error,
882                 MessageManager.getString("label.error_retrieving_data"),
883                 JOptionPane.WARNING_MESSAGE);
884       }
885     });
886   }
887
888   public IProgressIndicator getProgressIndicator()
889   {
890     return progressIndicator;
891   }
892
893   public void setProgressIndicator(IProgressIndicator progressIndicator)
894   {
895     this.progressIndicator = progressIndicator;
896   }
897 }