// Copyright (C) Stichting Deltares 2016. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Windows.Forms; using Core.Common.Gui.ContextMenu; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Forms.PresentationObjects; namespace Ringtoets.Common.Forms.TreeNodeInfos { /// /// Decorator for . /// public class RingtoetsContextMenuBuilder { private readonly IContextMenuBuilder contextMenuBuilder; /// /// Creates a new instance of the class. /// /// The context menu builder to decorate. public RingtoetsContextMenuBuilder(IContextMenuBuilder contextMenuBuilder) { this.contextMenuBuilder = contextMenuBuilder; } /// /// Adds an item to the , which adds a new calculation group to a calculation group. /// /// The calculation group to add the new calculation groups to. /// The itself. public RingtoetsContextMenuBuilder AddCreateCalculationGroupItem(CalculationGroup calculationGroup) { contextMenuBuilder.AddCustomItem(RingtoetsContextMenuItemFactory.CreateAddCalculationGroupItem(calculationGroup)); return this; } /// /// Adds an item to the , which adds a new calculation to a calculation group. /// /// The type of the calculation group context. /// The calculation group context belonging to the calculation group. /// The action for adding a calculation to the calculation group. /// The itself. public RingtoetsContextMenuBuilder AddCreateCalculationItem( TCalculationContext calculationGroupContext, Action addCalculationAction) where TCalculationContext : ICalculationContext { contextMenuBuilder.AddCustomItem(RingtoetsContextMenuItemFactory.CreateAddCalculationItem(calculationGroupContext, addCalculationAction)); return this; } /// /// Adds an item to the , which clears the output of all calculations in a calculation group. /// /// The calculation group to clear the output for. /// The itself. public RingtoetsContextMenuBuilder AddClearAllCalculationOutputInGroupItem(CalculationGroup calculationGroup) { contextMenuBuilder.AddCustomItem(RingtoetsContextMenuItemFactory.CreateClearAllCalculationOutputInGroupItem(calculationGroup)); return this; } /// /// Adds an item to the , which performs all calculations in a calculation group. /// /// The type of the calculation group context. /// The calculation group to perform all calculations for. /// The calculation group context belonging to the calculation group. /// The action that performs all calculations. /// The func that checks if the item is enabled. /// The itself. public RingtoetsContextMenuBuilder AddPerformAllCalculationsInGroupItem( CalculationGroup calculationGroup, TCalculationContext calculationGroupContext, Action calculateAllAction, Func isEnabledFunc) where TCalculationContext : ICalculationContext { contextMenuBuilder.AddCustomItem(RingtoetsContextMenuItemFactory.CreatePerformAllCalculationsInGroupItem(calculationGroup, calculationGroupContext, calculateAllAction, isEnabledFunc)); return this; } /// /// Adds an item to the , which performs a calculation. /// /// The type of the calculation. /// The type of the calculation context. /// The calculation to perform. /// The calculation context belonging to the calculation. /// The action that performs the calculation. /// The func that checks if the item is enabled. /// The itself. public RingtoetsContextMenuBuilder AddPerformCalculationItem( TCalculation calculation, TCalculationContext calculationContext, Action calculateAction, Func isEnabledFunc) where TCalculationContext : ICalculationContext where TCalculation : ICalculation { contextMenuBuilder.AddCustomItem(RingtoetsContextMenuItemFactory.CreatePerformCalculationItem(calculation, calculationContext, calculateAction, isEnabledFunc)); return this; } /// /// Adds an item to the , which clears the output of a calculation. /// /// The calculation to clear the output for. /// The itself. public RingtoetsContextMenuBuilder AddClearCalculationOutputItem(ICalculation calculation) { contextMenuBuilder.AddCustomItem(RingtoetsContextMenuItemFactory.CreateClearCalculationOutputItem(calculation)); return this; } /// /// Adds an item to the , which clears the output of all calculations in the failure mechanism. /// /// The failure mechanism to clear the output for. /// The itself. public RingtoetsContextMenuBuilder AddClearAllCalculationOutputInFailureMechanismItem(IFailureMechanism failureMechanism) { contextMenuBuilder.AddCustomItem(RingtoetsContextMenuItemFactory.CreateClearAllCalculationOutputInFailureMechanismItem(failureMechanism)); return this; } /// /// Adds an item to the , which performs all calculations in a failure mechanism. /// /// The type of the failure mechanism context. /// The failure mechanism context belonging to the failure mechanism. /// The action that performs all calculations. /// The func that checks if the item is enabled. /// The itself. public RingtoetsContextMenuBuilder AddPerformAllCalculationsInFailureMechanismItem( TFailureMechanismContext failureMechanismContext, Action calculateAllAction, Func isEnabledFunc) where TFailureMechanismContext : IFailureMechanismContext { contextMenuBuilder.AddCustomItem(RingtoetsContextMenuItemFactory.CreatePerformAllCalculationsInFailureMechanismItem(failureMechanismContext, calculateAllAction, isEnabledFunc)); return this; } /// /// Adds an item to the , which sets if the failure mechanism is relevant. /// /// The type of the failure mechanism context. /// The failure mechanism context belonging to the failure mechanism. /// The action to perform when relevance changes. /// The itself. public RingtoetsContextMenuBuilder AddToggleRelevancyOfFailureMechanismItem( TFailureMechanismContext failureMechanismContext, Action onChangeAction) where TFailureMechanismContext : IFailureMechanismContext { contextMenuBuilder.AddCustomItem(RingtoetsContextMenuItemFactory.CreateToggleRelevancyOfFailureMechanismItem(failureMechanismContext, onChangeAction)); return this; } # region Decorated members /// /// Adds an item to the , which starts edit mode for the name of . /// /// The itself. public RingtoetsContextMenuBuilder AddRenameItem() { contextMenuBuilder.AddRenameItem(); return this; } /// /// Adds an item to the , which deletes the . /// /// The itself. public RingtoetsContextMenuBuilder AddDeleteItem() { contextMenuBuilder.AddDeleteItem(); return this; } /// /// Adds an item to the , which expands the . /// /// The itself. public RingtoetsContextMenuBuilder AddExpandAllItem() { contextMenuBuilder.AddExpandAllItem(); return this; } /// /// Adds an item to the , which collapses the . /// /// The itself. public RingtoetsContextMenuBuilder AddCollapseAllItem() { contextMenuBuilder.AddCollapseAllItem(); return this; } /// /// Adds an item to the , which opens a view for the data of the . /// /// The itself. public RingtoetsContextMenuBuilder AddOpenItem() { contextMenuBuilder.AddOpenItem(); return this; } /// /// Adds an item to the , which exports the data of the . /// /// The itself. public RingtoetsContextMenuBuilder AddExportItem() { contextMenuBuilder.AddExportItem(); return this; } /// /// Adds an item to the , which imports to the data of the . /// /// The itself. public RingtoetsContextMenuBuilder AddImportItem() { contextMenuBuilder.AddImportItem(); return this; } /// /// Adds an item to the , which shows properties of the data of the . /// /// The itself. public RingtoetsContextMenuBuilder AddPropertiesItem() { contextMenuBuilder.AddPropertiesItem(); return this; } /// /// Adds a to the . A /// is only added if the last item that was added to the exists and is not a /// . /// /// The itself. public RingtoetsContextMenuBuilder AddSeparator() { contextMenuBuilder.AddSeparator(); return this; } /// /// Adds a custom item to the . /// /// The custom to add to the . /// The itself. public RingtoetsContextMenuBuilder AddCustomItem(StrictContextMenuItem item) { contextMenuBuilder.AddCustomItem(item); return this; } /// /// Obtain the , which has been constructed by using the other methods of /// . /// /// The constructed . public ContextMenuStrip Build() { return contextMenuBuilder.Build(); } # endregion } }