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.

The code underneath uses definitions inside the libraries DelftTools.Controls and DelftTools.Controls.Swf. In order to successfully build the code underneath, the references to these dynamic link libraries (dll's) need to be added:

  • DelftTools.Controls
  • DelftTools.Controls.Swf

These dll's can all be found in the packages folder of the solution (D:\VolumeModel\packages\DeltaShell.Framework.1.1.1.34867\lib\net40\DeltaShell).

After adding the references be sure to set the Copy Local property of the references to false to prevent duplication of these dll's in the bin folder.
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 :

Required
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 :

 

  • No labels