Index: Riskeer/DuneErosion/src/Riskeer.DuneErosion.Forms/Views/DuneLocationCalculationsView.cs =================================================================== diff -u -r3cecf6aa924b24586868d84962d7eb5f45496769 -re6622516721bba24cb2ca24555b1f634d9b005d7 --- Riskeer/DuneErosion/src/Riskeer.DuneErosion.Forms/Views/DuneLocationCalculationsView.cs (.../DuneLocationCalculationsView.cs) (revision 3cecf6aa924b24586868d84962d7eb5f45496769) +++ Riskeer/DuneErosion/src/Riskeer.DuneErosion.Forms/Views/DuneLocationCalculationsView.cs (.../DuneLocationCalculationsView.cs) (revision e6622516721bba24cb2ca24555b1f634d9b005d7) @@ -56,78 +56,14 @@ DuneErosionFailureMechanism failureMechanism, IAssessmentSection assessmentSection, Func getTargetProbabilityFunc, - Func getCalculationIdentifierFunc) + Func getCalculationIdentifierFunc) : base(calculations, failureMechanism, assessmentSection, getTargetProbabilityFunc, getCalculationIdentifierFunc) { - if (calculations == null) - { - throw new ArgumentNullException(nameof(calculations)); - } - - if (failureMechanism == null) - { - throw new ArgumentNullException(nameof(failureMechanism)); - } - - if (assessmentSection == null) - { - throw new ArgumentNullException(nameof(assessmentSection)); - } - - if (getTargetProbabilityFunc == null) - { - throw new ArgumentNullException(nameof(getTargetProbabilityFunc)); - } - - if (getCalculationIdentifierFunc == null) - { - throw new ArgumentNullException(nameof(getCalculationIdentifierFunc)); - } - InitializeComponent(); - - this.calculations = calculations; - this.getTargetProbabilityFunc = getTargetProbabilityFunc; - this.getCalculationIdentifierFunc = getCalculationIdentifierFunc; - FailureMechanism = failureMechanism; - AssessmentSection = assessmentSection; - - duneLocationCalculationsObserver = new Observer(UpdateDataGridViewDataSource) - { - Observable = calculations - }; - - duneLocationCalculationObserver = new RecursiveObserver, DuneLocationCalculation>(() => dataGridViewControl.RefreshDataGridView(), list => list) - { - Observable = calculations - }; - - failureMechanismObserver = new Observer(UpdateCalculateForSelectedButton) - { - Observable = failureMechanism - }; - UpdateDataGridViewDataSource(); } public override object Data { get; set; } - /// - /// Gets the assessment section. - /// - public IAssessmentSection AssessmentSection { get; } - - /// - /// Gets the for which the - /// calculations are shown. - /// - public DuneErosionFailureMechanism FailureMechanism { get; } - - /// - /// Gets or sets the - /// to perform calculations with. - /// - public DuneLocationCalculationGuiService CalculationGuiService { get; set; } - protected override void Dispose(bool disposing) { duneLocationCalculationsObserver.Dispose(); Index: Riskeer/DuneErosion/src/Riskeer.DuneErosion.Forms/Views/DuneLocationCalculationsViewBase.cs =================================================================== diff -u -r664ea533634f90fcabc7ec85ee0808714936abba -re6622516721bba24cb2ca24555b1f634d9b005d7 --- Riskeer/DuneErosion/src/Riskeer.DuneErosion.Forms/Views/DuneLocationCalculationsViewBase.cs (.../DuneLocationCalculationsViewBase.cs) (revision 664ea533634f90fcabc7ec85ee0808714936abba) +++ Riskeer/DuneErosion/src/Riskeer.DuneErosion.Forms/Views/DuneLocationCalculationsViewBase.cs (.../DuneLocationCalculationsViewBase.cs) (revision e6622516721bba24cb2ca24555b1f634d9b005d7) @@ -23,10 +23,13 @@ using System.Collections.Generic; using System.Linq; using System.Windows.Forms; +using Core.Common.Base; using Core.Common.Controls.Views; using Core.Common.Util.Extensions; +using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Forms.Properties; using Riskeer.DuneErosion.Data; +using Riskeer.DuneErosion.Forms.GuiServices; namespace Riskeer.DuneErosion.Forms.Views { @@ -35,15 +38,79 @@ /// public abstract partial class DuneLocationCalculationsViewBase : UserControl, ISelectionProvider, IView { + private readonly Observer failureMechanismObserver; + private readonly Observer duneLocationCalculationsObserver; + private readonly IObservableEnumerable calculations; + private readonly Func getTargetProbabilityFunc; + private readonly Func getCalculationIdentifierFunc; + private readonly RecursiveObserver, DuneLocationCalculation> duneLocationCalculationObserver; + private const int calculateColumnIndex = 0; private bool updatingDataSource; public event EventHandler SelectionChanged; /// - /// Creates a new instance of . + /// Creates a new instance of . /// - protected DuneLocationCalculationsViewBase() + /// The calculations to show in the view. + /// The failure mechanism which the calculations belong to. + /// The assessment section which the calculations belong to. + /// for getting the target probability to use during calculations. + /// for getting the calculation identifier to use in all messages. + /// Thrown when any parameter is null. + protected DuneLocationCalculationsViewBase(IObservableEnumerable calculations, + DuneErosionFailureMechanism failureMechanism, + IAssessmentSection assessmentSection, + Func getTargetProbabilityFunc, + Func getCalculationIdentifierFunc) { + if (calculations == null) + { + throw new ArgumentNullException(nameof(calculations)); + } + + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + if (getTargetProbabilityFunc == null) + { + throw new ArgumentNullException(nameof(getTargetProbabilityFunc)); + } + + if (getCalculationIdentifierFunc == null) + { + throw new ArgumentNullException(nameof(getCalculationIdentifierFunc)); + } + + this.calculations = calculations; + this.getTargetProbabilityFunc = getTargetProbabilityFunc; + this.getCalculationIdentifierFunc = getCalculationIdentifierFunc; + FailureMechanism = failureMechanism; + AssessmentSection = assessmentSection; + + duneLocationCalculationsObserver = new Observer(UpdateDataGridViewDataSource) + { + Observable = calculations + }; + + duneLocationCalculationObserver = new RecursiveObserver, DuneLocationCalculation>(() => dataGridViewControl.RefreshDataGridView(), list => list) + { + Observable = calculations + }; + + failureMechanismObserver = new Observer(UpdateCalculateForSelectedButton) + { + Observable = failureMechanism + }; + + InitializeComponent(); LocalizeControls(); InitializeEventHandlers(); @@ -58,7 +125,24 @@ } public abstract object Data { get; set; } + + /// + /// Gets or sets the + /// to perform calculations with. + /// + public DuneLocationCalculationGuiService CalculationGuiService { get; set; } + /// + /// Gets the assessment section. + /// + public IAssessmentSection AssessmentSection { get; } + + /// + /// Gets the for which the + /// calculations are shown. + /// + public DuneErosionFailureMechanism FailureMechanism { get; } + protected override void OnLoad(EventArgs e) { base.OnLoad(e); @@ -71,6 +155,10 @@ { components?.Dispose(); } + + duneLocationCalculationsObserver.Dispose(); + duneLocationCalculationObserver.Dispose(); + failureMechanismObserver.Dispose(); base.Dispose(disposing); }