using System; using System.Drawing; using Core.Common.Controls.Views; namespace Core.Common.Controls { public class ViewInfo : ICloneable { /// /// Type of the data for this viewInfo /// public Type DataType { get; set; } /// /// Type of the data of the view /// public Type ViewDataType { get; set; } /// /// Type of the view /// public Type ViewType { get; set; } /// /// Type of the composite view to which this view belongs /// public Type CompositeViewType { get; set; } /// /// Description of the view (shown to the user when there is more then one view for an item) /// public string Description { get; set; } /// /// Name the view should have /// /// The view to get a name for /// The data of the view /// out - the view name /// /// public Func GetViewName { get; set; } /// /// Icon of the view (shown top left) /// public Image Image { get; set; } /// /// Additional data checking for matching the ViewInfo /// /// Data as provided by the ViewProvider /// out - Check succeeded /// /// public Func AdditionalDataCheck { get; set; } /// /// Function that returns the data for the view (when not set it returns T in ) /// /// object - Original data for the view /// out object - data for the view /// /// public Func GetViewData { get; set; } /// /// Extra actions that can be performed on the view after creation /// /// View to modify /// Data for this viewinfo /// /// public Action AfterCreate { get; set; } /// /// Extra actions that can be performed on the view after the focus has been set on the view. /// (Will be called after creation and when the user tries to open a view for data while there is an existing view /// (and only the focus will be set to the existing view)) /// /// View to modify /// Data for this viewinfo /// /// public Action OnActivateView { get; set; } /// /// Gets the data for the composite view of which this is the child view info /// public Func GetCompositeViewData { get; set; } /// /// Override the default closing of the view constructed with this info /// /// View to close /// /// out - Close succeeded /// /// public Func CloseForData { get; set; } public override string ToString() { return DataType + " : " + ViewDataType + " : " + ViewType; } public object Clone() { return MemberwiseClone(); } } public class ViewInfo where TView : IView { public Type DataType { get { return typeof(TData); } } public Type ViewDataType { get { return typeof(TViewData); } } public Type ViewType { get { return typeof(TView); } } public Type CompositeViewType { get; set; } public string Description { get; set; } public Func GetViewName { get; set; } public Image Image { get; set; } public Func AdditionalDataCheck { get; set; } public Func GetViewData { get; set; } public Action AfterCreate { get; set; } public Action OnActivateView { get; set; } public Func GetCompositeViewData { get; set; } public Func CloseForData { get; set; } public static implicit operator ViewInfo(ViewInfo viewInfo) { return new ViewInfo { DataType = viewInfo.DataType, ViewDataType = viewInfo.ViewDataType, ViewType = viewInfo.ViewType, CompositeViewType = viewInfo.CompositeViewType, 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, GetCompositeViewData = o => viewInfo.GetCompositeViewData != null ? viewInfo.GetCompositeViewData((TData) o) : null, 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; } } public class ViewInfo : ViewInfo where TView : IView {} }