// 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.Collections.Generic;
using System.ComponentModel;
using Core.Common.Base;
using Core.Common.Gui.Attributes;
using Core.Common.Gui.PropertyBag;
using Core.Common.Utils;
using Core.Common.Utils.Attributes;
using Core.Common.Utils.Reflection;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.Contribution;
using Ringtoets.Integration.Forms.Properties;
using Ringtoets.Integration.Forms.Views;
using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources;
namespace Ringtoets.Integration.Forms.PropertyClasses
{
///
/// ViewModel of for properties panel.
///
public class FailureMechanismContributionProperties : ObjectProperties
{
private IFailureMechanismContributionNormChangeHandler normChangeHandler;
private IAssessmentSectionCompositionChangeHandler compositionChangeHandler;
[TypeConverter(typeof(EnumTypeConverter))]
[ResourcesCategory(typeof(RingtoetsCommonFormsResources), "Categories_General")]
[ResourcesDisplayName(typeof(Resources), "FailureMechanismContribution_Composition_DisplayName")]
[ResourcesDescription(typeof(Resources), "FailureMechanismContribution_Composition_Description")]
public AssessmentSectionComposition AssessmentSectionComposition
{
get
{
return AssessmentSection.Composition;
}
set
{
if (compositionChangeHandler.ConfirmCompositionChange())
{
IEnumerable changedObjects = compositionChangeHandler.ChangeComposition(AssessmentSection, value);
foreach (IObservable changedObject in changedObjects)
{
changedObject.NotifyObservers();
}
data.NotifyObservers();
}
}
}
[ResourcesCategory(typeof(RingtoetsCommonFormsResources), "Categories_General")]
[ResourcesDisplayName(typeof(Resources), "FailureMechanismContribution_ReturnPeriod_DisplayName")]
[ResourcesDescription(typeof(Resources), "FailureMechanismContribution_ReturnPeriod_Description")]
public int ReturnPeriod
{
get
{
return Convert.ToInt32(1.0/data.Norm);
}
set
{
if (value < 100 || value > 1000000)
{
throw new ArgumentOutOfRangeException("value", Resources.FailureMechanismContributionContextProperties_ReturnPeriod_Value_for_ReturnPeriod_Must_be_in_range_100_to_1000000);
}
if (value != 0 && normChangeHandler.ConfirmNormChange())
{
double newNormValue = 1.0/Convert.ToInt32(value);
IEnumerable changedObjects = normChangeHandler.ChangeNorm(AssessmentSection, newNormValue);
foreach (IObservable changedObject in changedObjects)
{
changedObject.NotifyObservers();
}
}
}
}
///
/// Gets or sets the assessment section this property control belongs to.
///
[DynamicVisible]
public IAssessmentSection AssessmentSection { get; set; }
///
/// Gets or sets the for when the norm changes.
///
/// Thrown when null is set.
[DynamicVisible]
public IFailureMechanismContributionNormChangeHandler NormChangeHandler
{
get
{
return normChangeHandler;
}
set
{
if (value == null)
{
throw new ArgumentNullException("value", @"NormChangeHandler is null");
}
normChangeHandler = value;
}
}
///
/// Gets or sets the for when the norm changes.
///
/// Thrown when null is set.
[DynamicVisible]
public IAssessmentSectionCompositionChangeHandler CompositionChangeHandler
{
get
{
return compositionChangeHandler;
}
set
{
if (value == null)
{
throw new ArgumentNullException("value", @"CompositionChangeHandler is null");
}
compositionChangeHandler = value;
}
}
[DynamicVisibleValidationMethod]
public bool DynamicVisibleValidationMethod(string propertyName)
{
// Hide all the properties that are used to set the data
return propertyName != TypeUtils.GetMemberName(p => p.AssessmentSection)
&& propertyName != TypeUtils.GetMemberName(p => p.NormChangeHandler)
&& propertyName != TypeUtils.GetMemberName(p => p.CompositionChangeHandler);
}
}
}