Index: Core/Gui/src/Core.Gui/Core.Gui.csproj =================================================================== diff -u -r98da4d6cd59cac814ec00c54b22db4dc74b7eed0 -rf869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e --- Core/Gui/src/Core.Gui/Core.Gui.csproj (.../Core.Gui.csproj) (revision 98da4d6cd59cac814ec00c54b22db4dc74b7eed0) +++ Core/Gui/src/Core.Gui/Core.Gui.csproj (.../Core.Gui.csproj) (revision f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e) @@ -123,6 +123,9 @@ UserControl + + UserControl + @@ -135,6 +138,7 @@ + Index: Core/Gui/src/Core.Gui/Forms/Chart/ChartLegendView.Designer.cs =================================================================== diff -u --- Core/Gui/src/Core.Gui/Forms/Chart/ChartLegendView.Designer.cs (revision 0) +++ Core/Gui/src/Core.Gui/Forms/Chart/ChartLegendView.Designer.cs (revision f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e) @@ -0,0 +1,78 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using Core.Common.Controls.TreeView; + +namespace Core.Gui.Forms.Chart +{ + partial class ChartLegendView + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ChartLegendView)); + this.treeViewControl = new TreeViewControl(); + this.SuspendLayout(); + // + // treeViewControl + // + resources.ApplyResources(this.treeViewControl, "treeViewControl"); + this.treeViewControl.Name = "treeViewControl"; + // + // ChartLegendView + // + resources.ApplyResources(this, "$this"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.treeViewControl); + this.Name = "ChartLegendView"; + this.ResumeLayout(false); + + } + + #endregion + + private TreeViewControl treeViewControl; + } +} \ No newline at end of file Index: Core/Gui/src/Core.Gui/Forms/Chart/ChartLegendView.cs =================================================================== diff -u --- Core/Gui/src/Core.Gui/Forms/Chart/ChartLegendView.cs (revision 0) +++ Core/Gui/src/Core.Gui/Forms/Chart/ChartLegendView.cs (revision f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e) @@ -0,0 +1,319 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Drawing; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Controls.TreeView; +using Core.Common.Controls.Views; +using Core.Components.Chart.Data; +using Core.Components.Chart.Forms; +using Core.Gui.ContextMenu; +using Core.Gui.PresentationObjects.Chart; +using GuiResources = Core.Gui.Properties.Resources; + +namespace Core.Gui.Forms.Chart +{ + /// + /// This class defines a view which shows the data that have been added to a . + /// + public sealed partial class ChartLegendView : UserControl, ISelectionProvider, IView + { + private readonly IContextMenuBuilderProvider contextMenuBuilderProvider; + private IChartControl chartControl; + + public event EventHandler SelectionChanged; + + /// + /// Creates a new instance of . + /// + /// The to create context menus. + /// Thrown when is null. + public ChartLegendView(IContextMenuBuilderProvider contextMenuBuilderProvider) + { + if (contextMenuBuilderProvider == null) + { + throw new ArgumentNullException(nameof(contextMenuBuilderProvider), + $@"Cannot create a {typeof(ChartLegendView).Name} when the context menu builder provider is null."); + } + + this.contextMenuBuilderProvider = contextMenuBuilderProvider; + InitializeComponent(); + Text = GuiResources.ChartLegendView_Chart_DisplayName; + + RegisterTreeNodeInfos(); + + treeViewControl.SelectedDataChanged += TreeViewControlSelectedDataChanged; + } + + public IChartControl ChartControl + { + private get + { + return chartControl; + } + set + { + chartControl = value; + Data = value?.Data; + } + } + + public object Selection + { + get + { + var chartDataContext = treeViewControl.SelectedData as ChartDataContext; + if (chartDataContext != null) + { + return chartDataContext.WrappedData; + } + + return treeViewControl.SelectedData; + } + } + + public object Data + { + get + { + return (ChartData) treeViewControl.Data; + } + set + { + treeViewControl.Data = (ChartData) value; + } + } + + private void RegisterTreeNodeInfos() + { + treeViewControl.RegisterTreeNodeInfo(new TreeNodeInfo + { + Text = context => context.WrappedData.Name, + Image = GetImage, + ChildNodeObjects = ChartDataContextGetChildNodeObjects, + CanDrag = (context, o) => !(context.WrappedData is ChartMultipleAreaData), + CanCheck = context => !(context.WrappedData is ChartDataCollection), + CheckedState = context => context.WrappedData.IsVisible ? TreeNodeCheckedState.Checked : TreeNodeCheckedState.Unchecked, + OnNodeChecked = ChartDataContextOnNodeChecked, + CanDrop = ChartDataContextCanDropAndInsert, + CanInsert = ChartDataContextCanDropAndInsert, + OnDrop = ChartDataContextOnDrop, + ContextMenuStrip = (nodeData, parentData, treeView) => contextMenuBuilderProvider.Get(nodeData.WrappedData, treeView) + .AddCustomItem(CreateZoomToExtentsItem(nodeData.WrappedData)) + .AddSeparator() + .AddPropertiesItem() + .Build() + }); + + treeViewControl.RegisterTreeNodeInfo(new TreeNodeInfo + { + Text = collection => collection.Name, + Image = collection => GuiResources.folder, + ChildNodeObjects = GetCollectionChildNodeObjects, + CanDrag = (collection, parentData) => true, + CanDrop = ChartDataCollectionCanDropAndInsert, + CanInsert = ChartDataCollectionCanDropAndInsert, + OnDrop = ChartDataCollectionOnDrop, + ContextMenuStrip = (nodeData, parentData, treeView) => contextMenuBuilderProvider.Get(nodeData, treeView) + .AddCustomItem(CreateZoomToExtentsItem(nodeData)) + .AddSeparator() + .AddPropertiesItem() + .Build() + }); + } + + private StrictContextMenuItem CreateZoomToExtentsItem(ChartData nodeData) + { + bool hasData = nodeData.HasData; + bool enabled = nodeData.IsVisible && hasData; + string toolTip; + + if (nodeData.IsVisible) + { + toolTip = hasData + ? GuiResources.ChartLegendView_CreateZoomToExtentsItem_ZoomToAll_Tooltip + : GuiResources.ChartLegendView_CreateZoomToExtentsItem_NoData_ZoomToAllDisabled_Tooltip; + } + else + { + toolTip = GuiResources.ChartLegendView_CreateZoomToExtentsItem_ZoomToAllDisabled_Tooltip; + } + + return CreateZoomToExtentsItem(nodeData, toolTip, enabled); + } + + private StrictContextMenuItem CreateZoomToExtentsItem(ChartData nodeData, string toolTip, bool isEnabled) + { + return new StrictContextMenuItem($"&{GuiResources.ZoomToAll_DisplayName}", + toolTip, + GuiResources.ZoomToAllIcon, + (sender, args) => ChartControl?.ZoomToVisibleSeries(nodeData)) + { + Enabled = isEnabled + }; + } + + private StrictContextMenuItem CreateZoomToExtentsItem(ChartDataCollection nodeData) + { + ChartData[] chartDatas = nodeData.GetChartDataRecursively().ToArray(); + var isVisible = false; + var hasData = false; + foreach (ChartData chartData in chartDatas) + { + if (chartData.IsVisible) + { + isVisible = true; + + if (chartData.HasData) + { + hasData = true; + break; + } + } + } + + bool enabled = isVisible && hasData; + + string toolTip; + + if (isVisible) + { + toolTip = hasData + ? GuiResources.ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_ZoomToAll_Tooltip + : GuiResources.ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_NoData_ZoomToAllDisabled_Tooltip; + } + else + { + toolTip = GuiResources.ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_ZoomToAllDisabled_Tooltip; + } + + return CreateZoomToExtentsItem(nodeData, toolTip, enabled); + } + + private static object[] GetChildNodeObjects(ChartDataCollection chartDataCollection) + { + return chartDataCollection.Collection.Reverse().Select(chartData => new ChartDataContext(chartData, chartDataCollection)).Cast().ToArray(); + } + + private void NotifyObserversOfData(ChartData chartData) + { + chartData.NotifyObservers(); + + var observableParent = Data as IObservable; + observableParent?.NotifyObservers(); + } + + private void TreeViewControlSelectedDataChanged(object sender, EventArgs e) + { + SelectionChanged?.Invoke(this, new EventArgs()); + } + + #region ChartDataContext + + private static Image GetImage(ChartDataContext context) + { + if (context.WrappedData is ChartPointData) + { + return GuiResources.PointsIcon; + } + + if (context.WrappedData is ChartLineData || context.WrappedData is ChartMultipleLineData) + { + return GuiResources.LineIcon; + } + + if (context.WrappedData is ChartAreaData || context.WrappedData is ChartMultipleAreaData) + { + return GuiResources.AreaIcon; + } + + return GuiResources.folder; + } + + private static object[] ChartDataContextGetChildNodeObjects(ChartDataContext chartDataContext) + { + var collection = chartDataContext.WrappedData as ChartDataCollection; + return collection != null ? GetChildNodeObjects(collection) : new object[0]; + } + + private void ChartDataContextOnNodeChecked(ChartDataContext chartDataContext, object parentData) + { + chartDataContext.WrappedData.IsVisible = !chartDataContext.WrappedData.IsVisible; + NotifyObserversOfData(chartDataContext.WrappedData); + } + + private static bool ChartDataContextCanDropAndInsert(object draggedData, object targetData) + { + var draggedDataContext = (ChartDataContext) draggedData; + var targetDataContext = (ChartDataContext) targetData; + + return draggedDataContext.ParentChartData.Equals(targetDataContext.WrappedData); + } + + private static void ChartDataContextOnDrop(object droppedData, object newParentData, object oldParentData, int position, TreeViewControl control) + { + var chartContext = (ChartDataContext) droppedData; + var sourceContext = oldParentData as ChartDataContext; + + ChartData chartData = chartContext.WrappedData; + var parent = (ChartDataCollection) (sourceContext != null ? sourceContext.WrappedData : oldParentData); + + parent.Remove(chartData); + parent.Insert(parent.Collection.Count() - position, chartData); + parent.NotifyObservers(); + } + + #endregion + + #region ChartDataCollection + + private static object[] GetCollectionChildNodeObjects(ChartDataCollection chartDataCollection) + { + return GetChildNodeObjects(chartDataCollection); + } + + private static bool ChartDataCollectionCanDropAndInsert(object draggedData, object targetData) + { + var draggedDataContext = (ChartDataContext) draggedData; + var targetDataContext = targetData as ChartDataContext; + object targetDataObject = targetDataContext != null ? targetDataContext.ParentChartData : targetData; + + return draggedDataContext.ParentChartData.Equals(targetDataObject); + } + + private static void ChartDataCollectionOnDrop(object droppedData, object newParentData, object oldParentData, int position, TreeViewControl control) + { + var chartContext = (ChartDataContext) droppedData; + + ChartData chartData = chartContext.WrappedData; + var parent = (ChartDataCollection) oldParentData; + + parent.Remove(chartData); + parent.Insert(parent.Collection.Count() - position, chartData); + parent.NotifyObservers(); + } + + #endregion + } +} \ No newline at end of file Index: Core/Gui/src/Core.Gui/Forms/Chart/ChartLegendView.resx =================================================================== diff -u --- Core/Gui/src/Core.Gui/Forms/Chart/ChartLegendView.resx (revision 0) +++ Core/Gui/src/Core.Gui/Forms/Chart/ChartLegendView.resx (revision f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e) @@ -0,0 +1,168 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + Fill + + + + 0 + + + + 0, 0 + + + 0 + + + 228, 412 + + + 2 + + + treeViewControl + + + Core.Plugins.Chart.Legend.LegendTreeView, Core.Plugins.Chart, Version=0.5.0.1876, Culture=neutral, PublicKeyToken=null + + + $this + + + 0 + + + True + + + 6, 13 + + + 228, 412 + + + ChartLegendView + + + System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file Index: Core/Gui/src/Core.Gui/Forms/Map/MapLegendView.cs =================================================================== diff -u -re25cbbd88e41c07ec5be2ba2f686f2e85e0f3706 -rf869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e --- Core/Gui/src/Core.Gui/Forms/Map/MapLegendView.cs (.../MapLegendView.cs) (revision e25cbbd88e41c07ec5be2ba2f686f2e85e0f3706) +++ Core/Gui/src/Core.Gui/Forms/Map/MapLegendView.cs (.../MapLegendView.cs) (revision f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e) @@ -211,7 +211,7 @@ private StrictContextMenuItem CreateZoomToExtentsItem(MapData nodeData, string toolTip, bool isEnabled) { - return new StrictContextMenuItem($"&{GuiResources.MapLegendView_CreateZoomToExtentsItem_ZoomToAll_DisplayName}", + return new StrictContextMenuItem($"&{GuiResources.ZoomToAll_DisplayName}", toolTip, GuiResources.ZoomToAllIcon, (sender, args) => MapControl?.ZoomToVisibleLayers(nodeData)) Index: Core/Gui/src/Core.Gui/Properties/Resources.Designer.cs =================================================================== diff -u -rb916044feb97e49547eec26fa1b1954e740b879d -rf869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e --- Core/Gui/src/Core.Gui/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b916044feb97e49547eec26fa1b1954e740b879d) +++ Core/Gui/src/Core.Gui/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e) @@ -311,6 +311,71 @@ } /// + /// Looks up a localized string similar to Grafiek. + /// + public static string ChartLegendView_Chart_DisplayName { + get { + return ResourceManager.GetString("ChartLegendView_Chart_DisplayName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Om het zoomniveau aan te passen moet minstens één van de zichtbare gegevensreeksen in deze map met gegevensreeksen elementen bevatten.. + /// + public static string ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_NoData_ZoomToAllDisabled_Tooltip { + get { + return ResourceManager.GetString("ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_NoData_ZoomToAllDisab" + + "led_Tooltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Zet het zoomniveau van de grafiek dusdanig dat alle zichtbare gegevensreeksen in deze map met gegevensreeksen precies in het beeld passen.. + /// + public static string ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_ZoomToAll_Tooltip { + get { + return ResourceManager.GetString("ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_ZoomToAll_Tooltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Om het zoomniveau aan te passen moet er minstens één gegevensreeks in deze map met gegevensreeksen zichtbaar zijn.. + /// + public static string ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_ZoomToAllDisabled_Tooltip { + get { + return ResourceManager.GetString("ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_ZoomToAllDisabled_Too" + + "ltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Om het zoomniveau aan te passen moet de gegevensreeks elementen bevatten.. + /// + public static string ChartLegendView_CreateZoomToExtentsItem_NoData_ZoomToAllDisabled_Tooltip { + get { + return ResourceManager.GetString("ChartLegendView_CreateZoomToExtentsItem_NoData_ZoomToAllDisabled_Tooltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Zet het zoomniveau van de grafiek dusdanig dat deze gegevensreeks precies in het beeld past.. + /// + public static string ChartLegendView_CreateZoomToExtentsItem_ZoomToAll_Tooltip { + get { + return ResourceManager.GetString("ChartLegendView_CreateZoomToExtentsItem_ZoomToAll_Tooltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Om het zoomniveau aan te passen moet de gegevensreeks zichtbaar zijn.. + /// + public static string ChartLegendView_CreateZoomToExtentsItem_ZoomToAllDisabled_Tooltip { + get { + return ResourceManager.GetString("ChartLegendView_CreateZoomToExtentsItem_ZoomToAllDisabled_Tooltip", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Alles i&nklappen. /// public static string Collapse_all { @@ -1411,15 +1476,6 @@ } /// - /// Looks up a localized string similar to Zoom naar alles. - /// - public static string MapLegendView_CreateZoomToExtentsItem_ZoomToAll_DisplayName { - get { - return ResourceManager.GetString("MapLegendView_CreateZoomToExtentsItem_ZoomToAll_DisplayName", resourceCulture); - } - } - - /// /// Looks up a localized string similar to Zet het zoomniveau van de kaart dusdanig dat deze kaartlaag precies in het beeld past.. /// public static string MapLegendView_CreateZoomToExtentsItem_ZoomToAll_Tooltip { @@ -2270,6 +2326,15 @@ } /// + /// Looks up a localized string similar to Zoom naar alles. + /// + public static string ZoomToAll_DisplayName { + get { + return ResourceManager.GetString("ZoomToAll_DisplayName", resourceCulture); + } + } + + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// public static System.Drawing.Bitmap ZoomToAllIcon { Index: Core/Gui/src/Core.Gui/Properties/Resources.resx =================================================================== diff -u -rb916044feb97e49547eec26fa1b1954e740b879d -rf869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e --- Core/Gui/src/Core.Gui/Properties/Resources.resx (.../Resources.resx) (revision b916044feb97e49547eec26fa1b1954e740b879d) +++ Core/Gui/src/Core.Gui/Properties/Resources.resx (.../Resources.resx) (revision f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e) @@ -634,7 +634,7 @@ Open het kaartenpaneel. - + Zoom naar alles @@ -832,4 +832,25 @@ Kaartlaag + + Om het zoomniveau aan te passen moet minstens één van de zichtbare gegevensreeksen in deze map met gegevensreeksen elementen bevatten. + + + Om het zoomniveau aan te passen moet er minstens één gegevensreeks in deze map met gegevensreeksen zichtbaar zijn. + + + Zet het zoomniveau van de grafiek dusdanig dat alle zichtbare gegevensreeksen in deze map met gegevensreeksen precies in het beeld passen. + + + Om het zoomniveau aan te passen moet de gegevensreeks elementen bevatten. + + + Om het zoomniveau aan te passen moet de gegevensreeks zichtbaar zijn. + + + Zet het zoomniveau van de grafiek dusdanig dat deze gegevensreeks precies in het beeld past. + + + Grafiek + \ No newline at end of file Index: Core/Gui/test/Core.Gui.Test/Forms/Chart/ChartLegendViewTest.cs =================================================================== diff -u --- Core/Gui/test/Core.Gui.Test/Forms/Chart/ChartLegendViewTest.cs (revision 0) +++ Core/Gui/test/Core.Gui.Test/Forms/Chart/ChartLegendViewTest.cs (revision f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e) @@ -0,0 +1,319 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Windows.Forms; +using Core.Common.Controls.TreeView; +using Core.Common.Controls.Views; +using Core.Common.TestUtil; +using Core.Common.Util.Reflection; +using Core.Components.Chart.Data; +using Core.Components.Chart.TestUtil; +using Core.Gui.ContextMenu; +using Core.Gui.Forms.Chart; +using Core.Gui.PresentationObjects.Chart; +using NUnit.Framework; +using Rhino.Mocks; + +namespace Core.Gui.Test.Forms.Chart +{ + [TestFixture] + public class ChartLegendViewTest + { + [Test] + public void Constructor_WithoutContextMenuBuilderProvider_CreatesUserControl() + { + // Call + var exception = Assert.Throws(() => new ChartLegendView(null)); + + // Assert + Assert.AreEqual("contextMenuBuilderProvider", exception.ParamName); + } + + [Test] + public void Constructor_WithBuilderProvider_CreatesUserControl() + { + // Setup + var mocks = new MockRepository(); + var menuBuilderProvider = mocks.Stub(); + mocks.ReplayAll(); + + // Call + using (var view = new ChartLegendView(menuBuilderProvider)) + { + // Assert + Assert.IsInstanceOf(view); + Assert.IsInstanceOf(view); + Assert.IsInstanceOf(view); + Assert.IsNull(view.Data); + Assert.AreEqual("Grafiek", view.Text); + } + + mocks.VerifyAll(); + } + + [Test] + public void Data_ChartDataCollection_DataSet() + { + // Setup + var mocks = new MockRepository(); + var menuBuilderProvider = mocks.Stub(); + mocks.ReplayAll(); + + using (var view = new ChartLegendView(menuBuilderProvider)) + { + var chartDataCollection = new ChartDataCollection("test data"); + + // Call + view.Data = chartDataCollection; + + // Assert + Assert.AreSame(chartDataCollection, view.Data); + } + + mocks.VerifyAll(); + } + + [Test] + public void Data_ForNull_NullSet() + { + // Setup + var mocks = new MockRepository(); + var menuBuilderProvider = mocks.Stub(); + mocks.ReplayAll(); + + using (var view = new ChartLegendView(menuBuilderProvider)) + { + // Call + view.Data = null; + + // Assert + Assert.IsNull(view.Data); + } + + mocks.VerifyAll(); + } + + [Test] + public void Data_OtherObject_ThrowsInvalidCastException() + { + // Setup + var mocks = new MockRepository(); + var menuBuilderProvider = mocks.Stub(); + mocks.ReplayAll(); + + using (var view = new ChartLegendView(menuBuilderProvider)) + { + // Call + TestDelegate test = () => view.Data = new object(); + + // Assert + Assert.Throws(test); + } + + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void Selection_NestedNodeData_ReturnsWrappedObjectData() + { + // Setup + var mocks = new MockRepository(); + var contextMenuBuilderProvider = mocks.Stub(); + mocks.ReplayAll(); + + ChartData chartData = CreateChartData(); + var chartDataCollection = new ChartDataCollection("collection"); + chartDataCollection.Add(chartData); + + using (var view = new ChartLegendView(contextMenuBuilderProvider) + { + Data = chartDataCollection + }) + { + var context = new ChartDataContext(chartData, chartDataCollection); + + var treeViewControl = TypeUtils.GetField(view, "treeViewControl"); + WindowsFormsTestHelper.Show(treeViewControl); + treeViewControl.TrySelectNodeForData(context); + + // Call + object selection = view.Selection; + + // Assert + Assert.AreSame(chartData, selection); + } + + WindowsFormsTestHelper.CloseAll(); + + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void Selection_RootNodeData_ReturnsObjectData() + { + // Setup + var mocks = new MockRepository(); + var contextMenuBuilderProvider = mocks.Stub(); + mocks.ReplayAll(); + + ChartData chartData = CreateChartData(); + var chartDataCollection = new ChartDataCollection("collection"); + chartDataCollection.Add(chartData); + + using (var view = new ChartLegendView(contextMenuBuilderProvider) + { + Data = chartDataCollection + }) + { + var treeViewControl = TypeUtils.GetField(view, "treeViewControl"); + WindowsFormsTestHelper.Show(treeViewControl); + treeViewControl.TrySelectNodeForData(chartDataCollection); + + // Call + object selection = view.Selection; + + // Assert + Assert.AreSame(chartDataCollection, selection); + } + + WindowsFormsTestHelper.CloseAll(); + + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenChartLegendView_WhenSelectedNodeChanged_SelectionChangedFired() + { + // Given + ChartData chartData = CreateChartData(); + var chartDataCollection = new ChartDataCollection("collection"); + chartDataCollection.Add(chartData); + + var mocks = new MockRepository(); + var contextMenuBuilderProvider = mocks.Stub(); + mocks.ReplayAll(); + + using (var view = new ChartLegendView(contextMenuBuilderProvider) + { + Data = chartDataCollection + }) + { + var treeViewControl = TypeUtils.GetField(view, "treeViewControl"); + WindowsFormsTestHelper.Show(treeViewControl); + + var selectionChangedCount = 0; + view.SelectionChanged += (sender, args) => selectionChangedCount++; + + // When + var context = new ChartDataContext(chartData, chartDataCollection); + treeViewControl.TrySelectNodeForData(context); + + // Then + Assert.AreEqual(1, selectionChangedCount); + } + + WindowsFormsTestHelper.CloseAll(); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenChartLegendView_WhenSettingData_SelectionChangedFired() + { + // Given + var mocks = new MockRepository(); + var contextMenuBuilderProvider = mocks.Stub(); + mocks.ReplayAll(); + + using (var view = new ChartLegendView(contextMenuBuilderProvider) + { + Data = new ChartDataCollection("collection") + }) + { + var treeViewControl = TypeUtils.GetField(view, "treeViewControl"); + WindowsFormsTestHelper.Show(treeViewControl); + + var selectionChangedCount = 0; + view.SelectionChanged += (sender, args) => selectionChangedCount++; + + // When + view.Data = new ChartDataCollection("collection"); + + // Then + Assert.AreEqual(1, selectionChangedCount); + } + + WindowsFormsTestHelper.CloseAll(); + mocks.VerifyAll(); + } + + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public void GivenChartDataContainingCollection_WhenDragDroppingFromRootToRoot_ThenDataPositionChanged(int index) + { + // Given + var mocks = new MockRepository(); + var menuBuilderProvider = mocks.Stub(); + mocks.ReplayAll(); + + ChartData chartData = CreateChartData(); + var rootCollection = new ChartDataCollection("test data"); + + rootCollection.Add(chartData); + rootCollection.Add(CreateChartData()); + rootCollection.Add(CreateChartData()); + + using (var chartLegendView = new ChartLegendView(menuBuilderProvider) + { + Data = rootCollection + }) + { + var treeViewControl = TypeUtils.GetField(chartLegendView, "treeViewControl"); + var treeNodeInfoLookup = TypeUtils.GetField>(treeViewControl, "tagTypeTreeNodeInfoLookup"); + TreeNodeInfo info = treeNodeInfoLookup[typeof(ChartDataCollection)]; + + var context = new ChartDataContext(chartData, rootCollection); + + // When + info.OnDrop(context, rootCollection, rootCollection, index, treeViewControl); + + // Then + Assert.AreEqual(2 - index, rootCollection.Collection.ToList().IndexOf(chartData)); + } + + mocks.VerifyAll(); + } + + private static ChartData CreateChartData() + { + return new TestChartData("some name"); + } + } +} \ No newline at end of file Index: Core/Plugins/src/Core.Plugins.Chart/Commands/ToggleLegendViewCommand.cs =================================================================== diff -u -rcbde09a1860a8a4480b958d6671de3480b995886 -rf869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e --- Core/Plugins/src/Core.Plugins.Chart/Commands/ToggleLegendViewCommand.cs (.../ToggleLegendViewCommand.cs) (revision cbde09a1860a8a4480b958d6671de3480b995886) +++ Core/Plugins/src/Core.Plugins.Chart/Commands/ToggleLegendViewCommand.cs (.../ToggleLegendViewCommand.cs) (revision f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e) @@ -20,6 +20,7 @@ // All rights reserved. using Core.Common.Controls.Commands; +using Core.Gui.Forms.Chart; using Core.Plugins.Chart.Legend; namespace Core.Plugins.Chart.Commands Index: Core/Plugins/src/Core.Plugins.Chart/Legend/ChartLegendController.cs =================================================================== diff -u -rab3938a73513858354f1240bb86c0098f930ef3d -rf869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e --- Core/Plugins/src/Core.Plugins.Chart/Legend/ChartLegendController.cs (.../ChartLegendController.cs) (revision ab3938a73513858354f1240bb86c0098f930ef3d) +++ Core/Plugins/src/Core.Plugins.Chart/Legend/ChartLegendController.cs (.../ChartLegendController.cs) (revision f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e) @@ -24,6 +24,7 @@ using Core.Components.Chart.Forms; using Core.Gui; using Core.Gui.ContextMenu; +using Core.Gui.Forms.Chart; using Core.Gui.Forms.ViewHost; using Core.Plugins.Chart.Properties; Fisheye: Tag f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e refers to a dead (removed) revision in file `Core/Plugins/src/Core.Plugins.Chart/Legend/ChartLegendView.Designer.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e refers to a dead (removed) revision in file `Core/Plugins/src/Core.Plugins.Chart/Legend/ChartLegendView.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e refers to a dead (removed) revision in file `Core/Plugins/src/Core.Plugins.Chart/Legend/ChartLegendView.resx'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Plugins/src/Core.Plugins.Chart/Properties/Resources.Designer.cs =================================================================== diff -u -rff5e93978092e3cd883d3eb366558a3ee9ea39c5 -rf869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e --- Core/Plugins/src/Core.Plugins.Chart/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision ff5e93978092e3cd883d3eb366558a3ee9ea39c5) +++ Core/Plugins/src/Core.Plugins.Chart/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e) @@ -1,25 +1,4 @@ -// Copyright (C) Stichting Deltares 2021. All rights reserved. -// -// This file is part of Riskeer. -// -// Riskeer is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see . -// -// All names, logos, and references to "Deltares" are registered trademarks of -// Stichting Deltares and remain full property of Stichting Deltares at all times. -// All rights reserved. - -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.42000 @@ -255,62 +234,6 @@ } /// - /// Looks up a localized string similar to Om het zoomniveau aan te passen moet minstens één van de zichtbare gegevensreeksen in deze map met gegevensreeksen elementen bevatten.. - /// - public static string ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_NoData_ZoomToAllDisabled_Tooltip { - get { - return ResourceManager.GetString("ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_NoData_ZoomToAllDisab" + - "led_Tooltip", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Zet het zoomniveau van de grafiek dusdanig dat alle zichtbare gegevensreeksen in deze map met gegevensreeksen precies in het beeld passen.. - /// - public static string ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_ZoomToAll_Tooltip { - get { - return ResourceManager.GetString("ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_ZoomToAll_Tooltip", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Om het zoomniveau aan te passen moet er minstens één gegevensreeks in deze map met gegevensreeksen zichtbaar zijn.. - /// - public static string ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_ZoomToAllDisabled_Tooltip { - get { - return ResourceManager.GetString("ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_ZoomToAllDisabled_Too" + - "ltip", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Om het zoomniveau aan te passen moet de gegevensreeks elementen bevatten.. - /// - public static string ChartLegendView_CreateZoomToExtentsItem_NoData_ZoomToAllDisabled_Tooltip { - get { - return ResourceManager.GetString("ChartLegendView_CreateZoomToExtentsItem_NoData_ZoomToAllDisabled_Tooltip", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Zet het zoomniveau van de grafiek dusdanig dat deze gegevensreeks precies in het beeld past.. - /// - public static string ChartLegendView_CreateZoomToExtentsItem_ZoomToAll_Tooltip { - get { - return ResourceManager.GetString("ChartLegendView_CreateZoomToExtentsItem_ZoomToAll_Tooltip", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Om het zoomniveau aan te passen moet de gegevensreeks zichtbaar zijn.. - /// - public static string ChartLegendView_CreateZoomToExtentsItem_ZoomToAllDisabled_Tooltip { - get { - return ResourceManager.GetString("ChartLegendView_CreateZoomToExtentsItem_ZoomToAllDisabled_Tooltip", resourceCulture); - } - } - - /// /// Looks up a localized string similar to De kleur van de lijnen waarmee deze gegevensreeks wordt weergegeven.. /// public static string ChartLineData_Color_Description { @@ -410,15 +333,6 @@ } /// - /// Looks up a localized string similar to Grafiek. - /// - public static string General_Chart { - get { - return ResourceManager.GetString("General_Chart", resourceCulture); - } - } - - /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// public static System.Drawing.Bitmap LineIcon { @@ -457,15 +371,6 @@ } /// - /// Looks up a localized string similar to Zoom naar alles. - /// - public static string Ribbon_ZoomToAll { - get { - return ResourceManager.GetString("Ribbon_ZoomToAll", resourceCulture); - } - } - - /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// public static System.Drawing.Bitmap ZoomToAllIcon { Index: Core/Plugins/src/Core.Plugins.Chart/Properties/Resources.resx =================================================================== diff -u -rff5e93978092e3cd883d3eb366558a3ee9ea39c5 -rf869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e --- Core/Plugins/src/Core.Plugins.Chart/Properties/Resources.resx (.../Resources.resx) (revision ff5e93978092e3cd883d3eb366558a3ee9ea39c5) +++ Core/Plugins/src/Core.Plugins.Chart/Properties/Resources.resx (.../Resources.resx) (revision f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e) @@ -124,9 +124,6 @@ ..\resources\chart.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - Grafiek - ..\resources\line.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -139,30 +136,9 @@ Open het grafiekenpaneel. - - Zoom naar alles - ..\resources\zoomextents.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - Zet het zoomniveau van de grafiek dusdanig dat deze gegevensreeks precies in het beeld past. - - - Om het zoomniveau aan te passen moet de gegevensreeks elementen bevatten. - - - Om het zoomniveau aan te passen moet de gegevensreeks zichtbaar zijn. - - - Om het zoomniveau aan te passen moet minstens één van de zichtbare gegevensreeksen in deze map met gegevensreeksen elementen bevatten. - - - Om het zoomniveau aan te passen moet er minstens één gegevensreeks in deze map met gegevensreeksen zichtbaar zijn. - - - Zet het zoomniveau van de grafiek dusdanig dat alle zichtbare gegevensreeksen in deze map met gegevensreeksen precies in het beeld passen. - Algemeen Index: Core/Plugins/test/Core.Plugins.Chart.Test/ChartPluginTest.cs =================================================================== diff -u -rab3938a73513858354f1240bb86c0098f930ef3d -rf869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e --- Core/Plugins/test/Core.Plugins.Chart.Test/ChartPluginTest.cs (.../ChartPluginTest.cs) (revision ab3938a73513858354f1240bb86c0098f930ef3d) +++ Core/Plugins/test/Core.Plugins.Chart.Test/ChartPluginTest.cs (.../ChartPluginTest.cs) (revision f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e) @@ -29,6 +29,7 @@ using Core.Components.Chart.Data; using Core.Components.Chart.Forms; using Core.Gui; +using Core.Gui.Forms.Chart; using Core.Gui.Forms.MainWindow; using Core.Gui.Forms.ViewHost; using Core.Gui.Plugin; Index: Core/Plugins/test/Core.Plugins.Chart.Test/Commands/ToggleLegendViewCommandTest.cs =================================================================== diff -u -rab3938a73513858354f1240bb86c0098f930ef3d -rf869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e --- Core/Plugins/test/Core.Plugins.Chart.Test/Commands/ToggleLegendViewCommandTest.cs (.../ToggleLegendViewCommandTest.cs) (revision ab3938a73513858354f1240bb86c0098f930ef3d) +++ Core/Plugins/test/Core.Plugins.Chart.Test/Commands/ToggleLegendViewCommandTest.cs (.../ToggleLegendViewCommandTest.cs) (revision f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e) @@ -24,6 +24,7 @@ using Core.Common.Controls.Views; using Core.Gui; using Core.Gui.ContextMenu; +using Core.Gui.Forms.Chart; using Core.Gui.Forms.ViewHost; using Core.Plugins.Chart.Commands; using Core.Plugins.Chart.Legend; Index: Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataCollectionTreeNodeInfoTest.cs =================================================================== diff -u -r98da4d6cd59cac814ec00c54b22db4dc74b7eed0 -rf869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e --- Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataCollectionTreeNodeInfoTest.cs (.../ChartDataCollectionTreeNodeInfoTest.cs) (revision 98da4d6cd59cac814ec00c54b22db4dc74b7eed0) +++ Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataCollectionTreeNodeInfoTest.cs (.../ChartDataCollectionTreeNodeInfoTest.cs) (revision f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e) @@ -34,6 +34,7 @@ using Core.Components.Chart.Data; using Core.Components.Chart.Forms; using Core.Components.Chart.TestUtil; +using Core.Gui.Forms.Chart; using Core.Gui.PresentationObjects.Chart; using Core.Plugins.Chart.Legend; using Core.Plugins.Chart.Properties; Index: Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataContextTreeNodeInfoTest.cs =================================================================== diff -u -r98da4d6cd59cac814ec00c54b22db4dc74b7eed0 -rf869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e --- Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataContextTreeNodeInfoTest.cs (.../ChartDataContextTreeNodeInfoTest.cs) (revision 98da4d6cd59cac814ec00c54b22db4dc74b7eed0) +++ Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataContextTreeNodeInfoTest.cs (.../ChartDataContextTreeNodeInfoTest.cs) (revision f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e) @@ -34,6 +34,7 @@ using Core.Components.Chart.Data; using Core.Components.Chart.Forms; using Core.Components.Chart.TestUtil; +using Core.Gui.Forms.Chart; using Core.Gui.PresentationObjects.Chart; using Core.Plugins.Chart.Legend; using Core.Plugins.Chart.Properties; Index: Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartLegendControllerTest.cs =================================================================== diff -u -rab3938a73513858354f1240bb86c0098f930ef3d -rf869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e --- Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartLegendControllerTest.cs (.../ChartLegendControllerTest.cs) (revision ab3938a73513858354f1240bb86c0098f930ef3d) +++ Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartLegendControllerTest.cs (.../ChartLegendControllerTest.cs) (revision f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e) @@ -24,6 +24,7 @@ using Core.Common.Controls.Views; using Core.Gui; using Core.Gui.ContextMenu; +using Core.Gui.Forms.Chart; using Core.Gui.Forms.ViewHost; using Core.Plugins.Chart.Legend; using NUnit.Framework; Fisheye: Tag f869d21f23cf0986db9b2b68fd1aa2b9e7d28c9e refers to a dead (removed) revision in file `Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartLegendViewTest.cs'. Fisheye: No comparison available. Pass `N' to diff?