Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneLocationsView.Designer.cs =================================================================== diff -u -r34d0075af5464460642aeb1c0e412f2543663a4a -r8b1f55193a7e6565f7e837bcf67f77c60eacf94b --- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneLocationsView.Designer.cs (.../DuneLocationsView.Designer.cs) (revision 34d0075af5464460642aeb1c0e412f2543663a4a) +++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneLocationsView.Designer.cs (.../DuneLocationsView.Designer.cs) (revision 8b1f55193a7e6565f7e837bcf67f77c60eacf94b) @@ -28,19 +28,6 @@ /// 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 /// Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneLocationsView.cs =================================================================== diff -u -r3b8956569af566bb85af32fedceff955e064e9c3 -r8b1f55193a7e6565f7e837bcf67f77c60eacf94b --- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneLocationsView.cs (.../DuneLocationsView.cs) (revision 3b8956569af566bb85af32fedceff955e064e9c3) +++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneLocationsView.cs (.../DuneLocationsView.cs) (revision 8b1f55193a7e6565f7e837bcf67f77c60eacf94b) @@ -37,6 +37,7 @@ /// public partial class DuneLocationsView : CalculatableView { + private readonly Observer duneLocationsObserver; private IEnumerable locations; /// @@ -45,6 +46,8 @@ public DuneLocationsView() { InitializeComponent(); + + duneLocationsObserver = new Observer(UpdateDuneLocations); } public override object Data @@ -55,8 +58,10 @@ } set { - locations = value as IEnumerable; + var data = (ObservableList) value; + locations = data; UpdateDataGridViewDataSource(); + duneLocationsObserver.Observable = data; } } @@ -65,6 +70,12 @@ /// public IAssessmentSection AssessmentSection { get; set; } + protected override void Dispose(bool disposing) + { + duneLocationsObserver.Dispose(); + base.Dispose(disposing); + } + protected override void InitializeDataGridView() { base.InitializeDataGridView(); @@ -102,5 +113,35 @@ } protected override void CalculateForSelectedRows() {} + + private void UpdateDuneLocations() + { + if (IsDataGridDataSourceChanged()) + { + UpdateDataGridViewDataSource(); + } + else + { + dataGridViewControl.RefreshDataGridView(); + } + } + + private bool IsDataGridDataSourceChanged() + { + var count = dataGridViewControl.Rows.Count; + if (count != locations.Count()) + { + return true; + } + for (int i = 0; i < count; i++) + { + var locationFromGrid = ((DuneLocationRow) dataGridViewControl.Rows[i].DataBoundItem).DuneLocation; + if (!ReferenceEquals(locationFromGrid, locations.ElementAt(i))) + { + return true; + } + } + return false; + } } } \ No newline at end of file Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Views/DuneLocationsViewTest.cs =================================================================== diff -u -r3b8956569af566bb85af32fedceff955e064e9c3 -r8b1f55193a7e6565f7e837bcf67f77c60eacf94b --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Views/DuneLocationsViewTest.cs (.../DuneLocationsViewTest.cs) (revision 3b8956569af566bb85af32fedceff955e064e9c3) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Views/DuneLocationsViewTest.cs (.../DuneLocationsViewTest.cs) (revision 8b1f55193a7e6565f7e837bcf67f77c60eacf94b) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Globalization; using System.Linq; using System.Windows.Forms; @@ -31,6 +32,9 @@ using Ringtoets.DuneErosion.Data; using Ringtoets.DuneErosion.Forms.PresentationObjects; using Ringtoets.DuneErosion.Forms.Views; +using System.Collections.Generic; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.DuneErosion.Data.TestUtil; namespace Ringtoets.DuneErosion.Forms.Test.Views { @@ -125,30 +129,29 @@ // Setup using (var view = new DuneLocationsView()) { - var hydraulicBoundaryLocations = Enumerable.Empty(); + var duneLocations = new ObservableList(); // Call - view.Data = hydraulicBoundaryLocations; + view.Data = duneLocations; // Assert - Assert.AreSame(hydraulicBoundaryLocations, view.Data); + Assert.AreSame(duneLocations, view.Data); } } [Test] - public void Data_OtherThanDuneLocations_DataNull() + public void Data_OtherThanDuneLocations_ThrowsInvalidCastException() { // Setup - using (var view = new DuneLocationsView()) - { - var data = new object(); + var view = ShowDuneLocationsView(); - // Call - view.Data = data; + var locations = new List(); - // Assert - Assert.IsNull(view.Data); - } + // Call + TestDelegate action = () => view.Data = locations; + + // Assert + Assert.Throws(action); } [Test] @@ -220,6 +223,98 @@ } } + [Test] + public void DuneLocationsView_DuneLocationsUpdated_DataGridViewCorrectlyUpdated() + { + // Setup + DuneLocationsView view = ShowFullyConfiguredDuneLocationsView(); + ObservableList locations = (ObservableList)view.Data; + + // Precondition + var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject; + var dataGridViewSource = dataGridView.DataSource; + var rows = dataGridView.Rows; + rows[0].Cells[locationCalculateColumnIndex].Value = true; + Assert.AreEqual(2, rows.Count); + + var duneLocation = new DuneLocation(10, "10", new Point2D(10.0, 10.0), new DuneLocation.ConstructionProperties + { + CoastalAreaId = 3, + Offset = 80, + D50 = 0.000321 + }) + { + Output = new DuneLocationOutput(CalculationConvergence.CalculatedConverged, new DuneLocationOutput.ConstructionProperties + { + WaterLevel = 3.21, + WaveHeight = 4.32, + WavePeriod = 5.43 + }) + }; + + locations.Clear(); + locations.Add(duneLocation); + + // Call + locations.NotifyObservers(); + + // Assert + Assert.AreNotSame(dataGridViewSource, dataGridView.DataSource); + + Assert.AreEqual(1, rows.Count); + var cells = rows[0].Cells; + Assert.AreEqual(10, cells.Count); + Assert.AreEqual(false, cells[locationCalculateColumnIndex].FormattedValue); + Assert.AreEqual("10", cells[locationNameColumnIndex].FormattedValue); + Assert.AreEqual("10", cells[locationIdColumnIndex].FormattedValue); + Assert.AreEqual(new Point2D(10, 10).ToString(), cells[locationColumnIndex].FormattedValue); + Assert.AreEqual("3", cells[coastalAreaIdColumnIndex].FormattedValue); + Assert.AreEqual("80", cells[offsetColumnIndex].FormattedValue); + Assert.AreEqual(0.000321.ToString(CultureInfo.CurrentCulture), cells[d50ColumnIndex].FormattedValue); + Assert.AreEqual(3.21.ToString(CultureInfo.CurrentCulture), cells[waterLevelColumnIndex].FormattedValue); + Assert.AreEqual(4.32.ToString(CultureInfo.CurrentCulture), cells[waveHeightColumnIndex].FormattedValue); + Assert.AreEqual(5.43.ToString(CultureInfo.CurrentCulture), cells[wavePeriodColumnIndex].FormattedValue); + } + + [Test] + public void DuneLocationsView_EachDuneLocationUpdated_DataGridViewRefreshedWithNewValues() + { + // Setup + DuneLocationsView view = ShowFullyConfiguredDuneLocationsView(); + ObservableList locations = (ObservableList)view.Data; + + // Precondition + var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject; + var rows = dataGridView.Rows; + Assert.AreEqual(2, rows.Count); + DataGridViewRow firstRow = rows[0]; + DataGridViewRow secondRow = rows[1]; + + Assert.AreEqual("-", firstRow.Cells[waterLevelColumnIndex].FormattedValue); + Assert.AreEqual("-", firstRow.Cells[waveHeightColumnIndex].FormattedValue); + Assert.AreEqual("-", firstRow.Cells[wavePeriodColumnIndex].FormattedValue); + Assert.AreEqual(1.23.ToString(CultureInfo.CurrentCulture), secondRow.Cells[waterLevelColumnIndex].FormattedValue); + Assert.AreEqual(2.34.ToString(CultureInfo.CurrentCulture), secondRow.Cells[waveHeightColumnIndex].FormattedValue); + Assert.AreEqual(3.45.ToString(CultureInfo.CurrentCulture), secondRow.Cells[wavePeriodColumnIndex].FormattedValue); + + locations.ForEach(loc => + { + loc.Output = null; + + // Call + loc.NotifyObservers(); + }); + + // Assert + Assert.AreEqual(2, rows.Count); + Assert.AreEqual("-", firstRow.Cells[waterLevelColumnIndex].FormattedValue); + Assert.AreEqual("-", firstRow.Cells[waveHeightColumnIndex].FormattedValue); + Assert.AreEqual("-", firstRow.Cells[wavePeriodColumnIndex].FormattedValue); + Assert.AreEqual("-", secondRow.Cells[waterLevelColumnIndex].FormattedValue); + Assert.AreEqual("-", secondRow.Cells[waveHeightColumnIndex].FormattedValue); + Assert.AreEqual("-", secondRow.Cells[wavePeriodColumnIndex].FormattedValue); + } + private DuneLocationsView ShowFullyConfiguredDuneLocationsView() { var view = ShowDuneLocationsView(); Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsView.cs =================================================================== diff -u -re182f6f394aa75e739467a77e7bcacd9a8b25429 -r8b1f55193a7e6565f7e837bcf67f77c60eacf94b --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsView.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsView.cs) (revision e182f6f394aa75e739467a77e7bcacd9a8b25429) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsView.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsView.cs) (revision 8b1f55193a7e6565f7e837bcf67f77c60eacf94b) @@ -66,6 +66,12 @@ /// public GrassCoverErosionOutwardsFailureMechanism FailureMechanism { get; set; } + protected override void Dispose(bool disposing) + { + hydraulicBoundaryLocationsObserver.Dispose(); + base.Dispose(disposing); + } + protected override DesignWaterLevelLocationRow CreateNewRow(HydraulicBoundaryLocation location) { return new DesignWaterLevelLocationRow(location); Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs =================================================================== diff -u -r8905298103eb01ce13dd5c1a2f267f879d4fda3e -r8b1f55193a7e6565f7e837bcf67f77c60eacf94b --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs) (revision 8905298103eb01ce13dd5c1a2f267f879d4fda3e) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs) (revision 8b1f55193a7e6565f7e837bcf67f77c60eacf94b) @@ -146,7 +146,7 @@ } [Test] - public void WaveHeightLocationsView_WithNonIObservableList_ThrowsInvalidCastException() + public void DesignWaterLevelLocationsView_WithNonIObservableList_ThrowsInvalidCastException() { // Setup var view = ShowDesignWaterLevelLocationsView();