// Copyright (C) Stichting Deltares 2019. All rights reserved. // // This file is part of Riskeer. // // Riskeer is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser 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 Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser 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.Drawing; using Core.Common.Controls.Views; namespace Core.Common.Gui.Plugin { /// /// Information for creating a view for a particular data object. /// public class ViewInfo { /// /// Initializes a new instance of the class. /// public ViewInfo() { CreateInstance = o => (IView) Activator.CreateInstance(ViewType); } /// /// Gets or sets the data type associated with this view info. /// public Type DataType { get; set; } /// /// Gets or sets the type of data used for the view. /// public Type ViewDataType { get; set; } /// /// Gets or sets the type of the view. /// public Type ViewType { get; set; } /// /// Gets or sets the description of the view. /// public string Description { get; set; } /// /// Gets or sets the method used to determine the name for the view. Function arguments: /// /// The view to get a name for. /// The data corresponding to this view info. /// out - The name of the view. /// /// public Func GetViewName { get; set; } /// /// Gets or sets the icon of the view. /// public Image Image { get; set; } /// /// Gets or sets the optional method for checking if this view info object can be /// used for a given data object. Function arguments: /// /// Data for the view. /// out - true is this view info can be used for the data, or false otherwise. /// /// public Func AdditionalDataCheck { get; set; } /// /// Gets or sets the optional method used to convert data from the type defined by /// to the type defined by . Function Arguments: /// /// Original data. /// out - The converted data to be used in the view. /// /// public Func GetViewData { get; set; } /// /// Gets or sets the optional method that performs additional actions after the /// view has been created. Function arguments: /// /// The created view instance. /// The data corresponding to this view info. /// /// public Action AfterCreate { get; set; } /// /// Gets or sets the optional method that allows for actions to be performed to /// see if the view should be closed. Function arguments: /// /// View to close. /// Data of the view. /// out - true if the closing action was successful, false otherwise. /// /// public Func CloseForData { get; set; } /// /// Gets or sets the optional method that allows for the construction of the view. /// Function arguments: /// /// The data corresponding to this view info. /// The view to create. /// /// /// This property needs to be set if no default constructor is available /// for the view type. public Func CreateInstance { get; set; } public override string ToString() { return DataType + " : " + ViewDataType + " : " + ViewType; } } /// /// Information for creating a view for a particular data object. /// /// Data type associated with this view info. /// Type of data used for the view. /// Type of the view. public class ViewInfo where TView : IView { /// /// Initializes a new instance of the class. /// public ViewInfo() { CreateInstance = o => (TView) Activator.CreateInstance(ViewType); } /// /// Gets the data type associated with this view info. /// public Type DataType { get { return typeof(TData); } } /// /// Gets the type of data used for the view. /// public Type ViewDataType { get { return typeof(TViewData); } } /// /// Gets the type of the view. /// public Type ViewType { get { return typeof(TView); } } /// /// Gets or sets the description of the view. /// public string Description { get; set; } /// /// Gets or sets the method used to determine the name for the view. Function arguments: /// /// The view to get a name for. /// The data corresponding to this view info. /// out - The name of the view. /// /// public Func GetViewName { get; set; } /// /// Gets or sets the icon of the view. /// public Image Image { get; set; } /// /// Gets or sets the optional method for checking if this view info object can be /// used for a given data object. Function arguments: /// /// Data for the view. /// out - true is this view info can be used for the data, or false otherwise. /// /// public Func AdditionalDataCheck { get; set; } /// /// Gets or sets the optional method used to convert data from the type defined by /// to the type defined by . Function Arguments: /// /// Original data. /// out - The converted data to be used in the view. /// /// public Func GetViewData { get; set; } /// /// Gets or sets the optional method that performs additional actions after the /// view has been created. Function arguments: /// /// The created view instance. /// The data corresponding to this view info. /// /// public Action AfterCreate { get; set; } /// /// Gets or sets the optional method that allows for actions to be performed to /// see if the view should be closed. Function arguments: /// /// View to close. /// Data of the view. /// out - true if the closing action was successful, false otherwise. /// /// public Func CloseForData { get; set; } /// /// Gets or sets the optional method that allows for the construction of the view. /// Function arguments: /// /// The data corresponding to this view info. /// The view to create. /// /// /// This property needs to be set if no default constructor is available /// for the view type. public Func CreateInstance { get; set; } /// /// Performs an implicit conversion from to . /// /// The view information to convert. /// The result of the conversion. public static implicit operator ViewInfo(ViewInfo viewInfo) { return new ViewInfo { DataType = viewInfo.DataType, ViewDataType = viewInfo.ViewDataType, ViewType = viewInfo.ViewType, Description = viewInfo.Description, Image = viewInfo.Image, AdditionalDataCheck = o => viewInfo.AdditionalDataCheck == null || viewInfo.AdditionalDataCheck((TData) o), GetViewData = o => viewInfo.GetViewData != null ? viewInfo.GetViewData((TData) o) : o, CloseForData = (v, o) => viewInfo.CloseForData != null && viewInfo.CloseForData((TView) v, o), AfterCreate = (v, o) => viewInfo.AfterCreate?.Invoke((TView) v, (TData) o), GetViewName = (v, o) => viewInfo.GetViewName?.Invoke((TView) v, (TData) o), CreateInstance = o => viewInfo.CreateInstance((TData) o) }; } public override string ToString() { return DataType + " : " + ViewDataType + " : " + ViewType; } } /// /// Information for creating a view for a particular data object. /// /// Data type associated with this view info. /// Type of the view. public class ViewInfo : ViewInfo where TView : IView {} }