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
{
///
/// Constructs a new .
///
public TreeNodeInfo()
{
Text = tag => "";
}
///
/// Gets or sets the of the data wrapped by the tree node.
///
public Type TagType { get; set; }
///
/// Gets or sets a function for obtaining the tree node text.
/// The object parameter represents the wrapped data of the tree node.
///
public Func Text { get; set; }
///
/// Gets or sets a function for obtaining the tree node fore color.
/// The object parameter represents the wrapped 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 wrapped data of the tree node.
///
public Func Image { get; set; }
///
/// Gets or sets a function for obtaining the tree node context menu.
/// The object parameter represents the wrapped data of the tree node.
/// The parameter represents the tree node.
/// The parameter represents the current tree node information object.
///
public Func ContextMenuStrip { get; set; }
///
/// Gets or sets a function for obtaining child node objects.
/// The object parameter represents the wrapped 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 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 wrapped 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 wrapped data of the tree node.
/// The second object parameter represents the wrapped 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 object parameter represents the wrapped data of the tree node.
/// The object parameter represents the wrapped 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 wrapped data of the tree node.
///
public Func CanCheck { get; set; }
///
/// Gets or sets a function for checking whether or not the tree node should be checked.
/// The object parameter represents the wrapped data of the tree node.
///
public Func IsChecked { get; set; }
///
/// Gets or sets an action for obtaining the logic to perform after checking or unchecking the tree node.
/// The parameter represents the tree node which is checked.
///
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 object parameter represents the wrapped data of the tree node.
/// The parameter represents the tree node which is dragged.
///
public Func CanDrag { get; set; }
///
/// Gets or sets a function for checking whether or not the tree node can be dropped to another location.
/// The first parameter represents the tree node which is dragged.
/// The second parameter represents the tree node being considered as drop target.
/// The parameter represents the supported drop operations for the tree node which is dragged.
/// The return value indicates what operation is valid when the tree node is dropped onto the drop target.
///
/// When dragging a node, the function of the of the drop target should be called.
public Func CanDrop { get; set; }
///
/// Gets or sets a function for checking whether or not the tree node can be inserted into the drop target at a specific index.
/// The first parameter represents the tree node which is dragged.
/// The second parameter represents the tree node being considered as drop target.
///
public Func CanInsert { get; set; }
///
/// Gets or sets an action for obtaining the logic to perform after dropping a tree node.
/// The first parameter represents the tree node which is dragged.
/// The second parameter represents the tree node being considered as drop target.
/// The parameter represents the type of drag operation that was performed.
/// The parameter represents the drop target index which the tree node was inserted at.
///
/// When dragging a node, the function 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 wrapped by the tree node.
public class TreeNodeInfo
{
///
/// Constructs a new .
///
public TreeNodeInfo()
{
Text = tag => "";
}
///
/// Gets the of the data wrapped by 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 wrapped data of the tree node.
///
public Func Text { get; set; }
///
/// Gets or sets a function for obtaining the tree node color.
/// The parameter represents the wrapped 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 wrapped 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 wrapped data of the tree node.
/// The parameter represents the tree node.
/// The parameter represents the current tree node information object.
///
public Func ContextMenuStrip { get; set; }
///
/// Gets or sets a function for obtaining child node objects.
/// The parameter represents the wrapped 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 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 wrapped 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 wrapped data of the tree node.
/// The object parameter represents the wrapped 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 wrapped data of the tree node.
/// The object parameter represents the wrapped 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 parameter represents the wrapped data of the tree node.
///
public Func CanCheck { get; set; }
///
/// Gets or sets a function for checking whether or not the tree node should be checked.
/// The parameter represents the wrapped data of the tree node.
///
public Func IsChecked { get; set; }
///
/// Gets or sets an action for obtaining the logic to perform after checking or unchecking the tree node.
/// The parameter represents the tree node which is checked.
///
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 wrapped data of the tree node.
/// The parameter represents the tree node which is dragged.
///
public Func CanDrag { get; set; }
///
/// Gets or sets a function for checking whether or not the tree node can be dropped to another location.
/// The first parameter represents the tree node which is dragged.
/// The second parameter represents the tree node being considered as drop target.
/// The parameter represents the supported drop operations for the tree node which is dragged.
/// The return value indicates what operation is valid when the tree node is dropped onto the drop target.
///
/// When dragging a node, the function of the of the drop target should be called.
public Func CanDrop { get; set; }
///
/// Gets or sets a function for checking whether or not the tree node can be inserted into the drop target at a specific index.
/// The first parameter represents the tree node which is dragged.
/// The second parameter represents the tree node being considered as drop target.
///
public Func CanInsert { get; set; }
///
/// Gets or sets an action for obtaining the logic to perform after dropping a tree node.
/// The first parameter represents the tree node which is dragged.
/// The second parameter represents the tree node being considered as drop target.
/// The parameter represents the type of drag operation that was performed.
/// The parameter represents the drop target index which the tree node was inserted at.
///
/// When dragging a node, the function 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, sourceNode, info) => treeNodeInfo.ContextMenuStrip((TData) tag, sourceNode, info)
: (Func) null,
ChildNodeObjects = treeNodeInfo.ChildNodeObjects != null
? tag => treeNodeInfo.ChildNodeObjects((TData) tag)
: (Func) null,
CanRename = treeNodeInfo.CanRename != null
? sourceNode => treeNodeInfo.CanRename(sourceNode)
: (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,
OnNodeRemoved = treeNodeInfo.OnNodeRemoved != null
? (tag, parentTag) => treeNodeInfo.OnNodeRemoved((TData) tag, parentTag)
: (Action) null,
CanCheck = treeNodeInfo.CanCheck != null
? tag => treeNodeInfo.CanCheck((TData) tag)
: (Func) null,
IsChecked = treeNodeInfo.IsChecked != null
? tag => treeNodeInfo.IsChecked((TData) tag)
: (Func) null,
OnNodeChecked = treeNodeInfo.OnNodeChecked != null
? sourceNode => treeNodeInfo.OnNodeChecked(sourceNode)
: (Action) null,
CanDrag = treeNodeInfo.CanDrag != null
? (tag, sourceNode) => treeNodeInfo.CanDrag((TData) tag, sourceNode)
: (Func) null,
CanDrop = treeNodeInfo.CanDrop != null
? (sourceNode, targetNode, dragOperations) => treeNodeInfo.CanDrop(sourceNode, targetNode, dragOperations)
: (Func) null,
CanInsert = treeNodeInfo.CanInsert != null
? (sourceNode, targetNode) => treeNodeInfo.CanInsert(sourceNode, targetNode)
: (Func) null,
OnDrop = treeNodeInfo.OnDrop != null
? (sourceNode, targetNode, dragOperations, index) => treeNodeInfo.OnDrop(sourceNode, targetNode, dragOperations, index)
: (Action) null,
};
}
}
}