// Copyright (C) Stichting Deltares 2021. 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 System.Windows.Forms; namespace Core.Common.Controls.TreeView { /// /// Class that represents information for updating tree nodes. /// public class TreeNodeInfo { /// /// Gets or sets the of the data of the tree node. /// public Type TagType { get; set; } /// /// Gets or sets a function for obtaining the tree node text. /// The object parameter represents the data of the tree node. /// public Func Text { get; set; } /// /// Gets or sets a function for obtaining the tree node forecolor. /// The object parameter represents the data of the tree node. /// public Func ForeColor { get; set; } /// /// Gets or sets a function for obtaining the tree node image. /// The object parameter represents the data of the tree node. /// public Func Image { get; set; } /// /// Gets or sets a function for obtaining the tree node context menu. /// The first object parameter represents the data of the tree node. /// The second object parameter represents the data of the parent tree node. /// The parameter represents the tree view control involved. /// public Func ContextMenuStrip { get; set; } /// /// Gets or sets a function for determining whether or not the tree node should become visible and selected on creation. /// The object parameter represents the data of the tree node. /// The second object parameter represents the data of the parent tree node. /// public Func EnsureVisibleOnCreate { get; set; } /// /// Gets or sets a function for determining whether or not the tree node should be expanded on creation. /// The object parameter represents the data of the tree node. /// public Func ExpandOnCreate { get; set; } /// /// Gets or sets a function for obtaining child node objects. /// The object parameter represents the data of the tree node. /// public Func ChildNodeObjects { get; set; } /// /// Gets or sets a function for checking whether or not the tree node can be renamed. /// The first object parameter represents the data of the tree node. /// The second object parameter represents the data of the parent tree node. /// public Func CanRename { get; set; } /// /// Gets or sets an action for obtaining the logic to perform after renaming the tree node. /// The object parameter represents the data of the tree node. /// The string parameter represents the new name of the tree node. /// public Action OnNodeRenamed { get; set; } /// /// Gets or sets a function for checking whether or not the tree node can be removed. /// The first object parameter represents the data of the tree node. /// The second object parameter represents the data of the parent tree node. /// public Func CanRemove { get; set; } /// /// Gets or sets a function for obtaining the text that is shown before the tree node is removed. /// The object parameter represents the data of the tree node. /// public Func BeforeNodeRemoveText { get; set; } /// /// Gets or sets an action for obtaining the logic to perform after removing the tree node. /// The first object parameter represents the data of the tree node. /// The second object parameter represents the data of the parent tree node. /// public Action OnNodeRemoved { get; set; } /// /// Gets or sets a function for checking whether or not the tree node can be checked. /// The object parameter represents the data of the tree node. /// public Func CanCheck { get; set; } /// /// Gets or sets a function for checking the checked state of the tree node. /// The object parameter represents the data of the tree node. /// public Func CheckedState { get; set; } /// /// Gets or sets an action for obtaining the logic to perform after checking or unchecking the tree node. /// The first object parameter represents the data of the tree node. /// The second object parameter represents the data of the parent tree node. /// public Action OnNodeChecked { get; set; } /// /// Gets or sets a function for checking whether or not the tree node can be dragged to another location. /// The first object parameter represents the data of the tree node. /// The second object parameter represents the data of the parent tree node. /// public Func CanDrag { get; set; } /// /// Gets or sets a function for checking whether or not a tree node can be dropped to the current tree node. /// The first object parameter represents the data of the tree node which is dragged. /// The second object parameter represents the data of the tree node being considered as drop target (the current node). /// /// When dragging a node, the method of the of the drop target should be called. public Func CanDrop { get; set; } /// /// Gets or sets a function for checking whether or not a tree node can be inserted into the current tree node at a specific index. /// The first object parameter represents the data of the tree node which is dragged. /// The second object parameter represents the data of the tree node being considered as drop target (the current node). /// /// When dragging a node, the method of the of the drop target should be called. public Func CanInsert { get; set; } /// /// Gets or sets an action for obtaining the logic to perform after dropping a tree node. /// The first object parameter represents the data of the tree node which was dropped. /// The second object parameter represents the data of the new parent tree node (the current node). /// The third object parameter represents the data of the former parent tree node. /// The parameter represents the drop target index which the tree node was inserted at. /// The parameter represents the tree view control involved. /// /// After dropping a node, the method of the of the drop target should be called. public Action OnDrop { get; set; } } /// /// Class that represents information for updating tree nodes. /// /// The type of data of the tree node. public class TreeNodeInfo { /// /// Gets the of the data of the tree node. /// public Type TagType { get { return typeof(TData); } } /// /// Gets or sets a function for obtaining the tree node text. /// The parameter represents the data of the tree node. /// public Func Text { get; set; } /// /// Gets or sets a function for obtaining the tree node forecolor. /// The parameter represents the data of the tree node. /// public Func ForeColor { get; set; } /// /// Gets or sets a function for obtaining the tree node image. /// The parameter represents the data of the tree node. /// public Func Image { get; set; } /// /// Gets or sets a function for obtaining the tree node context menu. /// The parameter represents the data of the tree node. /// The object parameter represents the data of the parent tree node. /// The parameter represents the tree view control involved. /// public Func ContextMenuStrip { get; set; } /// /// Gets or sets a function for determining whether or not the tree node should become visible and selected on creation. /// The parameter represents the data of the tree node. /// The object parameter represents the data of the parent tree node. /// public Func EnsureVisibleOnCreate { get; set; } /// /// Gets or sets a function for determining whether or not the tree node should be expanded on creation. /// The parameter represents the data of the tree node. /// public Func ExpandOnCreate { get; set; } /// /// Gets or sets a function for obtaining child node objects. /// The parameter represents the data of the tree node. /// public Func ChildNodeObjects { get; set; } /// /// Gets or sets a function for checking whether or not the tree node can be renamed. /// The parameter represents the data of the tree node. /// The object parameter represents the data of the parent tree node. /// public Func CanRename { get; set; } /// /// Gets or sets an action for obtaining the logic to perform after renaming the tree node. /// The parameter represents the data of the tree node. /// The string parameter represents the new name of the tree node. /// public Action OnNodeRenamed { get; set; } /// /// Gets or sets a function for checking whether or not the tree node can be removed. /// The parameter represents the data of the tree node. /// The object parameter represents the data of the parent tree node. /// public Func CanRemove { get; set; } /// /// Gets or sets an action for obtaining the logic to perform after removing the tree node. /// The parameter represents the data of the tree node. /// The object parameter represents the data of the parent tree node. /// public Action OnNodeRemoved { get; set; } /// /// Gets or sets a function for obtaining the text that is shown before the tree node is removed. /// The parameter represents the data of the tree node. /// public Func BeforeNodeRemoveText { get; set; } /// /// Gets or sets a function for checking whether or not the tree node can be checked. /// The parameter represents the data of the tree node. /// public Func CanCheck { get; set; } /// /// Gets or sets a function for checking the checked state of the tree node. /// The parameter represents the data of the tree node. /// public Func CheckedState { get; set; } /// /// Gets or sets an action for obtaining the logic to perform after checking or unchecking the tree node. /// The parameter represents the data of the tree node. /// The object parameter represents the data of the parent tree node. /// public Action OnNodeChecked { get; set; } /// /// Gets or sets a function for checking whether or not the tree node can be dragged to another location. /// The parameter represents the data of the tree node. /// The object parameter represents the data of the parent tree node. /// public Func CanDrag { get; set; } /// /// Gets or sets a function for checking whether or not a tree node can be dropped to the current tree node. /// The first object parameter represents the data of the tree node which is dragged. /// The second object parameter represents the data of the tree node being considered as drop target (the current node). /// /// When dragging a node, the method of the of the drop target should be called. public Func CanDrop { get; set; } /// /// Gets or sets a function for checking whether or not a tree node can be inserted into the current tree node at a specific index. /// The first object parameter represents the data of the tree node which is dragged. /// The second object parameter represents the data of the tree node being considered as drop target (the current node). /// /// When dragging a node, the method of the of the drop target should be called. public Func CanInsert { get; set; } /// /// Gets or sets an action for obtaining the logic to perform after dropping a tree node. /// The first object parameter represents the data of the tree node which was dropped. /// The second object parameter represents the data of the new parent tree node (the current node). /// The third object parameter represents the data of the former parent tree node. /// The parameter represents the drop target index which the tree node was inserted at. /// The parameter represents the tree view control involved. /// /// After dropping a node, the method of the of the drop target should be called. public Action OnDrop { get; set; } /// /// This operator converts a into a . /// /// The to convert. /// The converted . public static implicit operator TreeNodeInfo(TreeNodeInfo treeNodeInfo) { return new TreeNodeInfo { TagType = treeNodeInfo.TagType, Text = treeNodeInfo.Text != null ? tag => treeNodeInfo.Text((TData) tag) : (Func) null, ForeColor = treeNodeInfo.ForeColor != null ? tag => treeNodeInfo.ForeColor((TData) tag) : (Func) null, Image = treeNodeInfo.Image != null ? tag => treeNodeInfo.Image((TData) tag) : (Func) null, ContextMenuStrip = treeNodeInfo.ContextMenuStrip != null ? (tag, parentTag, treeViewControl) => treeNodeInfo.ContextMenuStrip((TData) tag, parentTag, treeViewControl) : (Func) null, EnsureVisibleOnCreate = treeNodeInfo.EnsureVisibleOnCreate != null ? (tag, parentTag) => treeNodeInfo.EnsureVisibleOnCreate((TData) tag, parentTag) : (Func) null, ExpandOnCreate = treeNodeInfo.ExpandOnCreate != null ? tag => treeNodeInfo.ExpandOnCreate((TData) tag) : (Func) null, ChildNodeObjects = treeNodeInfo.ChildNodeObjects != null ? tag => treeNodeInfo.ChildNodeObjects((TData) tag) : (Func) null, CanRename = treeNodeInfo.CanRename != null ? (tag, parentTag) => treeNodeInfo.CanRename((TData) tag, parentTag) : (Func) null, OnNodeRenamed = treeNodeInfo.OnNodeRenamed != null ? (tag, name) => treeNodeInfo.OnNodeRenamed((TData) tag, name) : (Action) null, CanRemove = treeNodeInfo.CanRemove != null ? (tag, parentTag) => treeNodeInfo.CanRemove((TData) tag, parentTag) : (Func) null, BeforeNodeRemoveText = treeNodeInfo.BeforeNodeRemoveText != null ? tag => treeNodeInfo.BeforeNodeRemoveText((TData) tag) : (Func) null, OnNodeRemoved = treeNodeInfo.OnNodeRemoved != null ? (tag, parentTag) => treeNodeInfo.OnNodeRemoved((TData) tag, parentTag) : (Action) null, CanCheck = treeNodeInfo.CanCheck != null ? tag => treeNodeInfo.CanCheck((TData) tag) : (Func) null, CheckedState = treeNodeInfo.CheckedState != null ? tag => treeNodeInfo.CheckedState((TData) tag) : (Func) null, OnNodeChecked = treeNodeInfo.OnNodeChecked != null ? (tag, parentTag) => treeNodeInfo.OnNodeChecked((TData) tag, parentTag) : (Action) null, CanDrag = treeNodeInfo.CanDrag != null ? (tag, parentTag) => treeNodeInfo.CanDrag((TData) tag, parentTag) : (Func) null, CanDrop = treeNodeInfo.CanDrop != null ? (draggedTag, targetTag) => treeNodeInfo.CanDrop(draggedTag, targetTag) : (Func) null, CanInsert = treeNodeInfo.CanInsert != null ? (draggedTag, targetTag) => treeNodeInfo.CanInsert(draggedTag, targetTag) : (Func) null, OnDrop = treeNodeInfo.OnDrop != null ? (droppedTag, newParentTag, oldParentTag, index, treeViewControl) => treeNodeInfo.OnDrop(droppedTag, newParentTag, oldParentTag, index, treeViewControl) : (Action) null }; } } }