Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs
===================================================================
diff -u -r73f50b32b84bb654d07639a3cbd9a72351292c6e -rcd7b72bcec3e2c60ad5de2fb54e0cd92d60c38c1
--- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 73f50b32b84bb654d07639a3cbd9a72351292c6e)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision cd7b72bcec3e2c60ad5de2fb54e0cd92d60c38c1)
@@ -728,6 +728,35 @@
}
///
+ /// Looks up a localized string similar to Er moet een voorlandprofiel geselecteerd zijn..
+ ///
+ public static string CreateUpdateForshoreProfileOfCalculationItem_Update_calculation_no_ForeshoreProfile_ToolTip {
+ get {
+ return ResourceManager.GetString("CreateUpdateForshoreProfileOfCalculationItem_Update_calculation_no_ForeshoreProfi" +
+ "le_ToolTip", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Berekening bijwerken waar een voorlandprofiel geselecteerd is..
+ ///
+ public static string CreateUpdateForshoreProfileOfCalculationItem_Update_calculation_with_ForeshoreProfile_ToolTip {
+ get {
+ return ResourceManager.GetString("CreateUpdateForshoreProfileOfCalculationItem_Update_calculation_with_ForeshorePro" +
+ "file_ToolTip", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to &Bijwerken voorlandprofiel....
+ ///
+ public static string CreateUpdateForshoreProfileOfCalculationItem_Update_ForeshoreProfile_data {
+ get {
+ return ResourceManager.GetString("CreateUpdateForshoreProfileOfCalculationItem_Update_ForeshoreProfile_data", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized resource of type System.Drawing.Bitmap.
///
public static System.Drawing.Bitmap DatabaseIcon {
@@ -2584,6 +2613,18 @@
}
///
+ /// Looks up a localized string similar to Wanneer het voorlandprofiel wijzigt als gevolg van het bijwerken, zal het resultaat van deze berekening worden verwijderd.
+ ///
+ ///Weet u zeker dat u wilt doorgaan?.
+ ///
+ public static string UpdateForshoreProfileOfCalculation_Confirm_calculation_output_cleared_when_updating_ForeshoreProfile_dependent_data {
+ get {
+ return ResourceManager.GetString("UpdateForshoreProfileOfCalculation_Confirm_calculation_output_cleared_when_updati" +
+ "ng_ForeshoreProfile_dependent_data", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized resource of type System.Drawing.Bitmap.
///
public static System.Drawing.Bitmap UpdateItemIcon {
Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx
===================================================================
diff -u -r73f50b32b84bb654d07639a3cbd9a72351292c6e -rcd7b72bcec3e2c60ad5de2fb54e0cd92d60c38c1
--- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision 73f50b32b84bb654d07639a3cbd9a72351292c6e)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision cd7b72bcec3e2c60ad5de2fb54e0cd92d60c38c1)
@@ -978,4 +978,18 @@
Er zijn geen berekeningen met een kunstwerk.
+
+ Berekening bijwerken waar een voorlandprofiel geselecteerd is.
+
+
+ Er moet een voorlandprofiel geselecteerd zijn.
+
+
+ Wanneer het voorlandprofiel wijzigt als gevolg van het bijwerken, zal het resultaat van deze berekening worden verwijderd.
+
+Weet u zeker dat u wilt doorgaan?
+
+
+ &Bijwerken voorlandprofiel...
+
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuItemFactory.cs
===================================================================
diff -u -rb3b6c13cf736c134476b3db34281332d01ca86b1 -rcd7b72bcec3e2c60ad5de2fb54e0cd92d60c38c1
--- Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuItemFactory.cs (.../RingtoetsContextMenuItemFactory.cs) (revision b3b6c13cf736c134476b3db34281332d01ca86b1)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuItemFactory.cs (.../RingtoetsContextMenuItemFactory.cs) (revision cd7b72bcec3e2c60ad5de2fb54e0cd92d60c38c1)
@@ -20,12 +20,16 @@
// All rights reserved.
using System;
+using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
+using Core.Common.Gui;
using Core.Common.Gui.ContextMenu;
using Ringtoets.Common.Data.Calculation;
+using Ringtoets.Common.Data.DikeProfiles;
using Ringtoets.Common.Data.FailureMechanism;
+using Ringtoets.Common.Forms.ChangeHandlers;
using Ringtoets.Common.Forms.Helpers;
using Ringtoets.Common.Forms.PresentationObjects;
using Ringtoets.Common.Forms.Properties;
@@ -365,6 +369,87 @@
});
}
+ ///
+ /// Creates a which is bound to the action when updating
+ /// the of a .
+ ///
+ /// The type of calculation input that has can have a foreshore profile.
+ /// The calculation to update.
+ /// Object responsible for inquiring the required data.
+ /// The action to perform when the foreshore profile is updated.
+ /// The created .
+ /// Thrown when any of the input parameters is null.
+ public static StrictContextMenuItem CreateUpdateForshoreProfileOfCalculationItem(
+ ICalculation calculation,
+ IInquiryHelper inquiryHelper,
+ Action> updateAction)
+ where TCalculationInput : ICalculationInput, IHasForeshoreProfile
+
+ {
+ if (calculation == null)
+ {
+ throw new ArgumentNullException(nameof(calculation));
+ }
+ if (inquiryHelper == null)
+ {
+ throw new ArgumentNullException(nameof(inquiryHelper));
+ }
+ if (updateAction == null)
+ {
+ throw new ArgumentNullException(nameof(updateAction));
+ }
+
+ bool hasForeshoreProfile = calculation.InputParameters.ForeshoreProfile != null;
+ string toolTipMessage = hasForeshoreProfile
+ ? Resources.CreateUpdateForshoreProfileOfCalculationItem_Update_calculation_with_ForeshoreProfile_ToolTip
+ : Resources.CreateUpdateForshoreProfileOfCalculationItem_Update_calculation_no_ForeshoreProfile_ToolTip;
+
+ var menuItem = new StrictContextMenuItem(
+ Resources.CreateUpdateForshoreProfileOfCalculationItem_Update_ForeshoreProfile_data,
+ toolTipMessage,
+ Resources.UpdateItemIcon,
+ (o, args) =>
+ {
+ UpdateForeshoreProfileDependentDataOfCalculation(calculation,
+ inquiryHelper,
+ updateAction);
+ })
+ {
+ Enabled = hasForeshoreProfile
+ };
+
+ return menuItem;
+ }
+
+ private static void UpdateForeshoreProfileDependentDataOfCalculation(
+ ICalculation calculation,
+ IInquiryHelper inquiryHelper,
+ Action> updateAction)
+ where TCalculationInput : ICalculationInput, IHasForeshoreProfile
+ {
+ string message = Resources.UpdateForshoreProfileOfCalculation_Confirm_calculation_output_cleared_when_updating_ForeshoreProfile_dependent_data;
+
+ if (ForeshoreProfileDependentDataShouldUpdate(new[]
+ {
+ calculation
+ }, message, inquiryHelper
+ ))
+ {
+ updateAction(calculation);
+ }
+ }
+
+ private static bool ForeshoreProfileDependentDataShouldUpdate(IEnumerable calculations,
+ string query,
+ IInquiryHelper inquiryHelper)
+ {
+ var changeHandler = new CalculationChangeHandler(calculations,
+ query,
+ inquiryHelper);
+
+ return !changeHandler.RequireConfirmation() || changeHandler.InquireConfirmation();
+ }
+
private static void SetStateWithEnableFunction(T context, Func enableFunction, StrictContextMenuItem menuItem)
{
string validationText = enableFunction?.Invoke(context);
Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuItemFactoryTest.cs
===================================================================
diff -u -rb3b6c13cf736c134476b3db34281332d01ca86b1 -rcd7b72bcec3e2c60ad5de2fb54e0cd92d60c38c1
--- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuItemFactoryTest.cs (.../RingtoetsContextMenuItemFactoryTest.cs) (revision b3b6c13cf736c134476b3db34281332d01ca86b1)
+++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuItemFactoryTest.cs (.../RingtoetsContextMenuItemFactoryTest.cs) (revision cd7b72bcec3e2c60ad5de2fb54e0cd92d60c38c1)
@@ -19,9 +19,11 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System;
using System.Drawing;
using System.Linq;
using Core.Common.Base;
+using Core.Common.Gui;
using Core.Common.Gui.ContextMenu;
using Core.Common.TestUtil;
using NUnit.Extensions.Forms;
@@ -30,6 +32,7 @@
using Ringtoets.Common.Data;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.Calculation;
+using Ringtoets.Common.Data.DikeProfiles;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Data.TestUtil;
using Ringtoets.Common.Forms.PresentationObjects;
@@ -98,7 +101,7 @@
var calculationGroupContext = new TestCalculationGroupContext(calculationGroup, failureMechanismMock);
// Call
- StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateAddCalculationItem(calculationGroupContext, context => { });
+ StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateAddCalculationItem(calculationGroupContext, context => {});
// Assert
Assert.AreEqual("Berekening &toevoegen", toolStripItem.Text);
@@ -593,6 +596,205 @@
mocks.VerifyAll();
}
+ #region CreateUpdateForshoreProfileOfCalculationItem
+
+ [Test]
+ public void CreateUpdateForshoreProfileOfCalculationItem_CalculationNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var inquiryHelper = mocks.StrictMock();
+ mocks.ReplayAll();
+
+ ICalculation calculation = null;
+
+ // Call
+ TestDelegate call = () => RingtoetsContextMenuItemFactory.CreateUpdateForshoreProfileOfCalculationItem(
+ calculation,
+ inquiryHelper, c => {});
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("calculation", paramName);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void CreateUpdateForshoreProfileOfCalculationItem_IInquiryHelperNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var calculation = mocks.StrictMock>();
+ mocks.ReplayAll();
+
+ // Call
+ TestDelegate call = () => RingtoetsContextMenuItemFactory.CreateUpdateForshoreProfileOfCalculationItem(
+ calculation,
+ null, null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("inquiryHelper", paramName);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void CreateUpdateForshoreProfileOfCalculationItem_ActionNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var calculation = mocks.StrictMock>();
+ var inquiryHelper = mocks.StrictMock();
+ mocks.ReplayAll();
+
+ // Call
+ TestDelegate call = () => RingtoetsContextMenuItemFactory.CreateUpdateForshoreProfileOfCalculationItem(
+ calculation,
+ inquiryHelper, null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("updateAction", paramName);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void CreateUpdateForshoreProfileOfCalculationItem_WithoutForeshoreProfile_CreatesEnabledItem()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var calculation = mocks.StrictMock>();
+ calculation.Expect(c => c.InputParameters.ForeshoreProfile).Return(null);
+ var inquiryHelper = mocks.StrictMock();
+ mocks.ReplayAll();
+
+ // Call
+ StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateUpdateForshoreProfileOfCalculationItem(
+ calculation,
+ inquiryHelper, c => {});
+
+ // Assert
+ Assert.AreEqual("&Bijwerken voorlandprofiel...", toolStripItem.Text);
+ Assert.AreEqual("Er moet een voorlandprofiel geselecteerd zijn.", toolStripItem.ToolTipText);
+ TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.UpdateItemIcon, toolStripItem.Image);
+ Assert.IsFalse(toolStripItem.Enabled);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void CreateUpdateForshoreProfileOfCalculationItem_WithForeshoreProfile_CreatesEnabledItem()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var calculation = mocks.StrictMock>();
+ calculation.Expect(c => c.InputParameters.ForeshoreProfile).Return(new TestForeshoreProfile());
+ var inquiryHelper = mocks.StrictMock();
+ mocks.ReplayAll();
+
+ // Call
+ StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateUpdateForshoreProfileOfCalculationItem(
+ calculation,
+ inquiryHelper, c => {});
+
+ // Assert
+ Assert.AreEqual("&Bijwerken voorlandprofiel...", toolStripItem.Text);
+ Assert.AreEqual("Berekening bijwerken waar een voorlandprofiel geselecteerd is.", toolStripItem.ToolTipText);
+ TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.UpdateItemIcon, toolStripItem.Image);
+ Assert.IsTrue(toolStripItem.Enabled);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void CreateUpdateForshoreProfileOfCalculationItem_WithoutCalculationOutputPerformClick_PerformesAction()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var calculation = mocks.StrictMock>();
+ calculation.Expect(c => c.InputParameters.ForeshoreProfile).Return(new TestForeshoreProfile());
+ calculation.Expect(c => c.HasOutput).Return(false);
+ var inquiryHelper = mocks.StrictMock();
+ mocks.ReplayAll();
+
+ ICalculation actionCalculation = null;
+ StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateUpdateForshoreProfileOfCalculationItem(
+ calculation,
+ inquiryHelper,
+ c => { actionCalculation = c; });
+
+ // Call
+ toolStripItem.PerformClick();
+
+ // Assert
+ Assert.AreSame(calculation, actionCalculation);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void CreateUpdateForshoreProfileOfCalculationItem_WithCalculationOutputPerformClickNoContinuation_DoesNotPerformAction()
+ {
+ // Setup
+ string inquireContinuationMessage = "Wanneer het voorlandprofiel wijzigt als gevolg van het bijwerken, " +
+ "zal het resultaat van deze berekening worden verwijderd." +
+ $"{Environment.NewLine}{Environment.NewLine}" +
+ "Weet u zeker dat u wilt doorgaan?";
+
+ var mocks = new MockRepository();
+ var calculation = mocks.StrictMock>();
+ calculation.Expect(c => c.InputParameters.ForeshoreProfile).Return(new TestForeshoreProfile());
+ calculation.Expect(c => c.HasOutput).Return(true);
+ var inquiryHelper = mocks.StrictMock();
+ inquiryHelper.Expect(i => i.InquireContinuation(inquireContinuationMessage)).Return(false);
+ mocks.ReplayAll();
+
+ var actionPerformed = false;
+ StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateUpdateForshoreProfileOfCalculationItem(
+ calculation,
+ inquiryHelper,
+ c => { actionPerformed = true; });
+
+ // Call
+ toolStripItem.PerformClick();
+
+ // Assert
+ Assert.IsFalse(actionPerformed);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void CreateUpdateForshoreProfileOfCalculationItem_WithCalculationOutputPerformClickWithContinuation_PerformsAction()
+ {
+ // Setup
+ string inquireContinuationMessage = "Wanneer het voorlandprofiel wijzigt als gevolg van het bijwerken, " +
+ "zal het resultaat van deze berekening worden verwijderd." +
+ $"{Environment.NewLine}{Environment.NewLine}" +
+ "Weet u zeker dat u wilt doorgaan?";
+
+ var mocks = new MockRepository();
+ var calculation = mocks.StrictMock>();
+ calculation.Expect(c => c.InputParameters.ForeshoreProfile).Return(new TestForeshoreProfile());
+ calculation.Expect(c => c.HasOutput).Return(true);
+ var inquiryHelper = mocks.StrictMock();
+ inquiryHelper.Expect(i => i.InquireContinuation(inquireContinuationMessage)).Return(true);
+ mocks.ReplayAll();
+
+ var actionPerformed = false;
+ StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateUpdateForshoreProfileOfCalculationItem(
+ calculation,
+ inquiryHelper,
+ c => { actionPerformed = true; });
+
+ // Call
+ toolStripItem.PerformClick();
+
+ // Assert
+ Assert.IsTrue(actionPerformed);
+ mocks.VerifyAll();
+ }
+
+ public interface ICalculationInputWithForeshoreProfile : ICalculationInput, IHasForeshoreProfile {}
+
+ #endregion
+
#region CreatePerformCalculationItem
[Test]