// Copyright (C) Stichting Deltares 2017. 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.Collections.Generic;
using Core.Common.Controls.DataGrid;
using Core.Common.Controls.Views;
using Core.Common.Gui.Commands;
using Ringtoets.Common.Data.Contribution;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Forms.Helpers;
namespace Ringtoets.Integration.Forms.Views
{
///
/// This class represents a row of .
///
internal class FailureMechanismContributionItemRow : IHasColumnStateDefinitions
{
private readonly IViewCommands viewCommands;
private readonly IFailureMechanism failureMechanism;
private readonly FailureMechanismContribution failureMechanismContribution;
private readonly int isRelevantColumnIndex;
private readonly int nameColumnIndex;
private readonly int codeColumnIndex;
private readonly int contributionColumnIndex;
private readonly int probabilitySpaceColumnIndex;
///
/// Fired when the row has started updating.
///
public EventHandler RowUpdated;
///
/// Fired when the row has finished updating.
///
public EventHandler RowUpdateDone;
///
/// Creates a new instance of .
///
/// The failure mechanism this row contains.
/// The failure mechanism contribution to get the norm from.
/// >Class responsible for exposing high level
/// related commands.
/// The property values required to create an instance of
/// .
/// Thrown when any parameter is null.
internal FailureMechanismContributionItemRow(IFailureMechanism failureMechanism, FailureMechanismContribution failureMechanismContribution,
IViewCommands viewCommands, ConstructionProperties constructionProperties)
{
if (failureMechanism == null)
{
throw new ArgumentNullException(nameof(failureMechanism));
}
if (failureMechanismContribution == null)
{
throw new ArgumentNullException(nameof(failureMechanismContribution));
}
if (viewCommands == null)
{
throw new ArgumentNullException(nameof(viewCommands));
}
if (constructionProperties == null)
{
throw new ArgumentNullException(nameof(constructionProperties));
}
this.failureMechanism = failureMechanism;
this.failureMechanismContribution = failureMechanismContribution;
this.viewCommands = viewCommands;
isRelevantColumnIndex = constructionProperties.IsRelevantColumnIndex;
nameColumnIndex = constructionProperties.NameColumnIndex;
codeColumnIndex = constructionProperties.CodeColumnIndex;
contributionColumnIndex = constructionProperties.ContributionColumnIndex;
probabilitySpaceColumnIndex = constructionProperties.ProbabilitySpaceColumnIndex;
CreateColumnStateDefinitions();
Update();
}
///
/// Gets .
///
public string Assessment
{
get
{
return failureMechanism.Name;
}
}
///
/// Gets .
///
public string Code
{
get
{
return failureMechanism.Code;
}
}
///
/// Gets .
///
public double Contribution
{
get
{
return failureMechanism.Contribution;
}
}
///
/// Gets .
///
public double ProbabilitySpace
{
get
{
return 100 / (failureMechanismContribution.Norm * failureMechanism.Contribution);
}
}
///
/// Gets or sets .
///
public bool IsRelevant
{
get
{
return failureMechanism.IsRelevant;
}
set
{
if (!value)
{
viewCommands.RemoveAllViewsForItem(failureMechanism);
}
failureMechanism.IsRelevant = value;
Update();
RowUpdated?.Invoke(this, EventArgs.Empty);
failureMechanism.NotifyObservers();
RowUpdateDone?.Invoke(this, EventArgs.Empty);
}
}
public IDictionary ColumnStateDefinitions { get; private set; }
public void Update()
{
if (!IsRelevant)
{
FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[nameColumnIndex]);
FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[codeColumnIndex]);
FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[contributionColumnIndex]);
FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[probabilitySpaceColumnIndex]);
}
else
{
FailureMechanismSectionResultRowHelper.EnableColumn(ColumnStateDefinitions[nameColumnIndex], true);
FailureMechanismSectionResultRowHelper.EnableColumn(ColumnStateDefinitions[codeColumnIndex], true);
FailureMechanismSectionResultRowHelper.EnableColumn(ColumnStateDefinitions[contributionColumnIndex], true);
FailureMechanismSectionResultRowHelper.EnableColumn(ColumnStateDefinitions[probabilitySpaceColumnIndex], true);
}
}
private void CreateColumnStateDefinitions()
{
ColumnStateDefinitions = new Dictionary
{
{
isRelevantColumnIndex, failureMechanism is OtherFailureMechanism
? DataGridViewColumnStateDefinitionFactory.CreateReadOnlyColumnStateDefinition()
: new DataGridViewColumnStateDefinition()
},
{
nameColumnIndex, DataGridViewColumnStateDefinitionFactory.CreateReadOnlyColumnStateDefinition()
},
{
codeColumnIndex, DataGridViewColumnStateDefinitionFactory.CreateReadOnlyColumnStateDefinition()
},
{
contributionColumnIndex, DataGridViewColumnStateDefinitionFactory.CreateReadOnlyColumnStateDefinition()
},
{
probabilitySpaceColumnIndex, DataGridViewColumnStateDefinitionFactory.CreateReadOnlyColumnStateDefinition()
}
};
}
///
/// Class holding the various construction parameters for .
///
internal class ConstructionProperties
{
///
/// Gets or sets the relevant column index.
///
public int IsRelevantColumnIndex { internal get; set; }
///
/// Gets or sets the name column index.
///
public int NameColumnIndex { internal get; set; }
///
/// Gets or sets the code column index.
///
public int CodeColumnIndex { internal get; set; }
///
/// Gets or sets the contribution column index.
///
public int ContributionColumnIndex { internal get; set; }
///
/// Gets or sets the probability space column index.
///
public int ProbabilitySpaceColumnIndex { internal get; set; }
}
}
}