Index: Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs =================================================================== diff -u -ra8bfedc443289dd37ebd3c2304d4c4add4ef7d58 -r5ce4ce33303962b5b3966b37c040d3c613fae1d4 --- Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision a8bfedc443289dd37ebd3c2304d4c4add4ef7d58) +++ Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision 5ce4ce33303962b5b3966b37c040d3c613fae1d4) @@ -44,13 +44,15 @@ /// /// The view which shows the data that is added to a . /// - public sealed partial class MapLegendView : UserControl, IView + public sealed partial class MapLegendView : UserControl, ISelectionProvider { private static readonly ILog log = LogManager.GetLogger(typeof(MapLegendView)); private readonly IContextMenuBuilderProvider contextMenuBuilderProvider; private readonly IWin32Window parentWindow; + public event EventHandler SelectionChanged; + /// /// Creates a new instance of . /// @@ -74,6 +76,8 @@ Text = MapResources.General_Map; RegisterTreeNodeInfos(); + + treeViewControl.SelectedDataChanged += TreeViewControlSelectedDataChanged; } public object Data @@ -88,6 +92,22 @@ } } + public object Selection + { + get + { + return treeViewControl.SelectedData; + } + } + + private void TreeViewControlSelectedDataChanged(object sender, EventArgs e) + { + if (SelectionChanged != null) + { + SelectionChanged(this, new EventArgs()); + } + } + private void RegisterTreeNodeInfos() { treeViewControl.RegisterTreeNodeInfo(new TreeNodeInfo @@ -200,7 +220,7 @@ } } - private void CheckDataFormat(string filePath, string title, MapDataCollection mapDataCollection) + private static void CheckDataFormat(string filePath, string title, MapDataCollection mapDataCollection) { try { @@ -271,7 +291,7 @@ } } - private FeatureBasedMapData GetShapeFileData(ShapeFileReaderBase reader, string title) + private static FeatureBasedMapData GetShapeFileData(ShapeFileReaderBase reader, string title) { return reader.ReadShapeFile(title); } Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapLegendViewTest.cs =================================================================== diff -u -rce31448a066c084f755439f3e7d453bfb042b291 -r5ce4ce33303962b5b3966b37c040d3c613fae1d4 --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapLegendViewTest.cs (.../MapLegendViewTest.cs) (revision ce31448a066c084f755439f3e7d453bfb042b291) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapLegendViewTest.cs (.../MapLegendViewTest.cs) (revision 5ce4ce33303962b5b3966b37c040d3c613fae1d4) @@ -205,6 +205,66 @@ } } + [Test] + [RequiresSTA] + public void Selection_Always_ReturnsSelectedNodeData() + { + // Setup + var mapData = new MapLineData("line data"); + var mapDataCollection = new MapDataCollection("collection"); + + mapDataCollection.Add(mapData); + + using (var view = new MapLegendView(contextMenuBuilderProvider, parentWindow) + { + Data = mapDataCollection + }) + { + var treeViewControl = TypeUtils.GetField(view, "treeViewControl"); + + WindowsFormsTestHelper.Show(treeViewControl); + treeViewControl.TrySelectNodeForData(mapData); + + // Call + var selection = view.Selection; + + // Assert + Assert.AreSame(mapData, selection); + } + WindowsFormsTestHelper.CloseAll(); + } + + [Test] + [RequiresSTA] + public void TreeViewSelectedNodeChanged_Always_SelectionChangedFired() + { + // Setup + var mapData = new MapLineData("line data"); + var mapDataCollection = new MapDataCollection("collection"); + + mapDataCollection.Add(mapData); + + using (var view = new MapLegendView(contextMenuBuilderProvider, parentWindow) + { + Data = mapDataCollection + }) + { + var treeViewControl = TypeUtils.GetField(view, "treeViewControl"); + + WindowsFormsTestHelper.Show(treeViewControl); + + var selectionChangedCount = 0; + view.SelectionChanged += (sender, args) => selectionChangedCount++; + + // Call + treeViewControl.TrySelectNodeForData(mapData); + + // Assert + Assert.AreEqual(1, selectionChangedCount); + } + WindowsFormsTestHelper.CloseAll(); + } + private static MapFeature[] CreateFeatures() { return new[]