+
+ /**
+ * change node labels to the annotation referred to by labelClass TODO:
+ * promote to a datamodel modification that can be undone TODO: make argument
+ * one case of a generic transformation function ie { undoStep = apply(Tree,
+ * TransformFunction)};
+ *
+ * @param labelClass
+ */
+ public void changeNames(final String labelClass)
+ {
+ tree.applyToNodes(new NodeTransformI()
+ {
+
+ public void transform(BinaryNode node)
+ {
+ if (node instanceof SequenceNode
+ && !((SequenceNode) node).isPlaceholder()
+ && !((SequenceNode) node).isDummy())
+ {
+ String newname = null;
+ SequenceI sq = (SequenceI) ((SequenceNode) node).element();
+ if (sq != null)
+ {
+ // search dbrefs, features and annotation
+ DBRefEntry[] refs = jalview.util.DBRefUtils.selectRefs(
+ sq.getDBRef(), new String[]
+ { labelClass.toUpperCase() });
+ if (refs != null)
+ {
+ for (int i = 0; i < refs.length; i++)
+ {
+ if (newname == null)
+ {
+ newname = new String(refs[i].getAccessionId());
+ }
+ else
+ {
+ newname = newname + "; " + refs[i].getAccessionId();
+ }
+ }
+ }
+ if (newname == null)
+ {
+ SequenceFeature sf[] = sq.getSequenceFeatures();
+ for (int i = 0; sf != null && i < sf.length; i++)
+ {
+ if (sf[i].getType().equals(labelClass))
+ {
+ if (newname == null)
+ {
+ newname = new String(sf[i].getDescription());
+ }
+ else
+ {
+ newname = newname + "; " + sf[i].getDescription();
+ }
+ }
+ }
+ }
+ }
+ if (newname != null)
+ {
+ String oldname = ((SequenceNode) node).getName();
+ // TODO : save in the undo object for this modification.
+ ((SequenceNode) node).setName(newname);
+ }
+ }
+ }
+ });
+ }