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