Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs =================================================================== diff -u -rb5accd775c390fa85f815ef13c3c3e54a6d10ada -rd705284acf98d459d09b5b2afd48ec3a629c9a3f --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs (.../ClosingStructuresPlugin.cs) (revision b5accd775c390fa85f815ef13c3c3e54a6d10ada) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs (.../ClosingStructuresPlugin.cs) (revision d705284acf98d459d09b5b2afd48ec3a629c9a3f) @@ -24,6 +24,7 @@ using System.Drawing; using System.Linq; using System.Windows.Forms; +using Core.Common.Base; using Core.Common.Controls.TreeView; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms.ProgressDialog; @@ -125,6 +126,8 @@ ForeColor = context => context.WrappedData.Any() ? Color.FromKnownColor(KnownColor.ControlText) : Color.FromKnownColor(KnownColor.GrayText), ChildNodeObjects = context => context.WrappedData.Cast().ToArray(), ContextMenuStrip = (nodeData, parentData, treeViewControl) => Gui.Get(nodeData, treeViewControl) + .AddDeleteChildrenItem() + .AddSeparator() .AddImportItem() .AddSeparator() .AddExpandAllItem() @@ -137,8 +140,12 @@ Text = structure => structure.Name, Image = structure => RingtoetsCommonFormsResources.StructuresIcon, ContextMenuStrip = (structure, parentData, treeViewControl) => Gui.Get(structure, treeViewControl) + .AddDeleteItem() + .AddSeparator() .AddPropertiesItem() - .Build() + .Build(), + CanRemove = CanRemoveClosingStructure, + OnNodeRemoved = OnClosingStructureRemoved }; yield return new TreeNodeInfo @@ -289,7 +296,7 @@ { new FailureMechanismSectionsContext(failureMechanism, assessmentSection), new ForeshoreProfilesContext(failureMechanism.ForeshoreProfiles, failureMechanism, assessmentSection), - new ClosingStructuresContext(failureMechanism.ClosingStructures, assessmentSection), + new ClosingStructuresContext(failureMechanism.ClosingStructures, failureMechanism, assessmentSection), new CommentContext(failureMechanism) }; } @@ -620,6 +627,41 @@ #endregion + #region ClosingStructure TreeNodeInfo + + private bool CanRemoveClosingStructure(ClosingStructure nodeData, object parentData) + { + return parentData is ClosingStructuresContext; + } + + private void OnClosingStructureRemoved(ClosingStructure nodeData, object parentData) + { + var parentContext = (ClosingStructuresContext) parentData; + var changedObservables = new List(); + StructuresCalculation[] closingStructureCalculations = parentContext.ParentFailureMechanism.Calculations + .Cast>() + .ToArray(); + StructuresCalculation[] calculationWithRemovedClosingStructure = closingStructureCalculations + .Where(c => ReferenceEquals(c.InputParameters.Structure, nodeData)) + .ToArray(); + foreach (StructuresCalculation calculation in calculationWithRemovedClosingStructure) + { + calculation.InputParameters.Structure = null; + StructuresHelper.Delete(parentContext.ParentFailureMechanism.SectionResults, calculation, closingStructureCalculations); + changedObservables.Add(calculation.InputParameters); + } + + parentContext.WrappedData.Remove(nodeData); + changedObservables.Add(parentContext.WrappedData); + + foreach (IObservable observable in changedObservables) + { + observable.NotifyObservers(); + } + } + #endregion + + #endregion } } \ No newline at end of file