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