Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs
===================================================================
diff -u -r37213b379dafd60f815fce7cb7fd70e8b85d0ec5 -r1dc89167ccdfcc4069e7bceb1db90dba570daba9
--- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 37213b379dafd60f815fce7cb7fd70e8b85d0ec5)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 1dc89167ccdfcc4069e7bceb1db90dba570daba9)
@@ -1467,6 +1467,15 @@
}
///
+ /// Looks up a localized string similar to Gebruik.
+ ///
+ public static string SelectionDialogBase_ColumnSelect_DisplayName {
+ get {
+ return ResourceManager.GetString("SelectionDialogBase_ColumnSelect_DisplayName", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized resource of type System.Drawing.Bitmap.
///
public static System.Drawing.Bitmap SelectionDialogIcon {
Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx
===================================================================
diff -u -r37213b379dafd60f815fce7cb7fd70e8b85d0ec5 -r1dc89167ccdfcc4069e7bceb1db90dba570daba9
--- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision 37213b379dafd60f815fce7cb7fd70e8b85d0ec5)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision 1dc89167ccdfcc4069e7bceb1db90dba570daba9)
@@ -598,4 +598,7 @@
Modelinstellingen
+
+ Gebruik
+
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj
===================================================================
diff -u -r3e5a3e2990566fe86caaaa87136d0f57543a9666 -r1dc89167ccdfcc4069e7bceb1db90dba570daba9
--- Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision 3e5a3e2990566fe86caaaa87136d0f57543a9666)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision 1dc89167ccdfcc4069e7bceb1db90dba570daba9)
@@ -79,6 +79,12 @@
+
+ Form
+
+
+ SelectionDialogBase.cs
+
@@ -99,13 +105,17 @@
FailureMechanismResultView.cs
+
PublicResXFileCodeGenerator
Resources.Designer.cs
Designer
+
+ SelectionDialogBase.cs
+
CommentView.cs
Index: Ringtoets/Common/src/Ringtoets.Common.Forms/SelectionDialogBase.Designer.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Forms/SelectionDialogBase.Designer.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/SelectionDialogBase.Designer.cs (revision 1dc89167ccdfcc4069e7bceb1db90dba570daba9)
@@ -0,0 +1,170 @@
+// 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.
+
+namespace Ringtoets.Common.Forms
+{
+ partial class SelectionDialogBase
+ {
+ ///
+ /// Required designer variable.
+ ///
+ protected System.ComponentModel.IContainer components = null;
+
+ #region Windows Form 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.ButtonGroupBox = new System.Windows.Forms.GroupBox();
+ this.panel2 = new System.Windows.Forms.Panel();
+ this.SelectAllButton = new System.Windows.Forms.Button();
+ this.DeselectAllButton = new System.Windows.Forms.Button();
+ this.DoForSelectedButton = new System.Windows.Forms.Button();
+ this.CustomCancelButton = new System.Windows.Forms.Button();
+ this.panel1 = new System.Windows.Forms.Panel();
+ this.ButtonGroupBox.SuspendLayout();
+ this.panel2.SuspendLayout();
+ this.panel1.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // DataGridViewControl
+ //
+ this.DataGridViewControl.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.DataGridViewControl.Location = new System.Drawing.Point(3, 16);
+ 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(261, 66);
+ this.DataGridViewControl.TabIndex = 0;
+ //
+ // ButtonGroupBox
+ //
+ this.ButtonGroupBox.Controls.Add(this.DataGridViewControl);
+ this.ButtonGroupBox.Controls.Add(this.panel2);
+ this.ButtonGroupBox.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.ButtonGroupBox.Location = new System.Drawing.Point(0, 0);
+ this.ButtonGroupBox.Name = "ButtonGroupBox";
+ this.ButtonGroupBox.Size = new System.Drawing.Size(267, 124);
+ this.ButtonGroupBox.TabIndex = 7;
+ this.ButtonGroupBox.TabStop = false;
+ //
+ // panel2
+ //
+ this.panel2.Controls.Add(this.SelectAllButton);
+ this.panel2.Controls.Add(this.DeselectAllButton);
+ this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
+ this.panel2.Location = new System.Drawing.Point(3, 82);
+ this.panel2.Name = "panel2";
+ this.panel2.Size = new System.Drawing.Size(261, 39);
+ this.panel2.TabIndex = 6;
+ //
+ // SelectAllButton
+ //
+ this.SelectAllButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
+ this.SelectAllButton.Location = new System.Drawing.Point(9, 6);
+ this.SelectAllButton.Name = "SelectAllButton";
+ this.SelectAllButton.Size = new System.Drawing.Size(111, 23);
+ this.SelectAllButton.TabIndex = 5;
+ this.SelectAllButton.Text = "Selecteer alles";
+ this.SelectAllButton.UseVisualStyleBackColor = true;
+ this.SelectAllButton.Click += new System.EventHandler(this.SelectAllButton_Click);
+ //
+ // DeselectAllButton
+ //
+ this.DeselectAllButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
+ this.DeselectAllButton.Location = new System.Drawing.Point(126, 6);
+ this.DeselectAllButton.Name = "DeselectAllButton";
+ this.DeselectAllButton.Size = new System.Drawing.Size(111, 23);
+ this.DeselectAllButton.TabIndex = 4;
+ this.DeselectAllButton.Text = "Deselecteer alles";
+ this.DeselectAllButton.UseVisualStyleBackColor = true;
+ this.DeselectAllButton.Click += new System.EventHandler(this.DeselectAllButton_Click);
+ //
+ // DoForSelectedButton
+ //
+ this.DoForSelectedButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.DoForSelectedButton.Enabled = false;
+ this.DoForSelectedButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
+ this.DoForSelectedButton.Location = new System.Drawing.Point(80, 6);
+ this.DoForSelectedButton.Name = "DoForSelectedButton";
+ this.DoForSelectedButton.Size = new System.Drawing.Size(86, 23);
+ this.DoForSelectedButton.TabIndex = 3;
+ this.DoForSelectedButton.Text = "Genereren";
+ this.DoForSelectedButton.UseVisualStyleBackColor = true;
+ this.DoForSelectedButton.Click += new System.EventHandler(this.DoForSelectedButton_Click);
+ //
+ // CustomCancelButton
+ //
+ this.CustomCancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.CustomCancelButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
+ this.CustomCancelButton.Location = new System.Drawing.Point(172, 6);
+ this.CustomCancelButton.Name = "CustomCancelButton";
+ this.CustomCancelButton.Size = new System.Drawing.Size(86, 23);
+ this.CustomCancelButton.TabIndex = 6;
+ this.CustomCancelButton.Text = "Annuleren";
+ this.CustomCancelButton.UseVisualStyleBackColor = true;
+ this.CustomCancelButton.Click += new System.EventHandler(this.CustomCancelButton_Click);
+ //
+ // panel1
+ //
+ this.panel1.Controls.Add(this.DoForSelectedButton);
+ this.panel1.Controls.Add(this.CustomCancelButton);
+ this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
+ this.panel1.Location = new System.Drawing.Point(0, 124);
+ this.panel1.Name = "panel1";
+ this.panel1.Size = new System.Drawing.Size(267, 35);
+ this.panel1.TabIndex = 8;
+ //
+ // SelectionDialogBase
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.AutoScroll = true;
+ this.AutoScrollMinSize = new System.Drawing.Size(240, 90);
+ this.ClientSize = new System.Drawing.Size(267, 159);
+ this.Controls.Add(this.ButtonGroupBox);
+ this.Controls.Add(this.panel1);
+ this.Name = "SelectionDialogBase";
+ this.Text = "SelectionDialogBase";
+ this.ButtonGroupBox.ResumeLayout(false);
+ this.panel2.ResumeLayout(false);
+ this.panel1.ResumeLayout(false);
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ protected Core.Common.Controls.DataGrid.DataGridViewControl DataGridViewControl;
+ private System.Windows.Forms.GroupBox ButtonGroupBox;
+ private System.Windows.Forms.Panel panel2;
+ private System.Windows.Forms.Button SelectAllButton;
+ private System.Windows.Forms.Button DeselectAllButton;
+ protected System.Windows.Forms.Button DoForSelectedButton;
+ protected System.Windows.Forms.Button CustomCancelButton;
+ private System.Windows.Forms.Panel panel1;
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.Forms/SelectionDialogBase.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Forms/SelectionDialogBase.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/SelectionDialogBase.cs (revision 1dc89167ccdfcc4069e7bceb1db90dba570daba9)
@@ -0,0 +1,159 @@
+// 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;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows.Forms;
+using Core.Common.Controls.Dialogs;
+using Core.Common.Utils.Extensions;
+using Core.Common.Utils.Reflection;
+using Ringtoets.Common.Forms.Properties;
+using Ringtoets.Common.Forms.Views;
+
+namespace Ringtoets.Common.Forms
+{
+ ///
+ /// Base class for selection dialogs which should be derived in order to get a consistent look and feel.
+ ///
+ public abstract partial class SelectionDialogBase : DialogBase where T : class
+ {
+ private const int selectItemColumnIndex = 0;
+
+ ///
+ /// Creates a new instance of .
+ ///
+ /// The owner of the dialog.
+ /// Thrown when is null.
+ protected SelectionDialogBase(IWin32Window dialogParent) : base(dialogParent, Resources.GenerateScenariosIcon, 370, 550)
+ {
+ InitializeComponent();
+ InitializeEventHandlers();
+
+ SelectedItems = new List();
+ }
+
+ ///
+ /// Gets a collection of selected if they were selected
+ /// in the dialog and a confirmation was given. If no confirmation was given or no
+ /// was selected, then an empty collection is returned.
+ ///
+ public IEnumerable SelectedItems { get; private set; }
+
+ ///
+ /// Sets the datasource on the .
+ ///
+ protected void SetDataSource(object data)
+ {
+ DataGridViewControl.SetDataSource(data);
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ protected override Button GetCancelButton()
+ {
+ return CustomCancelButton;
+ }
+
+ private void SetSelectedItems()
+ {
+ SelectedItems = GetSelectedItems();
+ }
+
+ private IEnumerable> GetSelectableRow()
+ {
+ return DataGridViewControl.Rows.Cast().Select(row => row.DataBoundItem).Cast>();
+ }
+
+ private IEnumerable GetSelectedItems()
+ {
+ return GetSelectableRow().Where(row => row.Selected).Select(row => row.Item).ToArray();
+ }
+
+ ///
+ /// Initializes the .
+ ///
+ protected void InitializeDataGridView(string nameColumnHeader)
+ {
+ DataGridViewControl.AddCheckBoxColumn(TypeUtils.GetMemberName>(row => row.Selected),
+ Resources.SelectionDialogBase_ColumnSelect_DisplayName);
+ DataGridViewControl.AddTextBoxColumn(TypeUtils.GetMemberName>(row => row.Name),
+ nameColumnHeader, true, DataGridViewAutoSizeColumnMode.Fill);
+
+ }
+
+ #region Event handling
+
+ private void SelectAllButton_Click(object sender, EventArgs e)
+ {
+ GetSelectableRow().ForEachElementDo(row => row.Selected = true);
+ DataGridViewControl.RefreshDataGridView();
+ UpdateDoForSelectedButton();
+ }
+
+ private void DeselectAllButton_Click(object sender, EventArgs e)
+ {
+ GetSelectableRow().ForEachElementDo(row => row.Selected = false);
+ DataGridViewControl.RefreshDataGridView();
+ UpdateDoForSelectedButton();
+ }
+
+ private void InitializeEventHandlers()
+ {
+ DataGridViewControl.AddCellValueChangedHandler(DataGridViewCellValueChanged);
+ }
+
+ private void DataGridViewCellValueChanged(object sender, DataGridViewCellEventArgs e)
+ {
+ if (e.ColumnIndex != selectItemColumnIndex)
+ {
+ return;
+ }
+ UpdateDoForSelectedButton();
+ }
+
+ private void DoForSelectedButton_Click(object sender, EventArgs e)
+ {
+ SetSelectedItems();
+ Close();
+ }
+
+ private void CustomCancelButton_Click(object sender, EventArgs e)
+ {
+ Close();
+ }
+
+ private void UpdateDoForSelectedButton()
+ {
+ DoForSelectedButton.Enabled = GetSelectableRow().Any(row => row.Selected);
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.Forms/SelectionDialogBase.resx
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Forms/SelectionDialogBase.resx (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/SelectionDialogBase.resx (revision 1dc89167ccdfcc4069e7bceb1db90dba570daba9)
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/SelectableRow.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/SelectableRow.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/SelectableRow.cs (revision 1dc89167ccdfcc4069e7bceb1db90dba570daba9)
@@ -0,0 +1,66 @@
+// 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;
+
+namespace Ringtoets.Common.Forms.Views
+{
+ ///
+ /// This class represents a row of that can be selected.
+ ///
+ public class SelectableRow
+ {
+ ///
+ /// Creates a new instance of .
+ ///
+ /// The this row contains.
+ /// The name representation of .
+ /// Thrown when any input parameter is null.
+ public SelectableRow(T item, string name)
+ {
+ if (item == null)
+ {
+ throw new ArgumentNullException("item");
+ }
+ if (name == null)
+ {
+ throw new ArgumentNullException("name");
+ }
+ Name = name;
+ Item = item;
+ }
+
+ ///
+ /// Gets or sets whether the is selected.
+ ///
+ public bool Selected { get; set; }
+
+ ///
+ /// Gets the name of the .
+ ///
+ public string Name { get; private set; }
+
+ ///
+ /// Gets the item.
+ ///
+ public T Item { get; private set; }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj
===================================================================
diff -u -r06b2840a2bb64c0960c8ac29322b5a0971c73c77 -r1dc89167ccdfcc4069e7bceb1db90dba570daba9
--- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision 06b2840a2bb64c0960c8ac29322b5a0971c73c77)
+++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision 1dc89167ccdfcc4069e7bceb1db90dba570daba9)
@@ -84,6 +84,7 @@
+
@@ -96,6 +97,7 @@
+
Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/SelectionDialogBaseTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/SelectionDialogBaseTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/SelectionDialogBaseTest.cs (revision 1dc89167ccdfcc4069e7bceb1db90dba570daba9)
@@ -0,0 +1,351 @@
+// 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.DataGrid;
+using Core.Common.Controls.Dialogs;
+using NUnit.Extensions.Forms;
+using NUnit.Framework;
+using Ringtoets.Common.Forms.Views;
+
+namespace Ringtoets.Common.Forms.Test
+{
+ [TestFixture]
+ public class SelectionDialogBaseTest
+ {
+ private const int selectItemColumnIndex = 0;
+ private const int nameColumnIndex = 1;
+ private Form testForm;
+
+ [SetUp]
+ public void Setup()
+ {
+ testForm = new Form();
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ testForm.Dispose();
+ }
+
+ [Test]
+ public void DefaultConstructor_DefaultValues()
+ {
+ // Call
+ using (var dialog = new TestSelectionDialogBase(testForm))
+ {
+ // Assert
+ Assert.IsInstanceOf(dialog);
+ }
+ }
+
+ [Test]
+ public void Constructor_DialogParentIsNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => new TestSelectionDialogBase(null);
+
+ // Assert
+ var paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("dialogParent", paramName);
+ }
+
+ [Test]
+ public void Constructor_DataGridViewCorrectlyInitialized()
+ {
+ // Setup & Call
+ using (var dialog = new TestFullyConfiguredSelectionDialogBase(testForm))
+ {
+ dialog.Show();
+
+ // Assert
+ Assert.IsEmpty(dialog.SelectedItems);
+
+ var dataGridViewControl = (DataGridViewControl)new ControlTester("DataGridViewControl", dialog).TheObject;
+ var dataGridView = dataGridViewControl.Controls.OfType().First();
+ Assert.AreEqual(2, dataGridView.ColumnCount);
+
+ var locationCalculateColumn = (DataGridViewCheckBoxColumn)dataGridView.Columns[selectItemColumnIndex];
+ const string expectedLocationCalculateHeaderText = "Gebruik";
+ Assert.AreEqual(expectedLocationCalculateHeaderText, locationCalculateColumn.HeaderText);
+ Assert.AreEqual("Selected", locationCalculateColumn.DataPropertyName);
+ Assert.IsFalse(locationCalculateColumn.ReadOnly);
+
+ var nameColumn = (DataGridViewTextBoxColumn)dataGridView.Columns[nameColumnIndex];
+ Assert.AreEqual(string.Empty, nameColumn.HeaderText);
+ Assert.AreEqual("Name", nameColumn.DataPropertyName);
+ Assert.AreEqual(DataGridViewAutoSizeColumnMode.Fill, nameColumn.AutoSizeMode);
+ Assert.IsTrue(nameColumn.ReadOnly);
+
+ var buttonTester = new ButtonTester("DoForSelectedButton", dialog);
+ var button = (Button)buttonTester.TheObject;
+ Assert.IsFalse(button.Enabled);
+ }
+ }
+
+ [Test]
+ public void Constructor_Always_SetMinimumSize()
+ {
+ // Setup
+ using (var dialog = new TestSelectionDialogBase(testForm))
+ {
+ // Call
+ dialog.Show();
+
+ // Assert
+ Assert.AreEqual(370, dialog.MinimumSize.Width);
+ Assert.AreEqual(550, dialog.MinimumSize.Height);
+ }
+ }
+
+ [Test]
+ public void GivenDialogWithSelectedItems_WhenCloseWithoutConfirmation_ThenReturnsEmptyCollection()
+ {
+ // Given
+ var items = new[]
+ {
+ new object(),
+ new object()
+ };
+
+ using (var dialog = new TestFullyConfiguredSelectionDialogBase(testForm))
+ {
+ var selectionView = (DataGridViewControl)new ControlTester("DataGridViewControl", dialog).TheObject;
+ dialog.SetDataSource(items);
+
+ dialog.Show();
+ selectionView.Rows[0].Cells[0].Value = true;
+
+ // When
+ dialog.Close();
+
+ // Then
+ Assert.IsEmpty(dialog.SelectedItems);
+ }
+ }
+
+ [Test]
+ public void GivenDialogWithSelectedItems_WhenCancelButtonClicked_ThenReturnsSelectedCollection()
+ {
+ // Given
+ var selectedItem = new object();
+ var items = new[]
+ {
+ selectedItem,
+ new object()
+ };
+
+ using (var dialog = new TestFullyConfiguredSelectionDialogBase(testForm))
+ {
+ var selectionView = (DataGridViewControl)new ControlTester("DataGridViewControl", dialog).TheObject;
+ dialog.SetDataSource(items);
+
+ dialog.Show();
+ selectionView.Rows[0].Cells[0].Value = true;
+
+ // When
+ var cancelButton = new ButtonTester("CustomCancelButton", dialog);
+ cancelButton.Click();
+
+ // Then
+ Assert.IsEmpty(dialog.SelectedItems);
+ }
+ }
+
+ [Test]
+ public void GivenDialogWithSelectedItems_WhenDoForSelectedButton_ThenReturnsSelectedCollection()
+ {
+ // Given
+ var selectedItem = new object();
+ var items = new[]
+ {
+ selectedItem,
+ new object()
+ };
+
+ using (var dialog = new TestFullyConfiguredSelectionDialogBase(testForm))
+ {
+ var selectionView = (DataGridViewControl)new ControlTester("DataGridViewControl", dialog).TheObject;
+ dialog.SetDataSource(items);
+
+ dialog.Show();
+ selectionView.Rows[0].Cells[0].Value = true;
+
+ // When
+ var generateButton = new ButtonTester("DoForSelectedButton", dialog);
+ generateButton.Click();
+
+ // Then
+ var result = dialog.SelectedItems;
+
+ CollectionAssert.AreEqual(new[]
+ {
+ selectedItem
+ }, result);
+ }
+ }
+
+ [Test]
+ public void SelectAllButton_SelectAllButtonClicked_AllItemsSelected()
+ {
+ // Setup
+ var items = new[]
+ {
+ new object(),
+ new object()
+ };
+
+ using (var dialog = new TestFullyConfiguredSelectionDialogBase(testForm))
+ {
+ dialog.SetDataSource(items);
+ dialog.Show();
+
+ var dataGridView = (DataGridViewControl)new ControlTester("DataGridViewControl", dialog).TheObject;
+ var rows = dataGridView.Rows;
+ var button = new ButtonTester("SelectAllButton", dialog);
+
+ // Precondition
+ Assert.IsFalse((bool)rows[0].Cells[selectItemColumnIndex].Value);
+ Assert.IsFalse((bool)rows[1].Cells[selectItemColumnIndex].Value);
+
+ // Call
+ button.Click();
+
+ // Assert
+ Assert.IsTrue((bool)rows[0].Cells[selectItemColumnIndex].Value);
+ Assert.IsTrue((bool)rows[1].Cells[selectItemColumnIndex].Value);
+ }
+ }
+
+ [Test]
+ public void DeselectAllButton_AllItemsSelectedDeselectAllButtonClicked_AllItemsNotSelected()
+ {
+ // Setup
+ var items = new[]
+ {
+ new object(),
+ new object()
+ };
+
+ using (var dialog = new TestFullyConfiguredSelectionDialogBase(testForm))
+ {
+ dialog.SetDataSource(items);
+ dialog.Show();
+
+ var dataGridView = (DataGridViewControl)new ControlTester("DataGridViewControl", dialog).TheObject;
+ var rows = dataGridView.Rows;
+ var button = new ButtonTester("DeselectAllButton", dialog);
+
+ foreach (DataGridViewRow row in rows)
+ {
+ row.Cells[selectItemColumnIndex].Value = true;
+ }
+
+ // Precondition
+ Assert.IsTrue((bool)rows[0].Cells[selectItemColumnIndex].Value);
+ Assert.IsTrue((bool)rows[1].Cells[selectItemColumnIndex].Value);
+
+ // Call
+ button.Click();
+
+ // Assert
+ Assert.IsFalse((bool)rows[0].Cells[selectItemColumnIndex].Value);
+ Assert.IsFalse((bool)rows[1].Cells[selectItemColumnIndex].Value);
+ }
+ }
+
+ [Test]
+ public void DoForSelectedButton_NoneSelected_DoForSelectedButtonDisabled()
+ {
+ // Setup
+ var items = new[]
+ {
+ new object(),
+ new object()
+ };
+
+ using (var dialog = new TestFullyConfiguredSelectionDialogBase(testForm))
+ {
+ dialog.SetDataSource(items);
+ dialog.Show();
+ var buttonTester = new ButtonTester("DoForSelectedButton", dialog);
+
+ // Call
+ var button = (Button)buttonTester.TheObject;
+
+ // Assert
+ Assert.IsFalse(button.Enabled);
+ Assert.IsEmpty(dialog.SelectedItems);
+ }
+ }
+
+ [Test]
+ public void DoForSelectedButton_OneSelected_ReturnsSelectedItems()
+ {
+ // Setup
+ var selectedItem = new object();
+ var items = new[]
+ {
+ selectedItem,
+ new object()
+ };
+
+ using (var dialog = new TestFullyConfiguredSelectionDialogBase(testForm))
+ {
+ dialog.SetDataSource(items);
+ dialog.Show();
+ var dataGridView = (DataGridViewControl)new ControlTester("DataGridViewControl", dialog).TheObject;
+ var rows = dataGridView.Rows;
+ rows[0].Cells[selectItemColumnIndex].Value = true;
+ var buttonTester = new ButtonTester("DoForSelectedButton", dialog);
+
+ // Call
+ buttonTester.Click();
+
+ // Assert
+ Assert.AreEqual(1, dialog.SelectedItems.Count());
+ Assert.AreEqual(selectedItem, dialog.SelectedItems.First());
+ }
+ }
+
+ private class TestSelectionDialogBase : SelectionDialogBase