// 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 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 { /// /// Data type associated with this view info. /// public Type DataType { get; set; } /// /// Type of data used for the view. /// public Type ViewDataType { get; set; } /// /// Type of the view. /// public Type ViewType { get; set; } /// /// Description of the view. /// public string Description { get; set; } /// /// Method used to determine the name for the view. Function arguments: /// /// The view to get a name for. /// The data of the view. /// out - The name of the view. /// /// public Func GetViewName { get; set; } /// /// Icon of the view. /// public Image Image { get; set; } /// /// 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; } /// /// Optional method, used to convert data from type defined by /// to type defined by . Function Arguments: /// /// Original data. /// out - The converted data to be used in the view. /// /// public Func GetViewData { get; set; } /// /// Optional method, to perform 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; } /// /// Optional method, to allow for extra actions to be performed after the view has /// received focus. Function arguments: /// /// View to modify. /// Data for this view info. /// /// public Action OnActivateView { get; set; } /// /// Optional method, such that actions can be performed or checked to see if the /// view should be closed. Function arguments: /// /// View to close. /// Data of the view. /// out - true is the closing action was successful, false otherwise. /// /// public Func CloseForData { 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 { /// /// Data type associated with this view info. /// public Type DataType { get { return typeof(TData); } } /// /// Type of data used for the view. /// public Type ViewDataType { get { return typeof(TViewData); } } /// /// Type of the view. /// public Type ViewType { get { return typeof(TView); } } /// /// Description of the view. /// public string Description { get; set; } /// /// Method used to determine the name for the view. Function arguments: /// /// The view to get a name for. /// The data of the view. /// out - The name of the view. /// /// public Func GetViewName { get; set; } /// /// Icon of the view. /// public Image Image { get; set; } /// /// 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; } /// /// Optional method, used to convert data from type defined by /// to type defined by . Function Arguments: /// /// Original data. /// out - The converted data to be used in the view. /// /// public Func GetViewData { get; set; } /// /// Optional method, to perform 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; } /// /// Optional method, to allow for extra actions to be performed after the view has /// received focus. Function arguments: /// /// View to modify. /// Data for this view info. /// /// public Action OnActivateView { get; set; } /// /// Optional method, such that actions can be performed or checked to see if the /// view should be closed. Function arguments: /// /// View to close. /// Data of the view. /// out - true is the closing action was successful, false otherwise. /// /// public Func CloseForData { get; set; } /// /// Performs an implicit conversion from to . /// /// The view information. /// /// 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) => { if (viewInfo.AfterCreate != null) { viewInfo.AfterCreate((TView) v, (TData) o); } }, OnActivateView = (v, o) => { if (viewInfo.OnActivateView != null) { viewInfo.OnActivateView((TView) v, o); } }, GetViewName = (v, o) => viewInfo.GetViewName != null ? viewInfo.GetViewName((TView) v, (TViewData) o) : null }; } 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 {} }