Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs =================================================================== diff -u -rb5accd775c390fa85f815ef13c3c3e54a6d10ada -r2545a8486f7c2820781ec3871125bdd8121622fd --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision b5accd775c390fa85f815ef13c3c3e54a6d10ada) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 2545a8486f7c2820781ec3871125bdd8121622fd) @@ -146,6 +146,8 @@ : Color.FromKnownColor(KnownColor.GrayText), ChildNodeObjects = context => context.WrappedData.Cast().ToArray(), ContextMenuStrip = (nodeData, parentData, treeViewControl) => Gui.Get(nodeData, treeViewControl) + .AddDeleteChildrenItem() + .AddSeparator() .AddImportItem() .AddSeparator() .AddExpandAllItem() @@ -158,8 +160,12 @@ Text = structure => structure.Name, Image = structure => RingtoetsCommonFormsResources.StructuresIcon, ContextMenuStrip = (structure, parentData, treeViewControl) => Gui.Get(structure, treeViewControl) + .AddDeleteItem() + .AddSeparator() .AddPropertiesItem() - .Build() + .Build(), + CanRemove = CanRemoveHeightStructure, + OnNodeRemoved = OnHeightStructureRemoved }; yield return new TreeNodeInfo @@ -222,6 +228,41 @@ return null; } + #region HeightStructure TreeNodeInfo + + private bool CanRemoveHeightStructure(HeightStructure nodeData, object parentData) + { + return parentData is HeightStructuresContext; + } + + private void OnHeightStructureRemoved(HeightStructure nodeData, object parentData) + { + var parentContext = (HeightStructuresContext) parentData; + var changedObservables = new List(); + StructuresCalculation[] grassCoverErosionInwardsCalculations = parentContext.ParentFailureMechanism.Calculations + .Cast>() + .ToArray(); + StructuresCalculation[] calculationWithRemovedHeightStructure = grassCoverErosionInwardsCalculations + .Where(c => ReferenceEquals(c.InputParameters.Structure, nodeData)) + .ToArray(); + foreach (StructuresCalculation calculation in calculationWithRemovedHeightStructure) + { + calculation.InputParameters.Structure = null; + StructuresHelper.Delete(parentContext.ParentFailureMechanism.SectionResults, calculation, grassCoverErosionInwardsCalculations); + changedObservables.Add(calculation.InputParameters); + } + + parentContext.WrappedData.Remove(nodeData); + changedObservables.Add(parentContext.WrappedData); + + foreach (IObservable observable in changedObservables) + { + observable.NotifyObservers(); + } + } + + #endregion + #region ViewInfo #region HeightStructuresFailureMechanismResultView ViewInfo @@ -295,7 +336,7 @@ { new FailureMechanismSectionsContext(failureMechanism, assessmentSection), new ForeshoreProfilesContext(failureMechanism.ForeshoreProfiles, failureMechanism, assessmentSection), - new HeightStructuresContext(failureMechanism.HeightStructures, assessmentSection), + new HeightStructuresContext(failureMechanism.HeightStructures, failureMechanism, assessmentSection), new CommentContext(failureMechanism) }; }