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