JAL-1834 removed quotes around truncated strings with ellipsis
[jalview.git] / src / jalview / gui / TreePanel.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.analysis.AlignmentSorter;
24 import jalview.analysis.NJTree;
25 import jalview.api.analysis.ScoreModelI;
26 import jalview.api.analysis.ViewBasedAnalysisI;
27 import jalview.bin.Cache;
28 import jalview.commands.CommandI;
29 import jalview.commands.OrderCommand;
30 import jalview.datamodel.Alignment;
31 import jalview.datamodel.AlignmentI;
32 import jalview.datamodel.AlignmentView;
33 import jalview.datamodel.BinaryNode;
34 import jalview.datamodel.ColumnSelection;
35 import jalview.datamodel.DBRefEntry;
36 import jalview.datamodel.NodeTransformI;
37 import jalview.datamodel.SequenceFeature;
38 import jalview.datamodel.SequenceI;
39 import jalview.datamodel.SequenceNode;
40 import jalview.io.JalviewFileChooser;
41 import jalview.io.JalviewFileView;
42 import jalview.io.NewickFile;
43 import jalview.jbgui.GTreePanel;
44 import jalview.schemes.ResidueProperties;
45 import jalview.util.MessageManager;
46 import jalview.viewmodel.AlignmentViewport;
47
48 import java.awt.Font;
49 import java.awt.Graphics;
50 import java.awt.event.ActionEvent;
51 import java.awt.event.ActionListener;
52 import java.awt.image.BufferedImage;
53 import java.beans.PropertyChangeEvent;
54 import java.io.FileOutputStream;
55 import java.util.ArrayList;
56 import java.util.List;
57
58 import javax.imageio.ImageIO;
59 import javax.swing.ButtonGroup;
60 import javax.swing.JMenuItem;
61 import javax.swing.JRadioButtonMenuItem;
62
63 import org.jibble.epsgraphics.EpsGraphics2D;
64
65 /**
66  * DOCUMENT ME!
67  * 
68  * @author $author$
69  * @version $Revision$
70  */
71 public class TreePanel extends GTreePanel
72 {
73   String type;
74
75   String pwtype;
76
77   TreeCanvas treeCanvas;
78
79   NJTree tree;
80
81   AlignViewport av;
82
83   /**
84    * Creates a new TreePanel object.
85    * 
86    * @param av
87    *          DOCUMENT ME!
88    * @param seqVector
89    *          DOCUMENT ME!
90    * @param type
91    *          DOCUMENT ME!
92    * @param pwtype
93    *          DOCUMENT ME!
94    * @param s
95    *          DOCUMENT ME!
96    * @param e
97    *          DOCUMENT ME!
98    */
99   public TreePanel(AlignmentPanel ap, String type, String pwtype)
100   {
101     super();
102     initTreePanel(ap, type, pwtype, null, null);
103
104     // We know this tree has distances. JBPNote TODO: prolly should add this as
105     // a userdefined default
106     // showDistances(true);
107   }
108
109   /**
110    * Creates a new TreePanel object.
111    * 
112    * @param av
113    *          DOCUMENT ME!
114    * @param seqVector
115    *          DOCUMENT ME!
116    * @param newtree
117    *          DOCUMENT ME!
118    * @param type
119    *          DOCUMENT ME!
120    * @param pwtype
121    *          DOCUMENT ME!
122    */
123   public TreePanel(AlignmentPanel ap, String type, String pwtype,
124           NewickFile newtree)
125   {
126     super();
127     initTreePanel(ap, type, pwtype, newtree, null);
128   }
129
130   public TreePanel(AlignmentPanel av, String type, String pwtype,
131           NewickFile newtree, AlignmentView inputData)
132   {
133     super();
134     initTreePanel(av, type, pwtype, newtree, inputData);
135   }
136
137   public AlignmentI getAlignment()
138   {
139     return treeCanvas.av.getAlignment();
140   }
141
142   public AlignmentViewport getViewPort()
143   {
144     return treeCanvas.av;
145   }
146
147   void initTreePanel(AlignmentPanel ap, String type, String pwtype,
148           NewickFile newTree, AlignmentView inputData)
149   {
150
151     av = ap.av;
152     this.type = type;
153     this.pwtype = pwtype;
154
155     treeCanvas = new TreeCanvas(this, ap, scrollPane);
156     scrollPane.setViewportView(treeCanvas);
157
158     PaintRefresher.Register(this, ap.av.getSequenceSetId());
159
160     buildAssociatedViewMenu();
161
162     av.addPropertyChangeListener(new java.beans.PropertyChangeListener()
163     {
164       public void propertyChange(PropertyChangeEvent evt)
165       {
166         if (evt.getPropertyName().equals("alignment"))
167         {
168           if (tree == null)
169           {
170             System.out.println("tree is null");
171             // TODO: deal with case when a change event is received whilst a
172             // tree is still being calculated - should save reference for
173             // processing message later.
174             return;
175           }
176           if (evt.getNewValue() == null)
177           {
178             System.out
179                     .println("new alignment sequences vector value is null");
180           }
181
182           tree.UpdatePlaceHolders((List<SequenceI>) evt.getNewValue());
183           treeCanvas.nameHash.clear(); // reset the mapping between canvas
184           // rectangles and leafnodes
185           repaint();
186         }
187       }
188     });
189
190     TreeLoader tl = new TreeLoader(newTree);
191     if (inputData != null)
192     {
193       tl.odata = inputData;
194     }
195     tl.start();
196
197   }
198
199   public void viewMenu_menuSelected()
200   {
201     buildAssociatedViewMenu();
202   }
203
204   void buildAssociatedViewMenu()
205   {
206     AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(av
207             .getSequenceSetId());
208     if (aps.length == 1 && treeCanvas.ap == aps[0])
209     {
210       associateLeavesMenu.setVisible(false);
211       return;
212     }
213
214     associateLeavesMenu.setVisible(true);
215
216     if ((viewMenu.getItem(viewMenu.getItemCount() - 2) instanceof JMenuItem))
217     {
218       viewMenu.insertSeparator(viewMenu.getItemCount() - 1);
219     }
220
221     associateLeavesMenu.removeAll();
222
223     JRadioButtonMenuItem item;
224     ButtonGroup buttonGroup = new ButtonGroup();
225     int i, iSize = aps.length;
226     final TreePanel thisTreePanel = this;
227     for (i = 0; i < iSize; i++)
228     {
229       final AlignmentPanel ap = aps[i];
230       item = new JRadioButtonMenuItem(ap.av.viewName, ap == treeCanvas.ap);
231       buttonGroup.add(item);
232       item.addActionListener(new ActionListener()
233       {
234         public void actionPerformed(ActionEvent evt)
235         {
236           treeCanvas.applyToAllViews = false;
237           treeCanvas.ap = ap;
238           treeCanvas.av = ap.av;
239           PaintRefresher.Register(thisTreePanel, ap.av.getSequenceSetId());
240         }
241       });
242
243       associateLeavesMenu.add(item);
244     }
245
246     final JRadioButtonMenuItem itemf = new JRadioButtonMenuItem(
247             "label.all_views");
248     buttonGroup.add(itemf);
249     itemf.setSelected(treeCanvas.applyToAllViews);
250     itemf.addActionListener(new ActionListener()
251     {
252       public void actionPerformed(ActionEvent evt)
253       {
254         treeCanvas.applyToAllViews = itemf.isSelected();
255       }
256     });
257     associateLeavesMenu.add(itemf);
258
259   }
260
261   class TreeLoader extends Thread
262   {
263     NewickFile newtree;
264
265     jalview.datamodel.AlignmentView odata = null;
266
267     public TreeLoader(NewickFile newtree)
268     {
269       this.newtree = newtree;
270       if (newtree != null)
271       {
272         // Must be outside run(), as Jalview2XML tries to
273         // update distance/bootstrap visibility at the same time
274         showBootstrap(newtree.HasBootstrap());
275         showDistances(newtree.HasDistances());
276       }
277     }
278
279     public void run()
280     {
281
282       if (newtree != null)
283       {
284         if (odata == null)
285         {
286           tree = new NJTree(av.getAlignment().getSequencesArray(), newtree);
287         }
288         else
289         {
290           tree = new NJTree(av.getAlignment().getSequencesArray(), odata,
291                   newtree);
292         }
293         if (!tree.hasOriginalSequenceData())
294         {
295           allowOriginalSeqData(false);
296         }
297       }
298       else
299       {
300         int start, end;
301         SequenceI[] seqs;
302         boolean selview = av.getSelectionGroup() != null
303                 && av.getSelectionGroup().getSize() > 1;
304         AlignmentView seqStrings = av.getAlignmentView(selview);
305         if (!selview)
306         {
307           start = 0;
308           end = av.getAlignment().getWidth();
309           seqs = av.getAlignment().getSequencesArray();
310         }
311         else
312         {
313           start = av.getSelectionGroup().getStartRes();
314           end = av.getSelectionGroup().getEndRes() + 1;
315           seqs = av.getSelectionGroup().getSequencesInOrder(
316                   av.getAlignment());
317         }
318         ScoreModelI sm = ResidueProperties.getScoreModel(pwtype);
319         if (sm instanceof ViewBasedAnalysisI)
320         {
321           try
322           {
323             sm = sm.getClass().newInstance();
324             ((ViewBasedAnalysisI) sm)
325                     .configureFromAlignmentView(treeCanvas.ap);
326           } catch (Exception q)
327           {
328             Cache.log.error("Couldn't create a scoremodel instance for "
329                     + sm.getName());
330           }
331           tree = new NJTree(seqs, seqStrings, type, pwtype, sm, start, end);
332         }
333         else
334         {
335           tree = new NJTree(seqs, seqStrings, type, pwtype, null, start,
336                   end);
337         }
338         showDistances(true);
339       }
340
341       tree.reCount(tree.getTopNode());
342       tree.findHeight(tree.getTopNode());
343       treeCanvas.setTree(tree);
344       treeCanvas.repaint();
345       av.setCurrentTree(tree);
346       if (av.getSortByTree())
347       {
348         sortByTree_actionPerformed();
349       }
350     }
351   }
352
353   public void showDistances(boolean b)
354   {
355     treeCanvas.setShowDistances(b);
356     distanceMenu.setSelected(b);
357   }
358
359   public void showBootstrap(boolean b)
360   {
361     treeCanvas.setShowBootstrap(b);
362     bootstrapMenu.setSelected(b);
363   }
364
365   public void showPlaceholders(boolean b)
366   {
367     placeholdersMenu.setState(b);
368     treeCanvas.setMarkPlaceholders(b);
369   }
370
371   private void allowOriginalSeqData(boolean b)
372   {
373     originalSeqData.setVisible(b);
374   }
375
376   /**
377    * DOCUMENT ME!
378    * 
379    * @return DOCUMENT ME!
380    */
381   public NJTree getTree()
382   {
383     return tree;
384   }
385
386   /**
387    * DOCUMENT ME!
388    * 
389    * @param e
390    *          DOCUMENT ME!
391    */
392   public void textbox_actionPerformed(ActionEvent e)
393   {
394     CutAndPasteTransfer cap = new CutAndPasteTransfer();
395
396     StringBuffer buffer = new StringBuffer();
397
398     if (type.equals("AV"))
399     {
400       buffer.append("Average distance tree using ");
401     }
402     else
403     {
404       buffer.append("Neighbour joining tree using ");
405     }
406
407     if (pwtype.equals("BL"))
408     {
409       buffer.append("BLOSUM62");
410     }
411     else
412     {
413       buffer.append("PID");
414     }
415
416     jalview.io.NewickFile fout = new jalview.io.NewickFile(
417             tree.getTopNode());
418     try
419     {
420       cap.setText(fout.print(tree.isHasBootstrap(), tree.isHasDistances(),
421               tree.isHasRootDistance()));
422       Desktop.addInternalFrame(cap, buffer.toString(), 500, 100);
423     } catch (OutOfMemoryError oom)
424     {
425       new OOMWarning("generating newick tree file", oom);
426       cap.dispose();
427     }
428
429   }
430
431   /**
432    * DOCUMENT ME!
433    * 
434    * @param e
435    *          DOCUMENT ME!
436    */
437   public void saveAsNewick_actionPerformed(ActionEvent e)
438   {
439     JalviewFileChooser chooser = new JalviewFileChooser(
440             jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
441     chooser.setFileView(new JalviewFileView());
442     chooser.setDialogTitle(MessageManager.getString("label.save_tree_as_newick"));
443     chooser.setToolTipText(MessageManager.getString("action.save"));
444
445     int value = chooser.showSaveDialog(null);
446
447     if (value == JalviewFileChooser.APPROVE_OPTION)
448     {
449       String choice = chooser.getSelectedFile().getPath();
450       jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
451               .getSelectedFile().getParent());
452
453       try
454       {
455         jalview.io.NewickFile fout = new jalview.io.NewickFile(
456                 tree.getTopNode());
457         String output = fout.print(tree.isHasBootstrap(),
458                 tree.isHasDistances(), tree.isHasRootDistance());
459         java.io.PrintWriter out = new java.io.PrintWriter(
460                 new java.io.FileWriter(choice));
461         out.println(output);
462         out.close();
463       } catch (Exception ex)
464       {
465         ex.printStackTrace();
466       }
467     }
468   }
469
470   /**
471    * DOCUMENT ME!
472    * 
473    * @param e
474    *          DOCUMENT ME!
475    */
476   public void printMenu_actionPerformed(ActionEvent e)
477   {
478     // Putting in a thread avoids Swing painting problems
479     treeCanvas.startPrinting();
480   }
481
482   public void originalSeqData_actionPerformed(ActionEvent e)
483   {
484     if (!tree.hasOriginalSequenceData())
485     {
486       jalview.bin.Cache.log
487               .info("Unexpected call to originalSeqData_actionPerformed - should have hidden this menu action.");
488       return;
489     }
490     // decide if av alignment is sufficiently different to original data to
491     // warrant a new window to be created
492     // create new alignmnt window with hidden regions (unhiding hidden regions
493     // yields unaligned seqs)
494     // or create a selection box around columns in alignment view
495     // test Alignment(SeqCigar[])
496     char gc = '-';
497     try
498     {
499       // we try to get the associated view's gap character
500       // but this may fail if the view was closed...
501       gc = av.getGapCharacter();
502
503     } catch (Exception ex)
504     {
505     }
506     ;
507     Object[] alAndColsel = tree.seqData.getAlignmentAndColumnSelection(gc);
508
509     if (alAndColsel != null && alAndColsel[0] != null)
510     {
511       // AlignmentOrder origorder = new AlignmentOrder(alAndColsel[0]);
512
513       Alignment al = new Alignment((SequenceI[]) alAndColsel[0]);
514       Alignment dataset = (av != null && av.getAlignment() != null) ? av
515               .getAlignment().getDataset() : null;
516       if (dataset != null)
517       {
518         al.setDataset(dataset);
519       }
520
521       if (true)
522       {
523         // make a new frame!
524         AlignFrame af = new AlignFrame(al,
525                 (ColumnSelection) alAndColsel[1], AlignFrame.DEFAULT_WIDTH,
526                 AlignFrame.DEFAULT_HEIGHT);
527
528         // >>>This is a fix for the moment, until a better solution is
529         // found!!<<<
530         // af.getFeatureRenderer().transferSettings(alignFrame.getFeatureRenderer());
531
532         // af.addSortByOrderMenuItem(ServiceName + " Ordering",
533         // msaorder);
534
535         Desktop.addInternalFrame(af, MessageManager.formatMessage(
536                 "label.original_data_for_params", new Object[]
537                 { this.title }), AlignFrame.DEFAULT_WIDTH,
538                 AlignFrame.DEFAULT_HEIGHT);
539       }
540     }
541   }
542
543   /**
544    * DOCUMENT ME!
545    * 
546    * @param e
547    *          DOCUMENT ME!
548    */
549   public void fitToWindow_actionPerformed(ActionEvent e)
550   {
551     treeCanvas.fitToWindow = fitToWindow.isSelected();
552     repaint();
553   }
554
555   /**
556    * sort the associated alignment view by the current tree.
557    * 
558    * @param e
559    */
560   @Override
561   public void sortByTree_actionPerformed()
562   {
563
564     if (treeCanvas.applyToAllViews)
565     {
566       final ArrayList<CommandI> commands = new ArrayList<CommandI>();
567       for (AlignmentPanel ap : PaintRefresher.getAssociatedPanels(av
568               .getSequenceSetId()))
569       {
570         commands.add(sortAlignmentIn(ap.av.getAlignPanel()));
571       }
572       av.getAlignPanel().alignFrame.addHistoryItem(new CommandI()
573       {
574
575         @Override
576         public void undoCommand(AlignmentI[] views)
577         {
578           for (CommandI tsort : commands)
579           {
580             tsort.undoCommand(views);
581           }
582         }
583
584         @Override
585         public int getSize()
586         {
587           return commands.size();
588         }
589
590         @Override
591         public String getDescription()
592         {
593           return "Tree Sort (many views)";
594         }
595
596         @Override
597         public void doCommand(AlignmentI[] views)
598         {
599
600           for (CommandI tsort : commands)
601           {
602             tsort.doCommand(views);
603           }
604         }
605       });
606       for (AlignmentPanel ap : PaintRefresher.getAssociatedPanels(av
607               .getSequenceSetId()))
608       {
609         // ensure all the alignFrames refresh their GI after adding an undo item
610         ap.alignFrame.updateEditMenuBar();
611       }
612     }
613     else
614     {
615       treeCanvas.ap.alignFrame
616               .addHistoryItem(sortAlignmentIn(treeCanvas.ap));
617     }
618
619   }
620
621   public CommandI sortAlignmentIn(AlignmentPanel ap)
622   {
623     AlignmentViewport av = ap.av;
624     SequenceI[] oldOrder = av.getAlignment().getSequencesArray();
625     AlignmentSorter.sortByTree(av.getAlignment(), tree);
626     CommandI undo;
627     undo = new OrderCommand("Tree Sort", oldOrder, av.getAlignment());
628
629     ap.paintAlignment(true);
630     return undo;
631   }
632
633   /**
634    * DOCUMENT ME!
635    * 
636    * @param e
637    *          DOCUMENT ME!
638    */
639   public void font_actionPerformed(ActionEvent e)
640   {
641     if (treeCanvas == null)
642     {
643       return;
644     }
645
646     new FontChooser(this);
647   }
648
649   public Font getTreeFont()
650   {
651     return treeCanvas.font;
652   }
653
654   public void setTreeFont(Font font)
655   {
656     if (treeCanvas != null)
657     {
658       treeCanvas.setFont(font);
659     }
660   }
661
662   /**
663    * DOCUMENT ME!
664    * 
665    * @param e
666    *          DOCUMENT ME!
667    */
668   public void distanceMenu_actionPerformed(ActionEvent e)
669   {
670     treeCanvas.setShowDistances(distanceMenu.isSelected());
671   }
672
673   /**
674    * DOCUMENT ME!
675    * 
676    * @param e
677    *          DOCUMENT ME!
678    */
679   public void bootstrapMenu_actionPerformed(ActionEvent e)
680   {
681     treeCanvas.setShowBootstrap(bootstrapMenu.isSelected());
682   }
683
684   /**
685    * DOCUMENT ME!
686    * 
687    * @param e
688    *          DOCUMENT ME!
689    */
690   public void placeholdersMenu_actionPerformed(ActionEvent e)
691   {
692     treeCanvas.setMarkPlaceholders(placeholdersMenu.isSelected());
693   }
694
695   /**
696    * DOCUMENT ME!
697    * 
698    * @param e
699    *          DOCUMENT ME!
700    */
701   public void epsTree_actionPerformed(ActionEvent e)
702   {
703     boolean accurateText = true;
704
705     String renderStyle = jalview.bin.Cache.getDefault("EPS_RENDERING",
706             "Prompt each time");
707
708     // If we need to prompt, and if the GUI is visible then
709     // Prompt for EPS rendering style
710     if (renderStyle.equalsIgnoreCase("Prompt each time")
711             && !(System.getProperty("java.awt.headless") != null && System
712                     .getProperty("java.awt.headless").equals("true")))
713     {
714       EPSOptions eps = new EPSOptions();
715       renderStyle = eps.getValue();
716
717       if (renderStyle == null || eps.cancelled)
718       {
719         return;
720       }
721
722     }
723
724     if (renderStyle.equalsIgnoreCase("text"))
725     {
726       accurateText = false;
727     }
728
729     int width = treeCanvas.getWidth();
730     int height = treeCanvas.getHeight();
731
732     try
733     {
734       jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
735               jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
736               { "eps" }, new String[]
737               { "Encapsulated Postscript" }, "Encapsulated Postscript");
738       chooser.setFileView(new jalview.io.JalviewFileView());
739       chooser.setDialogTitle(MessageManager.getString("label.create_eps_from_tree"));
740       chooser.setToolTipText(MessageManager.getString("action.save"));
741
742       int value = chooser.showSaveDialog(this);
743
744       if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION)
745       {
746         return;
747       }
748
749       jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
750               .getSelectedFile().getParent());
751
752       FileOutputStream out = new FileOutputStream(chooser.getSelectedFile());
753       EpsGraphics2D pg = new EpsGraphics2D("Tree", out, 0, 0, width, height);
754
755       pg.setAccurateTextMode(accurateText);
756
757       treeCanvas.draw(pg, width, height);
758
759       pg.flush();
760       pg.close();
761     } catch (Exception ex)
762     {
763       ex.printStackTrace();
764     }
765   }
766
767   /**
768    * DOCUMENT ME!
769    * 
770    * @param e
771    *          DOCUMENT ME!
772    */
773   public void pngTree_actionPerformed(ActionEvent e)
774   {
775     int width = treeCanvas.getWidth();
776     int height = treeCanvas.getHeight();
777
778     try
779     {
780       jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
781               jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
782               { "png" }, new String[]
783               { "Portable network graphics" }, "Portable network graphics");
784
785       chooser.setFileView(new jalview.io.JalviewFileView());
786       chooser.setDialogTitle(MessageManager.getString("label.create_png_from_tree"));
787       chooser.setToolTipText(MessageManager.getString("action.save"));
788
789       int value = chooser.showSaveDialog(this);
790
791       if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION)
792       {
793         return;
794       }
795
796       jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
797               .getSelectedFile().getParent());
798
799       FileOutputStream out = new FileOutputStream(chooser.getSelectedFile());
800
801       BufferedImage bi = new BufferedImage(width, height,
802               BufferedImage.TYPE_INT_RGB);
803       Graphics png = bi.getGraphics();
804
805       treeCanvas.draw(png, width, height);
806
807       ImageIO.write(bi, "png", out);
808       out.close();
809     } catch (Exception ex)
810     {
811       ex.printStackTrace();
812     }
813   }
814
815   /**
816    * change node labels to the annotation referred to by labelClass TODO:
817    * promote to a datamodel modification that can be undone TODO: make argument
818    * one case of a generic transformation function ie { undoStep = apply(Tree,
819    * TransformFunction)};
820    * 
821    * @param labelClass
822    */
823   public void changeNames(final String labelClass)
824   {
825     tree.applyToNodes(new NodeTransformI()
826     {
827
828       public void transform(BinaryNode node)
829       {
830         if (node instanceof SequenceNode
831                 && !((SequenceNode) node).isPlaceholder()
832                 && !((SequenceNode) node).isDummy())
833         {
834           String newname = null;
835           SequenceI sq = (SequenceI) ((SequenceNode) node).element();
836           if (sq != null)
837           {
838             // search dbrefs, features and annotation
839             DBRefEntry[] refs = jalview.util.DBRefUtils.selectRefs(
840                     sq.getDBRef(), new String[]
841                     { labelClass.toUpperCase() });
842             if (refs != null)
843             {
844               for (int i = 0; i < refs.length; i++)
845               {
846                 if (newname == null)
847                 {
848                   newname = new String(refs[i].getAccessionId());
849                 }
850                 else
851                 {
852                   newname = newname + "; " + refs[i].getAccessionId();
853                 }
854               }
855             }
856             if (newname == null)
857             {
858               SequenceFeature sf[] = sq.getSequenceFeatures();
859               for (int i = 0; sf != null && i < sf.length; i++)
860               {
861                 if (sf[i].getType().equals(labelClass))
862                 {
863                   if (newname == null)
864                   {
865                     newname = new String(sf[i].getDescription());
866                   }
867                   else
868                   {
869                     newname = newname + "; " + sf[i].getDescription();
870                   }
871                 }
872               }
873             }
874           }
875           if (newname != null)
876           {
877             String oldname = ((SequenceNode) node).getName();
878             // TODO : save in the undo object for this modification.
879             ((SequenceNode) node).setName(newname);
880           }
881         }
882       }
883     });
884   }
885 }