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);