using System; using System.Drawing; using Core.Common.Base; using Core.Common.Controls.TreeView; using Core.Components.Charting.Data; namespace Core.Plugins.OxyPlot.Legend { /// /// This class describes the presentation of as a tree node. /// public abstract class ChartDataNodePresenter : TreeViewNodePresenterBase where T : PointBasedChartData { /// /// Gets the text to set on the node. /// protected abstract string Text { get; } /// /// Gets the icon to set for the node. /// protected abstract Bitmap Icon { get; } /// /// Returns the possible on . /// /// The data of type to base /// on. /// The possible on . public override DragOperations CanDrag(T nodeData) { return DragOperations.Move; } /// /// Updates the with data taken from . /// /// The parent of the . /// The to update. /// The data of type to update the /// with. /// Thrown when: /// /// is null /// is null /// /// public override void UpdateNode(TreeNode parentNode, TreeNode node, T nodeData) { if (node == null) { throw new ArgumentNullException("node", "Cannot update node without data."); } if (nodeData == null) { throw new ArgumentNullException("nodeData", "Cannot update node without data."); } node.Text = Text; node.Image = Icon; node.ShowCheckBox = true; var isVisible = nodeData.IsVisible; if (node.Checked != isVisible) { node.Checked = isVisible; } } /// /// Updates the state of the data associated with based on its property. /// /// The which had its property updated. /// Thrown when is null. /// Thrown when of is null. public override void OnNodeChecked(TreeNode node) { if (node == null) { throw new ArgumentNullException("node", "Cannot update node without data."); } var data = node.Tag as T; if (data == null) { throw new ArgumentException("Cannot invoke OnNodeChecked for a node without tag."); } data.IsVisible = node.Checked; var parentData = node.Parent == null ? null : node.Parent.Tag as IObservable; if (parentData != null) { parentData.NotifyObservers(); } } } }