Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs =================================================================== diff -u -rada94ef2b6943fb9a2d8e59256871205a7d4c4ee -r7f714e8c05ea5fe684570b4e05db98af2346d0df --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision ada94ef2b6943fb9a2d8e59256871205a7d4c4ee) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 7f714e8c05ea5fe684570b4e05db98af2346d0df) @@ -508,12 +508,19 @@ return childNodeObjects.ToArray(); } - private ContextMenuStrip CalculationGroupContextContextMenuStrip(HeightStructuresCalculationGroupContext context, object parentData, TreeViewControl treeViewControl) + private ContextMenuStrip CalculationGroupContextContextMenuStrip(HeightStructuresCalculationGroupContext context, + object parentData, + TreeViewControl treeViewControl) { CalculationGroup group = context.WrappedData; var builder = new RingtoetsContextMenuBuilder(Gui.Get(context, treeViewControl)); + var inquiryHelper = new DialogBasedInquiryHelper(Gui.MainWindow); bool isNestedGroup = parentData is HeightStructuresCalculationGroupContext; + StructuresCalculation[] calculations = group + .GetCalculations() + .OfType>().ToArray(); + builder.AddImportItem() .AddExportItem() .AddSeparator(); @@ -533,7 +540,10 @@ builder.AddRenameItem(); } - builder.AddCustomItem(CreateUpdateStructureItem(context)) + builder.AddUpdateForeshoreProfileOfCalculationsItem(calculations, + inquiryHelper, + SynchronizeCalculationWithForeshoreProfileHelper.UpdateForeshoreProfileDerivedCalculationInput) + .AddCustomItem(CreateUpdateStructureItem(calculations)) .AddSeparator() .AddValidateAllCalculationsInGroupItem( context, @@ -564,12 +574,8 @@ .Build(); } - private StrictContextMenuItem CreateUpdateStructureItem(HeightStructuresCalculationGroupContext nodeData) + private StrictContextMenuItem CreateUpdateStructureItem(StructuresCalculation[] calculations) { - IEnumerable> calculations = nodeData.WrappedData - .GetCalculations() - .OfType>(); - var contextMenuEnabled = true; string toolTipText = RingtoetsCommonFormsResources.StructuresPlugin_CreateUpdateStructureItem_Update_all_calculations_with_Structure_Tooltip; if (!calculations.Any()) Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -rdad191ad1ec7648b4ead227124aa1df4b612bd45 -r7f714e8c05ea5fe684570b4e05db98af2346d0df --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision dad191ad1ec7648b4ead227124aa1df4b612bd45) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 7f714e8c05ea5fe684570b4e05db98af2346d0df) @@ -62,17 +62,19 @@ private const int contextMenuGenerateCalculationsIndexRootGroup = 3; private const int contextMenuAddCalculationGroupIndexRootGroup = 5; private const int contextMenuAddCalculationIndexRootGroup = 6; - private const int contextMenuUpdateStructureAllIndexRootGroup = 8; - private const int contextMenuValidateAllIndexRootGroup = 10; - private const int contextMenuCalculateAllIndexRootGroup = 11; - private const int contextMenuClearAllIndexRootGroup = 13; + private const int contextMenuUpdateForeshoreProfileIndexRootGroup = 8; + private const int contextMenuUpdateStructureAllIndexRootGroup = 9; + private const int contextMenuValidateAllIndexRootGroup = 11; + private const int contextMenuCalculateAllIndexRootGroup = 12; + private const int contextMenuClearAllIndexRootGroup = 14; private const int contextMenuAddCalculationGroupIndexNestedGroup = 3; private const int contextMenuAddCalculationIndexNestedGroup = 4; - private const int contextMenuUpdateStructureAllIndexNestedGroup = 7; - private const int contextMenuValidateAllIndexNestedGroup = 9; - private const int contextMenuCalculateAllIndexNestedGroup = 10; - private const int contextMenuClearAllIndexNestedGroup = 12; + private const int contextMenuUpdateForeshoreProfileIndexNestedGroup = 7; + private const int contextMenuUpdateStructureAllIndexNestedGroup = 8; + private const int contextMenuValidateAllIndexNestedGroup = 10; + private const int contextMenuCalculateAllIndexNestedGroup = 11; + private const int contextMenuClearAllIndexNestedGroup = 13; private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "HydraulicBoundaryDatabaseImporter"); private IGui guiStub; @@ -199,6 +201,7 @@ menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); @@ -215,9 +218,9 @@ using (var treeViewControl = new TreeViewControl()) { - guiStub.Stub(cmp => cmp.Get(groupContext, treeViewControl)).Return(menuBuilderMock); - guiStub.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); - + guiStub.Stub(g => g.Get(groupContext, treeViewControl)).Return(menuBuilderMock); + guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); mocks.ReplayAll(); // Call @@ -242,15 +245,15 @@ using (var treeViewControl = new TreeViewControl()) { guiStub.Stub(g => g.Get(groupContext, treeViewControl)).Return(menuBuilder); - guiStub.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); - + guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); mocks.ReplayAll(); // Call using (ContextMenuStrip menu = info.ContextMenuStrip(groupContext, null, treeViewControl)) { // Assert - Assert.AreEqual(20, menu.Items.Count); + Assert.AreEqual(21, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuGenerateCalculationsIndexRootGroup, "Genereer &berekeningen...", @@ -266,6 +269,11 @@ "Voeg een nieuwe berekening toe aan deze berekeningsmap.", RingtoetsCommonFormsResources.FailureMechanismIcon); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuUpdateForeshoreProfileIndexRootGroup, + "&Bijwerken voorlandprofielen...", + "De geselecteerde voorlandprofielen hebben geen wijzigingen om bij te werken.", + RingtoetsCommonFormsResources.UpdateItemIcon, + false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuUpdateStructureAllIndexRootGroup, "&Bijwerken kunstwerken", @@ -313,15 +321,15 @@ using (var treeViewControl = new TreeViewControl()) { guiStub.Stub(g => g.Get(groupContext, treeViewControl)).Return(menuBuilder); - guiStub.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); - + guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); mocks.ReplayAll(); // Call using (ContextMenuStrip menu = info.ContextMenuStrip(groupContext, null, treeViewControl)) { // Assert - Assert.AreEqual(20, menu.Items.Count); + Assert.AreEqual(21, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuGenerateCalculationsIndexRootGroup, "Genereer &berekeningen...", @@ -357,6 +365,7 @@ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddRenameItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); @@ -373,8 +382,8 @@ using (var treeViewControl = new TreeViewControl()) { - guiStub.Stub(cmp => cmp.Get(groupContext, treeViewControl)).Return(menuBuilderMock); - + guiStub.Stub(g => g.Get(groupContext, treeViewControl)).Return(menuBuilderMock); + guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); mocks.ReplayAll(); // Call @@ -400,17 +409,17 @@ assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - mocks.ReplayAll(); - using (var treeViewControl = new TreeViewControl()) { guiStub.Stub(g => g.Get(groupContext, treeViewControl)).Return(menuBuilder); + guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); // Call using (ContextMenuStrip menu = info.ContextMenuStrip(groupContext, parentGroupContext, treeViewControl)) { // Assert - Assert.AreEqual(19, menu.Items.Count); + Assert.AreEqual(20, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationGroupIndexNestedGroup, "&Map toevoegen", @@ -421,6 +430,11 @@ "Voeg een nieuwe berekening toe aan deze berekeningsmap.", RingtoetsCommonFormsResources.FailureMechanismIcon); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuUpdateForeshoreProfileIndexNestedGroup, + "&Bijwerken voorlandprofielen...", + "De geselecteerde voorlandprofielen hebben geen wijzigingen om bij te werken.", + RingtoetsCommonFormsResources.UpdateItemIcon, + false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuUpdateStructureAllIndexNestedGroup, "&Bijwerken kunstwerken", @@ -472,8 +486,8 @@ using (var treeViewControl = new TreeViewControl()) { guiStub.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - guiStub.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); - + guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); mocks.ReplayAll(); // Call @@ -514,8 +528,8 @@ using (var treeViewControl = new TreeViewControl()) { guiStub.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - guiStub.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); - + guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); mocks.ReplayAll(); assessmentSection.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); @@ -567,8 +581,8 @@ using (var treeViewControl = new TreeViewControl()) { guiStub.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - guiStub.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); - + guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); mocks.ReplayAll(); // Call @@ -617,8 +631,8 @@ using (var treeViewControl = new TreeViewControl()) { guiStub.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - guiStub.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); - + guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); mocks.ReplayAll(); // Call @@ -659,8 +673,8 @@ using (var treeViewControl = new TreeViewControl()) { guiStub.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - guiStub.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); - + guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); mocks.ReplayAll(); // Call @@ -702,8 +716,8 @@ using (var treeViewControl = new TreeViewControl()) { guiStub.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - guiStub.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); - + guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); mocks.ReplayAll(); // Call @@ -753,8 +767,8 @@ using (var treeViewControl = new TreeViewControl()) { guiStub.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - guiStub.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); - + guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); mocks.ReplayAll(); // Call @@ -803,8 +817,8 @@ using (var treeViewControl = new TreeViewControl()) { guiStub.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - guiStub.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); - + guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); mocks.ReplayAll(); // Call @@ -820,6 +834,113 @@ } [Test] + public void ContextMenuStrip_WithForeshoreProfileAndChanges_ContextMenuItemUpdateForeshoreProfilesEnabled() + { + // Setup + var assessmentSectionStub = mocks.Stub(); + var failureMechanism = new TestHeightStructuresFailureMechanism(); + var calculation = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile() + } + }; + calculation.InputParameters.UseBreakWater = true; + + var nodeData = new HeightStructuresCalculationGroupContext( + new CalculationGroup + { + Children = + { + calculation + } + }, + failureMechanism, + assessmentSectionStub); + + using (var treeViewControl = new TreeViewControl()) + { + guiStub.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + guiStub.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = guiStub; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, + contextMenuUpdateForeshoreProfileIndexRootGroup, + "&Bijwerken voorlandprofielen...", + "Berekeningen bijwerken waar een voorlandprofiel geselecteerd is.", + RingtoetsCommonFormsResources.UpdateItemIcon); + } + } + } + + [Test] + public void GivenCalculationWithForeshoreProfileSet_WhenUpdatingForeshoreProfileFromContextMenu_ThenCalculationUpdatedAndUpdateObserver() + { + // Given + var calculationObserver = mocks.StrictMock(); + var calculationInputObserver = mocks.StrictMock(); + calculationInputObserver.Expect(o => o.UpdateObserver()); + + var assessmentSectionStub = mocks.Stub(); + var failureMechanism = new TestHeightStructuresFailureMechanism(); + + var calculation = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(true) + } + }; + calculation.InputParameters.UseBreakWater = false; + + var nodeData = new HeightStructuresCalculationGroupContext( + new CalculationGroup + { + Children = + { + calculation + } + }, + failureMechanism, + assessmentSectionStub); + + calculation.Attach(calculationObserver); + calculation.InputParameters.Attach(calculationInputObserver); + + using (var treeViewControl = new TreeViewControl()) + { + guiStub.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + guiStub.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = guiStub; + + using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Precondition + TestHelper.AssertContextMenuStripContainsItem(contextMenuStrip, + contextMenuUpdateForeshoreProfileIndexRootGroup, + "&Bijwerken voorlandprofielen...", + "Berekeningen bijwerken waar een voorlandprofiel geselecteerd is.", + RingtoetsCommonFormsResources.UpdateItemIcon); + + // When + contextMenuStrip.Items[contextMenuUpdateForeshoreProfileIndexRootGroup].PerformClick(); + + // Then + Assert.IsTrue(calculation.InputParameters.UseBreakWater); + } + } + } + + [Test] public void ContextMenuStrip_ClickOnCalculateAllItem_ScheduleAllChildCalculations() { // Setup @@ -861,7 +982,7 @@ { guiStub.Stub(g => g.Get(groupContext, treeViewControl)).Return(menuBuilder); guiStub.Stub(g => g.MainWindow).Return(mainWindowStub); - guiStub.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); @@ -938,8 +1059,8 @@ using (var treeViewControl = new TreeViewControl()) { guiStub.Stub(g => g.Get(groupContext, treeViewControl)).Return(menuBuilder); - guiStub.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); - + guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); mocks.ReplayAll(); using (ContextMenuStrip contextMenu = info.ContextMenuStrip(groupContext, null, treeViewControl)) @@ -981,9 +1102,9 @@ using (var treeViewControl = new TreeViewControl()) { - guiStub.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); - guiStub.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); - + guiStub.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); mocks.ReplayAll(); group.Children.Add(calculationGroup); @@ -1027,9 +1148,9 @@ using (var treeViewControl = new TreeViewControl()) { - guiStub.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); - guiStub.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); - + guiStub.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); mocks.ReplayAll(); group.Children.Add(calculation); @@ -1067,7 +1188,8 @@ using (var treeViewControl = new TreeViewControl()) { - guiStub.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + guiStub.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); mocks.ReplayAll(); // Call @@ -1103,7 +1225,8 @@ using (var treeViewControl = new TreeViewControl()) { - guiStub.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + guiStub.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); mocks.ReplayAll(); // Call @@ -1146,6 +1269,7 @@ using (var treeViewControl = new TreeViewControl()) { guiStub.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); mocks.ReplayAll(); // Call