From a25f31a9140c9764baf76ec1c2ede98c1e3e52f9 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 9 Feb 2017 08:41:33 +0000 Subject: [PATCH] JAL-2405 set initial selection group alignment context --- src/jalview/viewmodel/AlignmentViewport.java | 5 +++-- test/jalview/gui/AlignViewportTest.java | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index e5c7b4c..8fa14ae 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -1073,7 +1073,8 @@ public abstract class AlignmentViewport implements AlignViewportI, } /** - * 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 @@ -1083,7 +1084,7 @@ public abstract class AlignmentViewport implements AlignViewportI, public void setSelectionGroup(SequenceGroup sg) { selectionGroup = sg; - if (sg != null) + if (sg != null && sg.getContext() == null) { sg.setContext(alignment); } diff --git a/test/jalview/gui/AlignViewportTest.java b/test/jalview/gui/AlignViewportTest.java index 1cdcdb7..06df70a 100644 --- a/test/jalview/gui/AlignViewportTest.java +++ b/test/jalview/gui/AlignViewportTest.java @@ -38,6 +38,7 @@ import jalview.datamodel.PDBEntry.Type; 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; @@ -382,4 +383,25 @@ public class AlignViewportTest 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 + } } -- 1.7.10.2