Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj
===================================================================
diff -u -rb74aa4c8b4b8995197d3252cc299835b7e57fc47 -rb9d3e9f07eb3d45c0b608fc219982c4ddec05d6a
--- Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision b74aa4c8b4b8995197d3252cc299835b7e57fc47)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision b9d3e9f07eb3d45c0b608fc219982c4ddec05d6a)
@@ -38,8 +38,10 @@
+
+
@@ -118,6 +120,12 @@
+
+ UserControl
+
+
+ CalculatableView.cs
+
UserControl
Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/CalculatableView.Designer.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/CalculatableView.Designer.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/CalculatableView.Designer.cs (revision b9d3e9f07eb3d45c0b608fc219982c4ddec05d6a)
@@ -0,0 +1,101 @@
+namespace Ringtoets.Common.Forms.Views
+{
+ partial class CalculatableView
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ #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.dataGridViewControl = new Core.Common.Controls.DataGrid.DataGridViewControl();
+ this.CalculateForSelectedButton = new System.Windows.Forms.Button();
+ this.DeselectAllButton = new System.Windows.Forms.Button();
+ this.SelectAllButton = new System.Windows.Forms.Button();
+ this.ButtonGroupBox = new System.Windows.Forms.GroupBox();
+ this.ButtonGroupBox.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // dataGridViewControl
+ //
+ this.dataGridViewControl.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.dataGridViewControl.Location = new System.Drawing.Point(0, 0);
+ this.dataGridViewControl.MultiSelect = true;
+ this.dataGridViewControl.Name = "dataGridViewControl";
+ this.dataGridViewControl.Padding = new System.Windows.Forms.Padding(0, 0, 0, 5);
+ this.dataGridViewControl.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.RowHeaderSelect;
+ this.dataGridViewControl.Size = new System.Drawing.Size(533, 85);
+ this.dataGridViewControl.TabIndex = 2;
+ //
+ // CalculateForSelectedButton
+ //
+ this.CalculateForSelectedButton.Enabled = false;
+ this.CalculateForSelectedButton.Location = new System.Drawing.Point(227, 29);
+ this.CalculateForSelectedButton.Name = "CalculateForSelectedButton";
+ this.CalculateForSelectedButton.Size = new System.Drawing.Size(207, 23);
+ this.CalculateForSelectedButton.TabIndex = 2;
+ this.CalculateForSelectedButton.UseVisualStyleBackColor = true;
+ this.CalculateForSelectedButton.Click += new System.EventHandler(this.CalculateForSelectedButton_Click);
+ //
+ // DeselectAllButton
+ //
+ this.DeselectAllButton.Location = new System.Drawing.Point(110, 29);
+ this.DeselectAllButton.Name = "DeselectAllButton";
+ this.DeselectAllButton.Size = new System.Drawing.Size(111, 23);
+ this.DeselectAllButton.TabIndex = 1;
+ this.DeselectAllButton.UseVisualStyleBackColor = true;
+ this.DeselectAllButton.Click += new System.EventHandler(this.DeselectAllButton_Click);
+ //
+ // SelectAllButton
+ //
+ this.SelectAllButton.Location = new System.Drawing.Point(6, 29);
+ this.SelectAllButton.Name = "SelectAllButton";
+ this.SelectAllButton.Size = new System.Drawing.Size(98, 23);
+ this.SelectAllButton.TabIndex = 0;
+ this.SelectAllButton.UseVisualStyleBackColor = true;
+ this.SelectAllButton.Click += new System.EventHandler(this.SelectAllButton_Click);
+ //
+ // ButtonGroupBox
+ //
+ this.ButtonGroupBox.Controls.Add(this.CalculateForSelectedButton);
+ this.ButtonGroupBox.Controls.Add(this.DeselectAllButton);
+ this.ButtonGroupBox.Controls.Add(this.SelectAllButton);
+ this.ButtonGroupBox.Dock = System.Windows.Forms.DockStyle.Bottom;
+ this.ButtonGroupBox.Location = new System.Drawing.Point(0, 85);
+ this.ButtonGroupBox.MinimumSize = new System.Drawing.Size(445, 61);
+ this.ButtonGroupBox.Name = "ButtonGroupBox";
+ this.ButtonGroupBox.Size = new System.Drawing.Size(533, 61);
+ this.ButtonGroupBox.TabIndex = 3;
+ this.ButtonGroupBox.TabStop = false;
+ //
+ // HydraulicBoundaryLocationsView
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.AutoScroll = true;
+ this.AutoScrollMinSize = new System.Drawing.Size(516, 85);
+ this.Controls.Add(this.dataGridViewControl);
+ this.Controls.Add(this.ButtonGroupBox);
+ this.Name = "HydraulicBoundaryLocationsView";
+ this.Size = new System.Drawing.Size(533, 146);
+ this.ButtonGroupBox.ResumeLayout(false);
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ protected Core.Common.Controls.DataGrid.DataGridViewControl dataGridViewControl;
+ private System.Windows.Forms.Button CalculateForSelectedButton;
+ private System.Windows.Forms.Button DeselectAllButton;
+ private System.Windows.Forms.Button SelectAllButton;
+ protected System.Windows.Forms.GroupBox ButtonGroupBox;
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/CalculatableView.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/CalculatableView.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/CalculatableView.cs (revision b9d3e9f07eb3d45c0b608fc219982c4ddec05d6a)
@@ -0,0 +1,188 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU 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 General Public License for more details.
+//
+// You should have received a copy of the GNU 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.Windows.Forms;
+using Core.Common.Controls.Views;
+using Core.Common.Utils.Extensions;
+using Core.Common.Utils.Reflection;
+using Ringtoets.Common.Data.Hydraulics;
+using Ringtoets.Common.Forms.Properties;
+
+namespace Ringtoets.Common.Forms.Views
+{
+ ///
+ /// Base view for calculatable objects such as views
+ /// which should be derived in order to get a consistent look and feel.
+ ///
+ public abstract partial class CalculatableView : UserControl, ISelectionProvider
+ {
+ private const int calculateColumnIndex = 0;
+ private bool updatingDataSource;
+ public event EventHandler SelectionChanged;
+
+ ///
+ /// Creates a new instance of .
+ ///
+ protected CalculatableView()
+ {
+ InitializeComponent();
+ LocalizeControls();
+ InitializeEventHandlers();
+ }
+
+ public abstract object Data { get; set; }
+
+ public object Selection
+ {
+ get
+ {
+ return CreateSelectedItemFromCurrentRow();
+ }
+ }
+
+ protected override void OnLoad(EventArgs e)
+ {
+ base.OnLoad(e);
+ InitializeDataGridView();
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ components?.Dispose();
+ }
+
+ base.Dispose(disposing);
+ }
+
+ ///
+ /// Updates the data source of the data table based on the .
+ ///
+ protected void UpdateDataGridViewDataSource()
+ {
+ updatingDataSource = true;
+ SetDataSource();
+ updatingDataSource = false;
+ UpdateCalculateForSelectedButton();
+ }
+
+ ///
+ /// Initializes the .
+ ///
+ protected virtual void InitializeDataGridView()
+ {
+ dataGridViewControl.AddCheckBoxColumn(TypeUtils.GetMemberName(row => row.ToCalculate),
+ Resources.HydraulicBoundaryLocationsView_Calculate);
+ }
+
+ ///
+ /// Creates a new object that is used as the object for from
+ /// the currently selected row in the data table.
+ ///
+ /// The newly created object.
+ protected abstract object CreateSelectedItemFromCurrentRow();
+
+ ///
+ /// Sets the datasource on the .
+ ///
+ protected abstract void SetDataSource();
+
+ ///
+ /// Handles the calculation routine for the currently selected rows.
+ ///
+ protected abstract void CalculateForSelectedRows();
+
+ protected IEnumerable GetCalculatableRows()
+ {
+ return dataGridViewControl.Rows.Cast().Select(row => (CalculatableRow) row.DataBoundItem);
+ }
+
+ private void LocalizeControls()
+ {
+ CalculateForSelectedButton.Text = Resources.HydraulicBoundaryLocationsView_CalculateForSelectedButton_Text;
+ DeselectAllButton.Text = Resources.HydraulicBoundaryLocationsView_DeselectAllButton_Text;
+ SelectAllButton.Text = Resources.HydraulicBoundaryLocationsView_SelectAllButton_Text;
+ ButtonGroupBox.Text = Resources.HydraulicBoundaryLocationsView_ButtonGroupBox_Text;
+ }
+
+ private void UpdateCalculateForSelectedButton()
+ {
+ CalculateForSelectedButton.Enabled = GetCalculatableRows().Any(r => r.ToCalculate);
+ }
+
+ private void InitializeEventHandlers()
+ {
+ dataGridViewControl.AddCurrentCellChangedHandler(DataGridViewOnCurrentCellChangedHandler);
+ dataGridViewControl.AddCellValueChangedHandler(DataGridViewCellValueChanged);
+ }
+
+ private void OnSelectionChanged()
+ {
+ SelectionChanged?.Invoke(this, new EventArgs());
+ }
+
+ #region Event handling
+
+ private void DataGridViewCellValueChanged(object sender, DataGridViewCellEventArgs e)
+ {
+ if (updatingDataSource || e.ColumnIndex != calculateColumnIndex)
+ {
+ return;
+ }
+ UpdateCalculateForSelectedButton();
+ }
+
+ private void DataGridViewOnCurrentCellChangedHandler(object sender, EventArgs e)
+ {
+ if (updatingDataSource)
+ {
+ return;
+ }
+
+ OnSelectionChanged();
+ }
+
+ private void SelectAllButton_Click(object sender, EventArgs e)
+ {
+ GetCalculatableRows().ForEachElementDo(row => row.ToCalculate = true);
+ dataGridViewControl.RefreshDataGridView();
+ UpdateCalculateForSelectedButton();
+ }
+
+ private void DeselectAllButton_Click(object sender, EventArgs e)
+ {
+ GetCalculatableRows().ForEachElementDo(row => row.ToCalculate = false);
+ dataGridViewControl.RefreshDataGridView();
+ UpdateCalculateForSelectedButton();
+ }
+
+ private void CalculateForSelectedButton_Click(object sender, EventArgs e)
+ {
+ CalculateForSelectedRows();
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/HydraulicBoundaryLocationsView.Designer.cs
===================================================================
diff -u -r1e9a35d13ae40069200f8b1e6c1aa91bb54ce086 -rb9d3e9f07eb3d45c0b608fc219982c4ddec05d6a
--- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/HydraulicBoundaryLocationsView.Designer.cs (.../HydraulicBoundaryLocationsView.Designer.cs) (revision 1e9a35d13ae40069200f8b1e6c1aa91bb54ce086)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/HydraulicBoundaryLocationsView.Designer.cs (.../HydraulicBoundaryLocationsView.Designer.cs) (revision b9d3e9f07eb3d45c0b608fc219982c4ddec05d6a)
@@ -36,87 +36,8 @@
///
private void InitializeComponent()
{
- this.dataGridViewControl = new Core.Common.Controls.DataGrid.DataGridViewControl();
- this.CalculateForSelectedButton = new System.Windows.Forms.Button();
- this.DeselectAllButton = new System.Windows.Forms.Button();
- this.SelectAllButton = new System.Windows.Forms.Button();
- this.ButtonGroupBox = new System.Windows.Forms.GroupBox();
- this.ButtonGroupBox.SuspendLayout();
- this.SuspendLayout();
- //
- // dataGridViewControl
- //
- this.dataGridViewControl.Dock = System.Windows.Forms.DockStyle.Fill;
- this.dataGridViewControl.Location = new System.Drawing.Point(0, 0);
- this.dataGridViewControl.MultiSelect = true;
- this.dataGridViewControl.Name = "dataGridViewControl";
- this.dataGridViewControl.Padding = new System.Windows.Forms.Padding(0, 0, 0, 5);
- this.dataGridViewControl.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.RowHeaderSelect;
- this.dataGridViewControl.Size = new System.Drawing.Size(533, 85);
- this.dataGridViewControl.TabIndex = 2;
- //
- // CalculateForSelectedButton
- //
- this.CalculateForSelectedButton.Enabled = false;
- this.CalculateForSelectedButton.Location = new System.Drawing.Point(227, 29);
- this.CalculateForSelectedButton.Name = "CalculateForSelectedButton";
- this.CalculateForSelectedButton.Size = new System.Drawing.Size(207, 23);
- this.CalculateForSelectedButton.TabIndex = 2;
- this.CalculateForSelectedButton.UseVisualStyleBackColor = true;
- this.CalculateForSelectedButton.Click += new System.EventHandler(this.CalculateForSelectedButton_Click);
- //
- // DeselectAllButton
- //
- this.DeselectAllButton.Location = new System.Drawing.Point(110, 29);
- this.DeselectAllButton.Name = "DeselectAllButton";
- this.DeselectAllButton.Size = new System.Drawing.Size(111, 23);
- this.DeselectAllButton.TabIndex = 1;
- this.DeselectAllButton.UseVisualStyleBackColor = true;
- this.DeselectAllButton.Click += new System.EventHandler(this.DeselectAllButton_Click);
- //
- // SelectAllButton
- //
- this.SelectAllButton.Location = new System.Drawing.Point(6, 29);
- this.SelectAllButton.Name = "SelectAllButton";
- this.SelectAllButton.Size = new System.Drawing.Size(98, 23);
- this.SelectAllButton.TabIndex = 0;
- this.SelectAllButton.UseVisualStyleBackColor = true;
- this.SelectAllButton.Click += new System.EventHandler(this.SelectAllButton_Click);
- //
- // ButtonGroupBox
- //
- this.ButtonGroupBox.Controls.Add(this.CalculateForSelectedButton);
- this.ButtonGroupBox.Controls.Add(this.DeselectAllButton);
- this.ButtonGroupBox.Controls.Add(this.SelectAllButton);
- this.ButtonGroupBox.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.ButtonGroupBox.Location = new System.Drawing.Point(0, 85);
- this.ButtonGroupBox.MinimumSize = new System.Drawing.Size(445, 61);
- this.ButtonGroupBox.Name = "ButtonGroupBox";
- this.ButtonGroupBox.Size = new System.Drawing.Size(533, 61);
- this.ButtonGroupBox.TabIndex = 3;
- this.ButtonGroupBox.TabStop = false;
- //
- // HydraulicBoundaryLocationsView
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.AutoScroll = true;
- this.AutoScrollMinSize = new System.Drawing.Size(516, 85);
- this.Controls.Add(this.dataGridViewControl);
- this.Controls.Add(this.ButtonGroupBox);
- this.Name = "HydraulicBoundaryLocationsView";
- this.Size = new System.Drawing.Size(533, 146);
- this.ButtonGroupBox.ResumeLayout(false);
- this.ResumeLayout(false);
-
}
#endregion
-
- protected Core.Common.Controls.DataGrid.DataGridViewControl dataGridViewControl;
- private System.Windows.Forms.Button CalculateForSelectedButton;
- private System.Windows.Forms.Button DeselectAllButton;
- private System.Windows.Forms.Button SelectAllButton;
- protected System.Windows.Forms.GroupBox ButtonGroupBox;
}
}
Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/HydraulicBoundaryLocationsView.cs
===================================================================
diff -u -rc282e767cf740d6fc47b4082a51a5f12f6fa2e3b -rb9d3e9f07eb3d45c0b608fc219982c4ddec05d6a
--- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/HydraulicBoundaryLocationsView.cs (.../HydraulicBoundaryLocationsView.cs) (revision c282e767cf740d6fc47b4082a51a5f12f6fa2e3b)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/HydraulicBoundaryLocationsView.cs (.../HydraulicBoundaryLocationsView.cs) (revision b9d3e9f07eb3d45c0b608fc219982c4ddec05d6a)
@@ -19,12 +19,9 @@
// 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.Windows.Forms;
-using Core.Common.Controls.Views;
-using Core.Common.Utils.Extensions;
+using Core.Common.Controls.DataGrid;
using Core.Common.Utils.Reflection;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.Hydraulics;
@@ -37,25 +34,11 @@
/// Base view for views which should be derived in order to get a consistent look and feel.
///
/// The type of the row objects which are shown in the data table.
- public abstract partial class HydraulicBoundaryLocationsView : UserControl, ISelectionProvider where T : HydraulicBoundaryLocationRow
+ public abstract partial class HydraulicBoundaryLocationsView : CalculatableView where T : HydraulicBoundaryLocationRow
{
- private const int locationCalculateColumnIndex = 0;
- private bool updatingDataSource;
private IEnumerable locations;
- public event EventHandler SelectionChanged;
-
///
- /// Creates a new instance of .
- ///
- protected HydraulicBoundaryLocationsView()
- {
- InitializeComponent();
- LocalizeControls();
- InitializeEventHandlers();
- }
-
- ///
/// Gets or sets the .
///
public IHydraulicBoundaryLocationCalculationGuiService CalculationGuiService { get; set; }
@@ -65,7 +48,7 @@
///
public abstract IAssessmentSection AssessmentSection { get; set; }
- public virtual object Data
+ public override object Data
{
get
{
@@ -78,48 +61,12 @@
}
}
- public object Selection
- {
- get
- {
- return CreateSelectedItemFromCurrentRow();
- }
- }
-
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- InitializeDataGridView();
- }
-
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
-
- base.Dispose(disposing);
- }
-
///
- /// Updates the data source of the data table based on the .
+ /// Initializes the .
///
- protected void UpdateDataGridViewDataSource()
+ protected override void InitializeDataGridView()
{
- updatingDataSource = true;
- SetDataSource();
- updatingDataSource = false;
- UpdateCalculateForSelectedButton();
- }
-
- ///
- /// Initializes the .
- ///
- protected virtual void InitializeDataGridView()
- {
- dataGridViewControl.AddCheckBoxColumn(TypeUtils.GetMemberName(row => row.ToCalculate),
- RingtoetsCommonFormsResources.HydraulicBoundaryLocationsView_Calculate);
+ base.InitializeDataGridView();
dataGridViewControl.AddTextBoxColumn(TypeUtils.GetMemberName(row => row.Name),
RingtoetsCommonFormsResources.HydraulicBoundaryDatabase_Location_Name_DisplayName);
dataGridViewControl.AddTextBoxColumn(TypeUtils.GetMemberName(row => row.Id),
@@ -136,109 +83,35 @@
protected abstract T CreateNewRow(HydraulicBoundaryLocation location);
///
- /// Creates a new object that is used as the object for from
- /// the currently selected row in the data table.
- ///
- /// The newly created object.
- protected abstract object CreateSelectedItemFromCurrentRow();
-
- ///
/// Handles the calculation of the .
///
/// The enumeration of to use in the calculation.
protected abstract void HandleCalculateSelectedLocations(IEnumerable locations);
- private void LocalizeControls()
+ protected override void CalculateForSelectedRows()
{
- CalculateForSelectedButton.Text = RingtoetsCommonFormsResources.HydraulicBoundaryLocationsView_CalculateForSelectedButton_Text;
- DeselectAllButton.Text = RingtoetsCommonFormsResources.HydraulicBoundaryLocationsView_DeselectAllButton_Text;
- SelectAllButton.Text = RingtoetsCommonFormsResources.HydraulicBoundaryLocationsView_SelectAllButton_Text;
- ButtonGroupBox.Text = RingtoetsCommonFormsResources.HydraulicBoundaryLocationsView_ButtonGroupBox_Text;
- }
+ if (CalculationGuiService == null)
+ {
+ return;
+ }
- private IEnumerable GetHydraulicBoundaryLocationContextRows()
- {
- return dataGridViewControl.Rows.Cast().Select(row => (T) row.DataBoundItem);
+ var selectedLocations = GetSelectedHydraulicBoundaryLocationContext();
+ HandleCalculateSelectedLocations(selectedLocations);
}
///
- /// Sets the datasource on the .
+ /// Sets the datasource on the .
///
- private void SetDataSource()
+ protected override void SetDataSource()
{
- dataGridViewControl.SetDataSource(locations != null ? locations.Select(CreateNewRow).ToArray()
- : null);
+ dataGridViewControl.SetDataSource(locations?.Select(CreateNewRow).ToArray());
}
- private void UpdateCalculateForSelectedButton()
- {
- CalculateForSelectedButton.Enabled = GetHydraulicBoundaryLocationContextRows().Any(r => r.ToCalculate);
- }
-
- private void InitializeEventHandlers()
- {
- dataGridViewControl.AddCurrentCellChangedHandler(DataGridViewOnCurrentCellChangedHandler);
- dataGridViewControl.AddCellValueChangedHandler(DataGridViewCellValueChanged);
- }
-
- private void OnSelectionChanged()
- {
- if (SelectionChanged != null)
- {
- SelectionChanged(this, new EventArgs());
- }
- }
-
private IEnumerable GetSelectedHydraulicBoundaryLocationContext()
{
- return GetHydraulicBoundaryLocationContextRows().Where(r => r.ToCalculate).Select(r => r.HydraulicBoundaryLocation);
+ return GetCalculatableRows().Where(r => r.ToCalculate)
+ .Cast()
+ .Select(r => r.HydraulicBoundaryLocation);
}
-
- #region Event handling
-
- private void DataGridViewCellValueChanged(object sender, DataGridViewCellEventArgs e)
- {
- if (updatingDataSource || e.ColumnIndex != locationCalculateColumnIndex)
- {
- return;
- }
- UpdateCalculateForSelectedButton();
- }
-
- private void DataGridViewOnCurrentCellChangedHandler(object sender, EventArgs e)
- {
- if (updatingDataSource)
- {
- return;
- }
-
- OnSelectionChanged();
- }
-
- private void SelectAllButton_Click(object sender, EventArgs e)
- {
- GetHydraulicBoundaryLocationContextRows().ForEachElementDo(row => row.ToCalculate = true);
- dataGridViewControl.RefreshDataGridView();
- UpdateCalculateForSelectedButton();
- }
-
- private void DeselectAllButton_Click(object sender, EventArgs e)
- {
- GetHydraulicBoundaryLocationContextRows().ForEachElementDo(row => row.ToCalculate = false);
- dataGridViewControl.RefreshDataGridView();
- UpdateCalculateForSelectedButton();
- }
-
- private void CalculateForSelectedButton_Click(object sender, EventArgs e)
- {
- if (CalculationGuiService == null)
- {
- return;
- }
- var selectedLocations = GetSelectedHydraulicBoundaryLocationContext();
- HandleCalculateSelectedLocations(selectedLocations);
- }
-
- #endregion
}
}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj
===================================================================
diff -u -rb74aa4c8b4b8995197d3252cc299835b7e57fc47 -rb9d3e9f07eb3d45c0b608fc219982c4ddec05d6a
--- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision b74aa4c8b4b8995197d3252cc299835b7e57fc47)
+++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision b9d3e9f07eb3d45c0b608fc219982c4ddec05d6a)
@@ -107,6 +107,7 @@
+
Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/CalculatableViewTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/CalculatableViewTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/CalculatableViewTest.cs (revision b9d3e9f07eb3d45c0b608fc219982c4ddec05d6a)
@@ -0,0 +1,296 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU 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 General Public License for more details.
+//
+// You should have received a copy of the GNU 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.Collections.Generic;
+using System.Linq;
+using System.Windows.Forms;
+using Core.Common.Controls.Views;
+using NUnit.Extensions.Forms;
+using NUnit.Framework;
+using Ringtoets.Common.Forms.Views;
+
+namespace Ringtoets.Common.Forms.Test.Views
+{
+ [TestFixture]
+ public class CalculatableViewTest
+ {
+ private const int calculateColumnIndex = 0;
+
+ private Form testForm;
+
+ [SetUp]
+ public void Setup()
+ {
+ testForm = new Form();
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ testForm.Dispose();
+ }
+
+ [Test]
+ public void DefaultConstructor_DefaultValues()
+ {
+ // Call
+ using (var view = new TestCalculatableView())
+ {
+ // Assert
+ Assert.IsInstanceOf(view);
+ Assert.IsInstanceOf(view);
+ Assert.IsNull(view.Data);
+ }
+ }
+
+ [Test]
+ public void Constructor_CalculateAllButtonCorrectlyInitialized()
+ {
+ // Setup & Call
+ ShowTestCalculatableView();
+
+ var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm);
+ var button = (Button)buttonTester.TheObject;
+ Assert.IsFalse(button.Enabled);
+ }
+
+ [Test]
+ public void Constructor_DataGridViewCorrectlyInitialized()
+ {
+ // Setup & Call
+ ShowTestCalculatableView();
+
+ // Assert
+ var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject;
+ Assert.AreEqual(1, dataGridView.ColumnCount);
+
+ var calculateColumn = (DataGridViewCheckBoxColumn)dataGridView.Columns[calculateColumnIndex];
+ const string expectedLocationCalculateHeaderText = "Berekenen";
+ Assert.AreEqual(expectedLocationCalculateHeaderText, calculateColumn.HeaderText);
+
+ var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm);
+ var button = (Button)buttonTester.TheObject;
+ Assert.IsFalse(button.Enabled);
+ }
+
+ [Test]
+ public void CalculatableView_SelectingCellInRow_SelectionChangedFired()
+ {
+ // Setup
+ var view = ShowFullyConfiguredTestCalculatableView();
+ var createdSelection = new object();
+ view.CreateForSelection = createdSelection;
+
+ var selectionChangedCount = 0;
+ view.SelectionChanged += (sender, args) => selectionChangedCount++;
+
+ var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject;
+
+ // Call
+ dataGridView.CurrentCell = dataGridView.Rows[1].Cells[calculateColumnIndex];
+ EventHelper.RaiseEvent(dataGridView, "CellClick", new DataGridViewCellEventArgs(0, 0));
+
+ // Assert
+ Assert.AreEqual(1, selectionChangedCount);
+ }
+
+ [Test]
+ public void Selection_Always_ReturnsCreatedSelectionObject()
+ {
+ // Setup
+ var view = ShowFullyConfiguredTestCalculatableView();
+ var createdSelection = new object();
+ view.CreateForSelection = createdSelection;
+
+ // Call
+ var selection = view.Selection;
+
+ // Assert
+ Assert.AreSame(createdSelection, selection);
+ }
+
+ [Test]
+ public void SelectAllButton_SelectAllButtonClicked_AllLocationsSelected()
+ {
+ // Setup
+ ShowFullyConfiguredTestCalculatableView();
+
+ var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject;
+ var rows = dataGridView.Rows;
+ var button = new ButtonTester("SelectAllButton", testForm);
+
+ // Precondition
+ Assert.IsFalse((bool)rows[0].Cells[calculateColumnIndex].Value);
+ Assert.IsFalse((bool)rows[1].Cells[calculateColumnIndex].Value);
+
+ // Call
+ button.Click();
+
+ // Assert
+ Assert.IsTrue((bool)rows[0].Cells[calculateColumnIndex].Value);
+ Assert.IsTrue((bool)rows[1].Cells[calculateColumnIndex].Value);
+ }
+
+ [Test]
+ public void DeselectAllButton_AllLocationsSelectedDeselectAllButtonClicked_AllLocationsNotSelected()
+ {
+ // Setup
+ ShowFullyConfiguredTestCalculatableView();
+
+ var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject;
+ var rows = dataGridView.Rows;
+ var button = new ButtonTester("DeselectAllButton", testForm);
+
+ foreach (DataGridViewRow row in rows)
+ {
+ row.Cells[calculateColumnIndex].Value = true;
+ }
+
+ // Precondition
+ Assert.IsTrue((bool)rows[0].Cells[calculateColumnIndex].Value);
+ Assert.IsTrue((bool)rows[1].Cells[calculateColumnIndex].Value);
+
+ // Call
+ button.Click();
+
+ // Assert
+ Assert.IsFalse((bool)rows[0].Cells[calculateColumnIndex].Value);
+ Assert.IsFalse((bool)rows[1].Cells[calculateColumnIndex].Value);
+ }
+
+ [Test]
+ public void CalculateForSelectedButton_NoneSelected_CalculateForSelectedButtonDisabled()
+ {
+ // Setup
+ TestCalculatableView view = ShowFullyConfiguredTestCalculatableView();
+ var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm);
+
+ // Call
+ var button = (Button)buttonTester.TheObject;
+
+ // Assert
+ Assert.IsFalse(button.Enabled);
+ Assert.IsEmpty(view.LocationsToCalculate);
+ }
+
+ [Test]
+ public void CalculateForSelectedButton_OneSelected_CallsCalculateHandleCalculateSelectedLocations()
+ {
+ // Setup
+ TestCalculatableView view = ShowFullyConfiguredTestCalculatableView();
+
+ var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject;
+ var rows = dataGridView.Rows;
+ rows[0].Cells[calculateColumnIndex].Value = true;
+
+ var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm);
+
+ // Call
+ buttonTester.Click();
+
+ // Assert
+ Assert.AreEqual(1, view.LocationsToCalculate.Count());
+ TestCalculatableObject expectedObject = ((IEnumerable)view.Data).First();
+ Assert.AreEqual(expectedObject, view.LocationsToCalculate.First());
+ }
+
+ private TestCalculatableView ShowTestCalculatableView()
+ {
+ var view = new TestCalculatableView();
+
+ testForm.Controls.Add(view);
+ testForm.Show();
+ return view;
+ }
+
+ private TestCalculatableView ShowFullyConfiguredTestCalculatableView()
+ {
+ var view = ShowTestCalculatableView();
+ view.Data = new[]
+ {
+ new TestCalculatableObject(),
+ new TestCalculatableObject()
+ };
+ return view;
+ }
+
+ private class TestCalculatableRow : CalculatableRow
+ {
+ public TestCalculatableRow(TestCalculatableObject calculatableObject)
+ {
+ CalculatableObject = calculatableObject;
+ ToCalculate = calculatableObject.IsChecked;
+ }
+
+ public TestCalculatableObject CalculatableObject { get; }
+ }
+
+ private class TestCalculatableObject
+ {
+ public bool IsChecked { get; }
+ }
+
+ private class TestCalculatableView : CalculatableView
+ {
+ private IEnumerable data;
+
+ public TestCalculatableView()
+ {
+ LocationsToCalculate = new List();
+ }
+
+ public override object Data
+ {
+ get
+ {
+ return data;
+ }
+ set
+ {
+ data = value as IEnumerable;
+ UpdateDataGridViewDataSource();
+ }
+ }
+
+ public object CreateForSelection { private get; set; }
+
+ public IEnumerable LocationsToCalculate { get; private set; }
+
+ protected override object CreateSelectedItemFromCurrentRow()
+ {
+ return CreateForSelection;
+ }
+
+ protected override void SetDataSource()
+ {
+ dataGridViewControl.SetDataSource(data.Select(d => new TestCalculatableRow(d)).ToArray());
+ }
+
+ protected override void CalculateForSelectedRows()
+ {
+ LocationsToCalculate = GetCalculatableRows()
+ .Where(r => r.ToCalculate)
+ .Cast()
+ .Select(row => row.CalculatableObject);
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/HydraulicBoundaryLocationsViewTest.cs
===================================================================
diff -u -r8dcb8c0fa8992c488bdea7d0631c84b7b1b09e61 -rb9d3e9f07eb3d45c0b608fc219982c4ddec05d6a
--- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/HydraulicBoundaryLocationsViewTest.cs (.../HydraulicBoundaryLocationsViewTest.cs) (revision 8dcb8c0fa8992c488bdea7d0631c84b7b1b09e61)
+++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/HydraulicBoundaryLocationsViewTest.cs (.../HydraulicBoundaryLocationsViewTest.cs) (revision b9d3e9f07eb3d45c0b608fc219982c4ddec05d6a)
@@ -68,24 +68,12 @@
using (var view = new TestHydraulicBoundaryLocationsView())
{
// Assert
- Assert.IsInstanceOf(view);
- Assert.IsInstanceOf(view);
+ Assert.IsInstanceOf(view);
Assert.IsNull(view.Data);
}
}
[Test]
- public void Constructor_CalculateAllButtonCorrectlyInitialized()
- {
- // Setup & Call
- ShowTestHydraulicBoundaryLocationsView();
-
- var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm);
- var button = (Button) buttonTester.TheObject;
- Assert.IsFalse(button.Enabled);
- }
-
- [Test]
public void Constructor_DataGridViewCorrectlyInitialized()
{
// Setup & Call
@@ -182,143 +170,6 @@
}
[Test]
- public void HydraulicBoundaryLocationsView_SelectingCellInRow_SelectionChangedFired()
- {
- // Setup
- var view = ShowFullyConfiguredTestHydraulicBoundaryLocationsView();
- var createdSelection = new object();
- view.CreateForSelection = createdSelection;
-
- var selectionChangedCount = 0;
- view.SelectionChanged += (sender, args) => selectionChangedCount++;
-
- var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject;
-
- // Call
- dataGridView.CurrentCell = dataGridView.Rows[1].Cells[locationCalculateColumnIndex];
- EventHelper.RaiseEvent(dataGridView, "CellClick", new DataGridViewCellEventArgs(0, 0));
-
- // Assert
- Assert.AreEqual(1, selectionChangedCount);
- }
-
- [Test]
- public void Selection_Always_ReturnsCreatedSelectionObject()
- {
- // Setup
- var view = ShowFullyConfiguredTestHydraulicBoundaryLocationsView();
- var createdSelection = new object();
- view.CreateForSelection = createdSelection;
-
- // Call
- var selection = view.Selection;
-
- // Assert
- Assert.AreSame(createdSelection, selection);
- }
-
- [Test]
- public void SelectAllButton_SelectAllButtonClicked_AllLocationsSelected()
- {
- // Setup
- ShowFullyConfiguredTestHydraulicBoundaryLocationsView();
-
- var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject;
- var rows = dataGridView.Rows;
- var button = new ButtonTester("SelectAllButton", testForm);
-
- // Precondition
- Assert.IsFalse((bool) rows[0].Cells[locationCalculateColumnIndex].Value);
- Assert.IsFalse((bool) rows[1].Cells[locationCalculateColumnIndex].Value);
- Assert.IsFalse((bool) rows[2].Cells[locationCalculateColumnIndex].Value);
-
- // Call
- button.Click();
-
- // Assert
- Assert.IsTrue((bool) rows[0].Cells[locationCalculateColumnIndex].Value);
- Assert.IsTrue((bool) rows[1].Cells[locationCalculateColumnIndex].Value);
- Assert.IsTrue((bool) rows[2].Cells[locationCalculateColumnIndex].Value);
- }
-
- [Test]
- public void DeselectAllButton_AllLocationsSelectedDeselectAllButtonClicked_AllLocationsNotSelected()
- {
- // Setup
- ShowFullyConfiguredTestHydraulicBoundaryLocationsView();
-
- var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject;
- var rows = dataGridView.Rows;
- var button = new ButtonTester("DeselectAllButton", testForm);
-
- foreach (DataGridViewRow row in rows)
- {
- row.Cells[locationCalculateColumnIndex].Value = true;
- }
-
- // Precondition
- Assert.IsTrue((bool) rows[0].Cells[locationCalculateColumnIndex].Value);
- Assert.IsTrue((bool) rows[1].Cells[locationCalculateColumnIndex].Value);
- Assert.IsTrue((bool) rows[2].Cells[locationCalculateColumnIndex].Value);
-
- // Call
- button.Click();
-
- // Assert
- Assert.IsFalse((bool) rows[0].Cells[locationCalculateColumnIndex].Value);
- Assert.IsFalse((bool) rows[1].Cells[locationCalculateColumnIndex].Value);
- Assert.IsFalse((bool) rows[2].Cells[locationCalculateColumnIndex].Value);
- }
-
- [Test]
- public void CalculateForSelectedButton_NoneSelected_CalculateForSelectedButtonDisabled()
- {
- // Setup
- var mockRepository = new MockRepository();
- var guiServiceMock = mockRepository.StrictMock();
- mockRepository.ReplayAll();
-
- TestHydraulicBoundaryLocationsView view = ShowFullyConfiguredTestHydraulicBoundaryLocationsView();
- view.CalculationGuiService = guiServiceMock;
- var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm);
-
- // Call
- var button = (Button) buttonTester.TheObject;
-
- // Assert
- Assert.IsFalse(button.Enabled);
- Assert.IsEmpty(view.LocationsToCalculate);
- mockRepository.VerifyAll();
- }
-
- [Test]
- public void CalculateForSelectedButton_OneSelected_CallsCalculateHandleCalculateSelectedLocations()
- {
- // Setup
- TestHydraulicBoundaryLocationsView view = ShowFullyConfiguredTestHydraulicBoundaryLocationsView();
-
- var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject;
- var rows = dataGridView.Rows;
- rows[0].Cells[locationCalculateColumnIndex].Value = true;
-
- var mockRepository = new MockRepository();
- var guiServiceMock = mockRepository.StrictMock();
- mockRepository.ReplayAll();
-
- view.CalculationGuiService = guiServiceMock;
- var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm);
-
- // Call
- buttonTester.Click();
-
- // Assert
- Assert.AreEqual(1, view.LocationsToCalculate.Count());
- HydraulicBoundaryLocation expectedLocation = ((IEnumerable) view.Data).First();
- Assert.AreEqual(expectedLocation, view.LocationsToCalculate.First());
- mockRepository.VerifyAll();
- }
-
- [Test]
public void CalculateForSelectedButton_OneSelectedButCalculationGuiServiceNotSet_DoesNotThrowException()
{
// Setup
@@ -411,30 +262,22 @@
private sealed class TestHydraulicBoundaryLocationsView : HydraulicBoundaryLocationsView
{
- public TestHydraulicBoundaryLocationsView()
- {
- LocationsToCalculate = new List();
- }
public override IAssessmentSection AssessmentSection { get; set; }
- public IEnumerable LocationsToCalculate { get; private set; }
-
- public object CreateForSelection { get; set; }
-
protected override TestHydraulicBoundaryLocationRow CreateNewRow(HydraulicBoundaryLocation location)
{
return new TestHydraulicBoundaryLocationRow(location);
}
- protected override object CreateSelectedItemFromCurrentRow()
+ protected override void HandleCalculateSelectedLocations(IEnumerable locations)
{
- return CreateForSelection;
+ throw new NotImplementedException();
}
- protected override void HandleCalculateSelectedLocations(IEnumerable locations)
+ protected override object CreateSelectedItemFromCurrentRow()
{
- LocationsToCalculate = locations;
+ throw new NotImplementedException();
}
}
}