}
/**
- * Set the selection group for this window.
+ * Set the selection group for this window. Also sets the current alignment as
+ * the context for the group, if it does not already have one.
*
* @param sg
* - group holding references to sequences in this alignment view
public void setSelectionGroup(SequenceGroup sg)
{
selectionGroup = sg;
- if (sg != null)
+ if (sg != null && sg.getContext() == null)
{
sg.setContext(alignment);
}
import jalview.datamodel.SearchResults;
import jalview.datamodel.SearchResultsI;
import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.io.DataSourceType;
import jalview.io.FileLoader;
af.getViewport().setSearchResults(null);
assertFalse(af.getViewport().hasSearchResults());
}
+
+ /**
+ * Verify that setting the selection group has the side-effect of setting the
+ * context on the group, unless it already has one
+ */
+ @Test(groups = { "Functional" })
+ public void testSetSelectionGroup()
+ {
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
+ "examples/uniref50.fa", DataSourceType.FILE);
+ AlignViewport av = af.getViewport();
+ SequenceGroup sg1 = new SequenceGroup();
+ SequenceGroup sg2 = new SequenceGroup();
+
+ av.setSelectionGroup(sg1);
+ assertSame(sg1.getContext(), av.getAlignment()); // context set
+
+ sg2.setContext(sg1);
+ av.setSelectionGroup(sg2);
+ assertSame(sg2.getContext(), sg1); // unchanged
+ }
}