Index: Core/Gui/src/Core.Gui/Forms/MainWindow/MainWindow.xaml.cs =================================================================== diff -u -ra5a3c17b09c5cc24e5cfa6d986182fb213bc4cbf -r6be31462252a65cf54edd67c4005f66c944260fe --- Core/Gui/src/Core.Gui/Forms/MainWindow/MainWindow.xaml.cs (.../MainWindow.xaml.cs) (revision a5a3c17b09c5cc24e5cfa6d986182fb213bc4cbf) +++ Core/Gui/src/Core.Gui/Forms/MainWindow/MainWindow.xaml.cs (.../MainWindow.xaml.cs) (revision 6be31462252a65cf54edd67c4005f66c944260fe) @@ -30,6 +30,7 @@ using System.Windows.Media.Imaging; using Core.Common.Controls.Views; using Core.Common.Util.Settings; +using Core.Components.Chart.Forms; using Core.Components.Gis.Forms; using Core.Gui.Commands; using Core.Gui.Forms.Chart; @@ -61,6 +62,7 @@ private PropertyGridView.PropertyGridView propertyGrid; private IMapView currentMapView; + private IChartView currentChartView; /// /// Initializes a new instance of the class. @@ -559,16 +561,23 @@ mapView.Map.ZoomToVisibleLayers(); UpdateComponentsForMapView(mapView); } + + if (e.View is IChartView chartView) + { + UpdateComponentsForChartView(chartView); + } } private void OnViewBroughtToFront(object sender, ViewChangeEventArgs e) { UpdateComponentsForMapView(e.View as IMapView); + UpdateComponentsForChartView(e.View as IChartView); } private void OnActiveDocumentViewChanged(object sender, EventArgs e) { UpdateComponentsForMapView(viewController.ViewHost.ActiveDocumentView as IMapView); + UpdateComponentsForChartView(viewController.ViewHost.ActiveDocumentView as IChartView); } private void OnViewClosed(object sender, ViewChangeEventArgs e) @@ -602,6 +611,11 @@ { UpdateComponentsForMapView(null); } + + if (ReferenceEquals(e.View, currentChartView)) + { + UpdateComponentsForChartView(null); + } } private void UpdateComponentsForMapView(IMapView mapView) @@ -612,10 +626,20 @@ } currentMapView = mapView; - MapLegendView.MapControl = mapView?.Map; } + private void UpdateComponentsForChartView(IChartView chartView) + { + if (ReferenceEquals(currentChartView, chartView)) + { + return; + } + + currentChartView = chartView; + ChartLegendView.ChartControl = chartView?.Chart; + } + #endregion #region Implementation: ISynchronizeInvoke Index: Core/Gui/test/Core.Gui.Test/Forms/MainWindow/MainWindowTest.cs =================================================================== diff -u -ra5a3c17b09c5cc24e5cfa6d986182fb213bc4cbf -r6be31462252a65cf54edd67c4005f66c944260fe --- Core/Gui/test/Core.Gui.Test/Forms/MainWindow/MainWindowTest.cs (.../MainWindowTest.cs) (revision a5a3c17b09c5cc24e5cfa6d986182fb213bc4cbf) +++ Core/Gui/test/Core.Gui.Test/Forms/MainWindow/MainWindowTest.cs (.../MainWindowTest.cs) (revision 6be31462252a65cf54edd67c4005f66c944260fe) @@ -395,7 +395,7 @@ { new TreeNodeInfo() }; - + var mocks = new MockRepository(); var selectedObjectProperties = mocks.Stub(); @@ -413,7 +413,7 @@ gui.Stub(g => g.Project).Return(project); gui.Stub(g => g.GetTreeNodeInfos()).Return(treeNodeInfos); mocks.ReplayAll(); - + gui.Selection = selectedObject; using (var mainWindow = new Gui.Forms.MainWindow.MainWindow()) @@ -426,20 +426,20 @@ // Assert Assert.IsInstanceOf(mainWindow.ProjectExplorer); Assert.AreSame(gui.Project, mainWindow.ProjectExplorer.Data); - + Assert.IsInstanceOf(mainWindow.PropertyGrid); Assert.AreEqual("Eigenschappen", mainWindow.PropertyGrid.Text); Assert.AreEqual(selectedObject, mainWindow.PropertyGrid.Data); Assert.IsInstanceOf(mainWindow.MessageWindow); Assert.AreEqual("Berichten", mainWindow.MessageWindow.Text); - + Assert.IsInstanceOf(mainWindow.MapLegendView); Assert.IsNull(GetMapControl(mainWindow.MapLegendView)); Assert.IsInstanceOf(mainWindow.ChartLegendView); Assert.IsNull(GetChartControl(mainWindow.ChartLegendView)); - + Assert.IsNull(viewHost.ActiveDocumentView); } @@ -456,7 +456,7 @@ var projectFactory = mocks.Stub(); projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); mocks.ReplayAll(); - + using (var mainWindow = new Gui.Forms.MainWindow.MainWindow()) using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { @@ -465,7 +465,7 @@ mainWindow.SetGui(gui); mainWindow.InitializeToolWindows(); - + // Precondition Assert.IsNotNull(mainWindow.ProjectExplorer); @@ -624,28 +624,29 @@ var projectFactory = mocks.Stub(); projectFactory.Stub(pf => pf.CreateNewProject()).Return(project1); mocks.ReplayAll(); - + using (var mainWindow = new Gui.Forms.MainWindow.MainWindow()) using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { gui.Plugins.Add(new TestPlugin()); gui.Run(); - + mainWindow.SetGui(gui); mainWindow.InitializeToolWindows(); // Precondition Assert.IsNotNull(mainWindow.ProjectExplorer); Assert.AreSame(project1, mainWindow.ProjectExplorer.Data); - + gui.SetProject(project2, string.Empty); // When mainWindow.UpdateProjectExplorer(); - + // Then Assert.AreSame(project2, mainWindow.ProjectExplorer.Data); } + mocks.VerifyAll(); } @@ -665,7 +666,7 @@ { gui.Plugins.Add(new TestPlugin()); gui.Run(); - + mainWindow.SetGui(gui); mainWindow.InitializeToolWindows(); @@ -701,7 +702,7 @@ { gui.Plugins.Add(new TestPlugin()); gui.Run(); - + mainWindow.SetGui(gui); mainWindow.InitializeToolWindows(); @@ -737,10 +738,10 @@ { gui.Plugins.Add(new TestPlugin()); gui.Run(); - + mainWindow.SetGui(gui); mainWindow.InitializeToolWindows(); - + var view1 = new TestMapView(); var view2 = new TestMapView(); MapLegendView mapLegendView = mainWindow.MapLegendView; @@ -777,10 +778,10 @@ { gui.Plugins.Add(new TestPlugin()); gui.Run(); - + mainWindow.SetGui(gui); mainWindow.InitializeToolWindows(); - + var view = new TestMapView(); MapLegendView mapLegendView = mainWindow.MapLegendView; @@ -815,10 +816,10 @@ { gui.Plugins.Add(new TestPlugin()); gui.Run(); - + mainWindow.SetGui(gui); mainWindow.InitializeToolWindows(); - + var view1 = new TestMapView(); var view2 = new TestMapView(); MapLegendView mapLegendView = mainWindow.MapLegendView; @@ -838,12 +839,166 @@ mocks.VerifyAll(); } - + + [Test] + public void GivenGuiWithChartLegendView_WhenChartViewAdded_ThenComponentsUpdated() + { + // Given + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var mainWindow = new Gui.Forms.MainWindow.MainWindow()) + using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) + { + gui.Plugins.Add(new TestPlugin()); + gui.Run(); + + mainWindow.SetGui(gui); + mainWindow.InitializeToolWindows(); + + var view = new TestChartView(); + ChartLegendView chartLegendView = mainWindow.ChartLegendView; + + // Precondition + Assert.IsNull(GetChartControl(chartLegendView)); + + // When + gui.ViewHost.AddDocumentView(view); + + // Then + Assert.AreSame(view.Chart, GetChartControl(chartLegendView)); + } + + mocks.VerifyAll(); + } + + [Test] + public void GivenGuiWithChartLegendView_WhenChartViewBroughtToFront_ThenComponentsUpdated() + { + // Given + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var mainWindow = new Gui.Forms.MainWindow.MainWindow()) + using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) + { + gui.Plugins.Add(new TestPlugin()); + gui.Run(); + + mainWindow.SetGui(gui); + mainWindow.InitializeToolWindows(); + + var view1 = new TestChartView(); + var view2 = new TestChartView(); + ChartLegendView chartLegendView = mainWindow.ChartLegendView; + + gui.ViewHost.AddDocumentView(view1); + gui.ViewHost.AddDocumentView(view2); + + // Precondition + Assert.AreSame(view2.Chart, GetChartControl(chartLegendView)); + + // When + gui.ViewHost.BringToFront(view1); + + // Then + Assert.AreSame(view1.Chart, GetChartControl(chartLegendView)); + } + + mocks.VerifyAll(); + } + + [Test] + public void GivenGuiWithChartLegendView_WhenChartViewRemoved_ThenComponentsUpdated() + { + // Given + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var mainWindow = new Gui.Forms.MainWindow.MainWindow()) + using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) + { + gui.Plugins.Add(new TestPlugin()); + gui.Run(); + + mainWindow.SetGui(gui); + mainWindow.InitializeToolWindows(); + + var view = new TestChartView(); + ChartLegendView chartLegendView = mainWindow.ChartLegendView; + + gui.ViewHost.AddDocumentView(view); + + // Precondition + Assert.AreSame(view.Chart, GetChartControl(chartLegendView)); + + // When + gui.ViewHost.Remove(view); + + // Then + Assert.IsNull(GetChartControl(chartLegendView)); + } + + mocks.VerifyAll(); + } + + [Test] + public void GivenGuiWithChartLegendView_WhenOtherChartViewRemoved_ThenComponentsNotUpdated() + { + // Given + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var mainWindow = new Gui.Forms.MainWindow.MainWindow()) + using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) + { + gui.Plugins.Add(new TestPlugin()); + gui.Run(); + + mainWindow.SetGui(gui); + mainWindow.InitializeToolWindows(); + + var view1 = new TestChartView(); + var view2 = new TestChartView(); + ChartLegendView chartLegendView = mainWindow.ChartLegendView; + + gui.ViewHost.AddDocumentView(view1); + gui.ViewHost.AddDocumentView(view2); + + // Precondition + Assert.AreSame(view2.Chart, GetChartControl(chartLegendView)); + + // When + gui.ViewHost.Remove(view1); + + // Then + Assert.AreSame(view2.Chart, GetChartControl(chartLegendView)); + } + + mocks.VerifyAll(); + } + private static IMapControl GetMapControl(MapLegendView mapLegendView) { return TypeUtils.GetProperty(mapLegendView, "MapControl"); } - + private static IChartControl GetChartControl(ChartLegendView chartLegendView) { return TypeUtils.GetProperty(chartLegendView, "ChartControl"); Index: Core/Gui/test/Core.Gui.TestUtil/Core.Gui.TestUtil.csproj =================================================================== diff -u -r89e16fb45c79e575b0c335e71705694a9dac87c8 -r6be31462252a65cf54edd67c4005f66c944260fe --- Core/Gui/test/Core.Gui.TestUtil/Core.Gui.TestUtil.csproj (.../Core.Gui.TestUtil.csproj) (revision 89e16fb45c79e575b0c335e71705694a9dac87c8) +++ Core/Gui/test/Core.Gui.TestUtil/Core.Gui.TestUtil.csproj (.../Core.Gui.TestUtil.csproj) (revision 6be31462252a65cf54edd67c4005f66c944260fe) @@ -8,7 +8,9 @@ + + @@ -21,4 +23,9 @@ 3.8.1 + + + Component + + \ No newline at end of file Index: Core/Gui/test/Core.Gui.TestUtil/TestChartView.cs =================================================================== diff -u --- Core/Gui/test/Core.Gui.TestUtil/TestChartView.cs (revision 0) +++ Core/Gui/test/Core.Gui.TestUtil/TestChartView.cs (revision 6be31462252a65cf54edd67c4005f66c944260fe) @@ -0,0 +1,37 @@ +// 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.Windows.Forms; +using Core.Components.Chart.Forms; +using Core.Components.OxyPlot.Forms; + +namespace Core.Gui.TestUtil +{ + /// + /// Simple implementation which can be used in tests. + /// + public class TestChartView : Control, IChartView + { + public object Data { get; set; } + + public IChartControl Chart => (ChartControl) Data; + } +} \ No newline at end of file Fisheye: Tag 6be31462252a65cf54edd67c4005f66c944260fe refers to a dead (removed) revision in file `Core/Plugins/test/Core.Plugins.Chart.Test/TestChartView.cs'. Fisheye: No comparison available. Pass `N' to diff?