Exercise outline
In this exercise we change the way that drainage basin is represented in the project tree-view.
Create custom NodePresenter
First start by downloading and adding the basin.png to the resources. Then, add a new folder called Nodepresenters to the plugin project. In this folder, create a new class named DrainageBasinTreeViewNodePresenter.cs and place the code indicated below inside this class file.
using System.Drawing; using System.Linq; using DelftTools.Controls; using DelftTools.Controls.Swf.TreeViewControls; using DeltaShell.Plugins.VolumeModel.Models; namespace DeltaShell.Plugins.VolumeModel.Nodepresenters { public class DrainageBasinTreeViewNodePresenter : TreeViewNodePresenterBase<DrainageBasin> { private static readonly Image DrainageBasinImage = Properties.Resources.basin; public override void UpdateNode(ITreeNode parentNode, ITreeNode node, DrainageBasin nodeData) { var hasCatchments = nodeData.Catchments.Any(); node.Text = string.Format("Drainage basin{0}", hasCatchments ? "" : " (Empty)"); node.Image = DrainageBasinImage; } } }
Register the NodePresenter class in the GUI plugin class
The NodePresenter class must be registered in the GUI plug-in class in order to be accessible. Go to the VolumeModelGuiPlugin class and add the following code:
public override IEnumerable<ITreeNodePresenter> GetProjectTreeViewNodePresenters() { yield return new DrainageBasinTreeViewNodePresenter(); }
For the required code IEnumerable, ITreeNodePresenter, GetProjectTreeViewNodePresenters, and DrainageBasinTreeViewNodePresenter to be accessible and subsequently, once used, disposed, we will add the following using statements :
using System.Collections.Generic; // IEnumerable using DeltaShell.Plugins.VolumeModel.Nodepresenters; //DrainageBasinTreeViewNodePresenter using DelftTools.Controls; //ITreeNodePresenter, GetProjectTreeViewNodePresenters
Exercise results
After adding a Volume model to the project, you will now see the following representation for the Drainage Basin :