JAL-1355
[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                 MessageManager.getString("status.waiting_sequence_database_fetchers_init"),
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                         MessageManager.getString("status.waiting_sequence_database_fetchers_init"),
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(MessageManager.getString("status.init_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(MessageManager.getString("status.init_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                               MessageManager.getString("warn.couldnt_create_sequence_fetcher_client"),
165                               MessageManager.getString("label.couldnt_create_sequence_fetcher"),
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
235             .getString("label.separate_multiple_accession_ids"));
236
237     replacePunctuation.setHorizontalAlignment(SwingConstants.CENTER);
238     replacePunctuation
239             .setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
240     replacePunctuation.setText(MessageManager
241             .getString("label.replace_commas_semicolons"));
242     ok.setText(MessageManager.getString("action.ok"));
243     ok.addActionListener(new ActionListener()
244     {
245       @Override
246       public void actionPerformed(ActionEvent e)
247       {
248         ok_actionPerformed();
249       }
250     });
251     clear.setText(MessageManager.getString("action.clear"));
252     clear.addActionListener(new ActionListener()
253     {
254       @Override
255       public void actionPerformed(ActionEvent e)
256       {
257         clear_actionPerformed();
258       }
259     });
260
261     example.setText(MessageManager.getString("label.example"));
262     example.addActionListener(new ActionListener()
263     {
264       @Override
265       public void actionPerformed(ActionEvent e)
266       {
267         example_actionPerformed();
268       }
269     });
270     close.setText(MessageManager.getString("action.close"));
271     close.addActionListener(new ActionListener()
272     {
273       @Override
274       public void actionPerformed(ActionEvent e)
275       {
276         close_actionPerformed(e);
277       }
278     });
279     textArea.setFont(JvSwingUtils.getLabelFont());
280     textArea.setLineWrap(true);
281     textArea.addKeyListener(new KeyAdapter()
282     {
283       @Override
284       public void keyPressed(KeyEvent e)
285       {
286         if (e.getKeyCode() == KeyEvent.VK_ENTER)
287           ok_actionPerformed();
288       }
289     });
290     jPanel3.setLayout(borderLayout1);
291     borderLayout1.setVgap(5);
292     jPanel1.add(ok);
293     jPanel1.add(example);
294     jPanel1.add(clear);
295     jPanel1.add(close);
296     jPanel3.add(jPanel2, java.awt.BorderLayout.CENTER);
297     jPanel2.setLayout(borderLayout3);
298     databaseButt = database.getDatabaseSelectorButton();
299     databaseButt.setFont(JvSwingUtils.getLabelFont());
300     database.addActionListener(new ActionListener()
301     {
302
303       @Override
304       public void actionPerformed(ActionEvent e)
305       {
306         try
307         {
308           databaseButt.setText(database.getSelectedItem()
309                   + (database.getSelectedSources().size() > 1 ? " (and "
310                           + database.getSelectedSources().size()
311                           + " others)" : ""));
312           String eq = database.getExampleQueries();
313           dbeg.setText(MessageManager.formatMessage(
314                   "label.example_query_param", new String[]
315                   { eq }));
316           boolean enablePunct = !(eq != null && eq.indexOf(",") > -1);
317           for (DbSourceProxy dbs : database.getSelectedSources())
318           {
319             if (dbs instanceof jalview.ws.dbsources.das.datamodel.DasSequenceSource)
320             {
321               enablePunct = false;
322               break;
323             }
324           }
325           replacePunctuation.setEnabled(enablePunct);
326
327         } catch (Exception ex)
328         {
329           dbeg.setText("");
330           replacePunctuation.setEnabled(true);
331         }
332         jPanel2.repaint();
333       }
334     });
335     dbeg.setText("");
336     jPanel2.add(databaseButt, java.awt.BorderLayout.NORTH);
337     jPanel2.add(dbeg, java.awt.BorderLayout.CENTER);
338     JPanel jPanel2a = new JPanel(new BorderLayout());
339     jPanel2a.add(jLabel1, java.awt.BorderLayout.NORTH);
340     jPanel2a.add(replacePunctuation, java.awt.BorderLayout.SOUTH);
341     jPanel2.add(jPanel2a, java.awt.BorderLayout.SOUTH);
342     // jPanel2.setPreferredSize(new Dimension())
343     jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER);
344     this.add(jPanel1, java.awt.BorderLayout.SOUTH);
345     this.add(jPanel3, java.awt.BorderLayout.CENTER);
346     this.add(jPanel2, java.awt.BorderLayout.NORTH);
347     jScrollPane1.getViewport().add(textArea);
348
349   }
350
351   protected void example_actionPerformed()
352   {
353     DbSourceProxy db = null;
354     try
355     {
356       textArea.setText(database.getExampleQueries());
357     } catch (Exception ex)
358     {
359     }
360     jPanel3.repaint();
361   }
362
363   protected void clear_actionPerformed()
364   {
365     textArea.setText("");
366     jPanel3.repaint();
367   }
368
369   JLabel dbeg = new JLabel();
370
371   JDatabaseTree database;
372
373   JButton databaseButt;
374
375   JLabel jLabel1 = new JLabel();
376
377   JCheckBox replacePunctuation = new JCheckBox();
378
379   JButton ok = new JButton();
380
381   JButton clear = new JButton();
382
383   JButton example = new JButton();
384
385   JButton close = new JButton();
386
387   JPanel jPanel1 = new JPanel();
388
389   JTextArea textArea = new JTextArea();
390
391   JScrollPane jScrollPane1 = new JScrollPane();
392
393   JPanel jPanel2 = new JPanel();
394
395   JPanel jPanel3 = new JPanel();
396
397   JPanel jPanel4 = new JPanel();
398
399   BorderLayout borderLayout1 = new BorderLayout();
400
401   BorderLayout borderLayout2 = new BorderLayout();
402
403   BorderLayout borderLayout3 = new BorderLayout();
404
405   public void close_actionPerformed(ActionEvent e)
406   {
407     try
408     {
409       frame.setClosed(true);
410     } catch (Exception ex)
411     {
412     }
413   }
414
415   public void ok_actionPerformed()
416   {
417     databaseButt.setEnabled(false);
418     example.setEnabled(false);
419     textArea.setEnabled(false);
420     ok.setEnabled(false);
421     close.setEnabled(false);
422
423     Thread worker = new Thread(this);
424     worker.start();
425   }
426
427   private void resetDialog()
428   {
429     databaseButt.setEnabled(true);
430     example.setEnabled(true);
431     textArea.setEnabled(true);
432     ok.setEnabled(true);
433     close.setEnabled(true);
434   }
435
436   @Override
437   public void run()
438   {
439     String error = "";
440     if (!database.hasSelection())
441     {
442       error += "Please select the source database\n";
443     }
444     // TODO: make this transformation more configurable
445     com.stevesoft.pat.Regex empty;
446     if (replacePunctuation.isEnabled() && replacePunctuation.isSelected())
447     {
448       empty = new com.stevesoft.pat.Regex(
449       // replace commas and spaces with a semicolon
450               "(\\s|[,; ])+", ";");
451     }
452     else
453     {
454       // just turn spaces and semicolons into single semicolons
455       empty = new com.stevesoft.pat.Regex("(\\s|[; ])+", ";");
456     }
457     textArea.setText(empty.replaceAll(textArea.getText()));
458     // see if there's anthing to search with
459     if (!new com.stevesoft.pat.Regex("[A-Za-z0-9_.]").search(textArea
460             .getText()))
461     {
462       error += "Please enter a (semi-colon separated list of) database id(s)";
463     }
464     if (error.length() > 0)
465     {
466       showErrorMessage(error);
467       resetDialog();
468       return;
469     }
470     // indicate if successive sources should be merged into one alignment.
471     boolean addToLast = false;
472     ArrayList<String> aresultq = new ArrayList<String>(), presultTitle = new ArrayList<String>();
473     ArrayList<AlignmentI> presult = new ArrayList<AlignmentI>(), aresult = new ArrayList<AlignmentI>();
474     Iterator<DbSourceProxy> proxies = database.getSelectedSources()
475             .iterator();
476     String[] qries;
477     List<String> nextfetch = Arrays.asList(qries = textArea.getText()
478             .split(";"));
479     Iterator<String> en = Arrays.asList(new String[0]).iterator();
480     int nqueries = qries.length;
481     while (proxies.hasNext() && (en.hasNext() || nextfetch.size() > 0))
482     {
483       if (!en.hasNext() && nextfetch.size() > 0)
484       {
485         en = nextfetch.iterator();
486         nqueries = nextfetch.size();
487         // save the remaining queries in the original array
488         qries = nextfetch.toArray(new String[nqueries]);
489         nextfetch = new ArrayList<String>();
490       }
491
492       DbSourceProxy proxy = proxies.next();
493       boolean isAliSource = false;
494       try
495       {
496         // update status
497         guiWindow.setProgressBar(MessageManager.formatMessage("status.fetching_sequence_queries_from", new String[]{Integer.valueOf(nqueries).toString(),proxy.getDbName()}), Thread
498                 .currentThread().hashCode());
499         isAliSource = proxy.isA(DBRefSource.ALIGNMENTDB);
500         if (proxy.getAccessionSeparator() == null)
501         {
502           while (en.hasNext())
503           {
504             String item = en.next();
505             try
506             {
507               if (aresult != null)
508               {
509                 try
510                 {
511                   // give the server a chance to breathe
512                   Thread.sleep(5);
513                 } catch (Exception e)
514                 {
515                   //
516                 }
517
518               }
519
520               AlignmentI indres = null;
521               try
522               {
523                 indres = proxy.getSequenceRecords(item);
524               } catch (OutOfMemoryError oome)
525               {
526                 new OOMWarning("fetching " + item + " from "
527                         + proxy.getDbName(), oome, this);
528               }
529               if (indres != null)
530               {
531                 aresultq.add(item);
532                 aresult.add(indres);
533               }
534               else
535               {
536                 nextfetch.add(item);
537               }
538             } catch (Exception e)
539             {
540               jalview.bin.Cache.log.info("Error retrieving " + item
541                       + " from " + proxy.getDbName(), e);
542               nextfetch.add(item);
543             }
544           }
545         }
546         else
547         {
548           StringBuffer multiacc = new StringBuffer();
549           ArrayList<String> tosend = new ArrayList<String>();
550           while (en.hasNext())
551           {
552             String nel = en.next();
553             tosend.add(nel);
554             multiacc.append(nel);
555             if (en.hasNext())
556             {
557               multiacc.append(proxy.getAccessionSeparator());
558             }
559           }
560           try
561           {
562             AlignmentI rslt;
563             SequenceI[] rs;
564             List<String> nores = new ArrayList<String>();
565             rslt = proxy.getSequenceRecords(multiacc.toString());
566             if (rslt == null || rslt.getHeight() == 0)
567             {
568               // no results - pass on all queries to next source
569               nextfetch.addAll(tosend);
570             }
571             else
572             {
573               aresultq.add(multiacc.toString());
574               aresult.add(rslt);
575
576               rs = rslt.getSequencesArray();
577               // search for each query in the dbrefs associated with each
578               // sequence
579               // returned.
580               // ones we do not find will be used to query next source (if any)
581               for (String q : tosend)
582               {
583                 DBRefEntry dbr = new DBRefEntry(), found[] = null;
584                 dbr.setSource(proxy.getDbSource());
585                 dbr.setVersion(null);
586                 if (proxy.getAccessionValidator() != null)
587                 {
588                   Regex vgr = proxy.getAccessionValidator();
589                   vgr.search(q);
590                   if (vgr.numSubs() > 0)
591                   {
592                     dbr.setAccessionId(vgr.stringMatched(1));
593                   }
594                   else
595                   {
596                     dbr.setAccessionId(vgr.stringMatched());
597                   }
598                 }
599                 else
600                 {
601                   dbr.setAccessionId(q);
602                 }
603                 boolean rfound = false;
604                 for (int r = 0; r < rs.length; r++)
605                 {
606                   if (rs[r] != null
607                           && (found = DBRefUtils.searchRefs(
608                                   rs[r].getDBRef(), dbr)) != null
609                           && found.length > 0)
610                   {
611                     rfound = true;
612                     rs[r] = null;
613                     continue;
614                   }
615                 }
616                 if (!rfound)
617                 {
618                   nextfetch.add(q);
619                 }
620               }
621             }
622           } catch (OutOfMemoryError oome)
623           {
624             new OOMWarning("fetching " + multiacc + " from "
625                     + database.getSelectedItem(), oome, this);
626           }
627         }
628
629       } catch (Exception e)
630       {
631         showErrorMessage("Error retrieving " + textArea.getText()
632                 + " from " + database.getSelectedItem());
633         // error
634         // +="Couldn't retrieve sequences from "+database.getSelectedItem();
635         System.err.println("Retrieval failed for source ='"
636                 + database.getSelectedItem() + "' and query\n'"
637                 + textArea.getText() + "'\n");
638         e.printStackTrace();
639       } catch (OutOfMemoryError e)
640       {
641         // resets dialog box - so we don't use OOMwarning here.
642         showErrorMessage("Out of Memory when retrieving "
643                 + textArea.getText()
644                 + " from "
645                 + database.getSelectedItem()
646                 + "\nPlease see the Jalview FAQ for instructions for increasing the memory available to Jalview.\n");
647         e.printStackTrace();
648       } catch (Error e)
649       {
650         showErrorMessage("Serious Error retrieving " + textArea.getText()
651                 + " from " + database.getSelectedItem());
652         e.printStackTrace();
653       }
654       // Stack results ready for opening in alignment windows
655       if (aresult != null && aresult.size() > 0)
656       {
657         AlignmentI ar = null;
658         if (isAliSource)
659         {
660           addToLast = false;
661           // new window for each result
662           while (aresult.size() > 0)
663           {
664             presult.add(aresult.remove(0));
665             presultTitle.add(aresultq.remove(0) + " "
666                     + getDefaultRetrievalTitle());
667           }
668         }
669         else
670         {
671           String titl = null;
672           if (addToLast && presult.size() > 0)
673           {
674             ar = presult.remove(presult.size() - 1);
675             titl = presultTitle.remove(presultTitle.size() - 1);
676           }
677           // concatenate all results in one window
678           while (aresult.size() > 0)
679           {
680             if (ar == null)
681             {
682               ar = aresult.remove(0);
683             }
684             else
685             {
686               ar.append(aresult.remove(0));
687             }
688             ;
689           }
690           addToLast = true;
691           presult.add(ar);
692           presultTitle.add(titl);
693         }
694       }
695       guiWindow.setProgressBar(MessageManager.getString("status.finshed_querying"), Thread.currentThread()
696               .hashCode());
697     }
698     guiWindow.setProgressBar((presult.size() > 0) ? MessageManager.getString("status.parsing_results")
699             : MessageManager.getString("status.processing"), Thread.currentThread().hashCode());
700     // process results
701     while (presult.size() > 0)
702     {
703       parseResult(presult.remove(0), presultTitle.remove(0), null);
704     }
705     // only remove visual delay after we finished parsing.
706     guiWindow.setProgressBar(null, Thread.currentThread().hashCode());
707     if (nextfetch.size() > 0)
708     {
709       StringBuffer sb = new StringBuffer();
710       sb.append("Didn't retrieve the following "
711               + (nextfetch.size() == 1 ? "query" : nextfetch.size()
712                       + " queries") + ": \n");
713       int l = sb.length(), lr = 0;
714       for (String s : nextfetch)
715       {
716         if (l != sb.length())
717         {
718           sb.append("; ");
719         }
720         if (lr - sb.length() > 40)
721         {
722           sb.append("\n");
723         }
724         sb.append(s);
725       }
726       showErrorMessage(sb.toString());
727     }
728     resetDialog();
729   }
730
731   AlignmentI parseResult(String result, String title)
732   {
733     String format = new IdentifyFile().Identify(result, "Paste");
734     Alignment sequences = null;
735     if (FormatAdapter.isValidFormat(format))
736     {
737       sequences = null;
738       try
739       {
740         sequences = new FormatAdapter().readFile(result.toString(),
741                 "Paste", format);
742       } catch (Exception ex)
743       {
744       }
745
746       if (sequences != null)
747       {
748         return parseResult(sequences, title, format);
749       }
750     }
751     else
752     {
753       showErrorMessage("Error retrieving " + textArea.getText() + " from "
754               + database.getSelectedItem());
755     }
756
757     return null;
758   }
759
760   /**
761    * 
762    * @return a standard title for any results retrieved using the currently
763    *         selected source and settings
764    */
765   public String getDefaultRetrievalTitle()
766   {
767     return "Retrieved from " + database.getSelectedItem();
768   }
769
770   AlignmentI parseResult(AlignmentI al, String title,
771           String currentFileFormat)
772   {
773
774     if (al != null && al.getHeight() > 0)
775     {
776       if (alignFrame == null)
777       {
778         AlignFrame af = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
779                 AlignFrame.DEFAULT_HEIGHT);
780         if (currentFileFormat != null)
781         {
782           af.currentFileFormat = currentFileFormat; // WHAT IS THE DEFAULT
783           // FORMAT FOR
784           // NON-FormatAdapter Sourced
785           // Alignments?
786         }
787
788         if (title == null)
789         {
790           title = getDefaultRetrievalTitle();
791         }
792         SequenceFeature[] sfs = null;
793         List<SequenceI> alsqs;
794         synchronized (alsqs = al.getSequences())
795         {
796           for (SequenceI sq : alsqs)
797           {
798             if ((sfs = (sq).getDatasetSequence().getSequenceFeatures()) != null)
799             {
800               if (sfs.length > 0)
801               {
802                 af.setShowSeqFeatures(true);
803                 break;
804               }
805             }
806
807           }
808         }
809         Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH,
810                 AlignFrame.DEFAULT_HEIGHT);
811
812         af.statusBar.setText(MessageManager
813                 .getString("label.successfully_pasted_alignment_file"));
814
815         try
816         {
817           af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN",
818                   false));
819         } catch (Exception ex)
820         {
821         }
822       }
823       else
824       {
825         for (int i = 0; i < al.getHeight(); i++)
826         {
827           alignFrame.viewport.getAlignment().addSequence(
828                   al.getSequenceAt(i)); // this
829           // also
830           // creates
831           // dataset
832           // sequence
833           // entries
834         }
835         alignFrame.viewport.setEndSeq(alignFrame.viewport.getAlignment()
836                 .getHeight());
837         alignFrame.viewport.getAlignment().getWidth();
838         alignFrame.viewport.firePropertyChange("alignment", null,
839                 alignFrame.viewport.getAlignment().getSequences());
840       }
841     }
842     return al;
843   }
844
845   void showErrorMessage(final String error)
846   {
847     resetDialog();
848     javax.swing.SwingUtilities.invokeLater(new Runnable()
849     {
850       @Override
851       public void run()
852       {
853         JOptionPane.showInternalMessageDialog(Desktop.desktop, error,
854                 MessageManager.getString("label.error_retrieving_data"),
855                 JOptionPane.WARNING_MESSAGE);
856       }
857     });
858   }
859 }