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