Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsInputView.cs
===================================================================
diff -u -re0868fe8d1c342d98fcb16a0273353fcf697d1c0 -rf9aefa56762ac1dd731bc4bfed955d651781d598
--- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsInputView.cs (.../GrassCoverErosionInwardsInputView.cs) (revision e0868fe8d1c342d98fcb16a0273353fcf697d1c0)
+++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsInputView.cs (.../GrassCoverErosionInwardsInputView.cs) (revision f9aefa56762ac1dd731bc4bfed955d651781d598)
@@ -33,10 +33,11 @@
///
/// This class is a view to show the grass cover erosion inwards input.
///
- public partial class GrassCoverErosionInwardsInputView : UserControl, IChartView, IObserver
+ public partial class GrassCoverErosionInwardsInputView : UserControl, IChartView
{
- private GrassCoverErosionInwardsInput data;
- private GrassCoverErosionInwardsCalculation calculation;
+ private readonly Observer calculationObserver;
+ private readonly Observer calculationInputObserver;
+ private GrassCoverErosionInwardsCalculation data;
private ChartData dikeProfileData;
private ChartData foreshoreData;
private ChartData dikeHeightData;
@@ -47,24 +48,9 @@
public GrassCoverErosionInwardsInputView()
{
InitializeComponent();
- }
- ///
- /// Gets or sets the calculation the input belongs to.
- ///
- public GrassCoverErosionInwardsCalculation Calculation
- {
- get
- {
- return calculation;
- }
- set
- {
- DetachFromData();
- calculation = value;
- SetChartTitle();
- AttachToData();
- }
+ calculationObserver = new Observer(SetChartTitle);
+ calculationInputObserver = new Observer(SetDataToChart);
}
public object Data
@@ -75,19 +61,19 @@
}
set
{
- var newValue = value as GrassCoverErosionInwardsInput;
+ data = value as GrassCoverErosionInwardsCalculation;
- DetachFromData();
- data = newValue;
+ calculationObserver.Observable = data;
+ calculationInputObserver.Observable = data != null ? data.InputParameters : null;
if (data == null)
{
Chart.ResetChartData();
return;
}
+ SetChartTitle();
SetDataToChart();
- AttachToData();
}
}
@@ -99,12 +85,27 @@
}
}
- public void UpdateObserver()
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
{
- SetChartTitle();
- SetDataToChart();
+ calculationObserver.Dispose();
+ calculationInputObserver.Dispose();
+
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
}
+ private void SetChartTitle()
+ {
+ chartControl.ChartTitle = data != null ? data.Name : string.Empty;
+ }
+
private void SetDataToChart()
{
chartControl.Data.Name = Resources.GrassCoverErosionInwardsInputContext_NodeDisplayName;
@@ -123,32 +124,32 @@
private ChartData GetForeshoreData()
{
- if (data == null || data.DikeProfile == null || !data.ForeshoreGeometry.Any() || !data.UseForeshore)
+ if (!HasForeshorePoints())
{
return ChartDataFactory.CreateEmptyLineData(Resources.Foreshore_DisplayName);
}
- return GrassCoverErosionInwardsChartDataFactory.Create(data.ForeshoreGeometry, data.DikeProfile.Name);
+ return GrassCoverErosionInwardsChartDataFactory.Create(data.InputParameters.ForeshoreGeometry, data.InputParameters.DikeProfile.Name);
}
private ChartData GetDikeProfileData()
{
- if (data == null || data.DikeProfile == null || !data.DikeGeometry.Any())
+ if (!HasDikeProfilePoints())
{
return ChartDataFactory.CreateEmptyLineData(Resources.DikeProfile_DisplayName);
}
- return GrassCoverErosionInwardsChartDataFactory.Create(data.DikeGeometry, data.DikeProfile.Name);
+ return GrassCoverErosionInwardsChartDataFactory.Create(data.InputParameters.DikeGeometry, data.InputParameters.DikeProfile.Name);
}
private ChartData GetDikeHeightData()
{
- if (data == null || data.DikeProfile == null || !data.DikeGeometry.Any())
+ if (!HasDikeProfilePoints())
{
return ChartDataFactory.CreateEmptyLineData(Resources.DikeHeight_ChartName);
}
- return GrassCoverErosionInwardsChartDataFactory.Create(data.DikeHeight, data.DikeGeometry, data.DikeProfile.Name);
+ return GrassCoverErosionInwardsChartDataFactory.Create(data.InputParameters.DikeHeight, data.InputParameters.DikeGeometry, data.InputParameters.DikeProfile.Name);
}
private ChartData AddOrUpdateChartData(ChartData oldChartData, ChartData newChartData)
@@ -165,35 +166,15 @@
return newChartData;
}
- private void SetChartTitle()
+ private bool HasForeshorePoints()
{
- chartControl.ChartTitle = calculation != null ? calculation.Name : string.Empty;
+ return data != null && data.InputParameters.DikeProfile != null && data.InputParameters.ForeshoreGeometry.Any() && data.InputParameters.UseForeshore;
}
- private void DetachFromData()
- {
- if (calculation != null)
- {
- calculation.Detach(this);
- }
- if (data != null)
- {
- data.Detach(this);
- }
- }
-
- private void AttachToData()
+ private bool HasDikeProfilePoints()
{
- if (calculation != null)
- {
- calculation.Attach(this);
- }
-
- if (data != null)
- {
- data.Attach(this);
- }
+ return data != null && data.InputParameters.DikeProfile != null && data.InputParameters.DikeGeometry.Any();
}
}
}
\ No newline at end of file