Click here to Skip to main content
15,897,518 members
Articles / Programming Languages / Visual Basic
Tip/Trick

DSL Modelling - Adding a Tool Tip to the Connectors

Rate me:
Please Sign up or sign in to vote.
4.60/5 (3 votes)
4 Jun 2015CPOL1 min read 8.1K  
Make a nice diagram experience for your domain specific language by adding a smart tooltip to your connectors

Introduction

When you use the DSL SDK, you can create a tool with which you draw out your domain and it is subsequently turned into code with the T4 templates and code generation. However, the diagram can be quite busy so by having a tool tip on your connector classes, you can create it.

Background

Creating a domain specific language model requires the Visual Studio Modelling SDK.

Image 1

1. Make Your Connector Use a Custom Tool Tip

To do this, find the ConnectorShape you have in your DSL definition diagram and at the very bottom of the list of properties for it, you will find Tooltip Type. Set this to "Variable".

Image 2

2. Hooking Up the Code to Create the Tooltip

The DSL model is turned into code by text templates. You need to create a matching partial class of your own so that your changes don't get overwritten every time the DSL is compiled.

In that partial class, override the HasTooltip property to indicate to the designer that your connector has a tool tip:

C#
/// <summary>
/// The projection-handles-event always has a tooltip
/// </summary>
public override bool HasToolTip
{
    get
    {
        return true;
    }
}

Then, you need to override the GetTooltipText method to return the actual text to go into the tooltip:

C#
public override string GetToolTipText(DiagramItem item)
{
    string fromName = this.FromShape.AccessibleName;
    string toName = this.ToShape.AccessibleName;

    return string.Format("Projection {0} handles the event {1}", fromName, toName);
}

The resulting tooltip will show what the connector connects thus:

Image 3

History

  • 2015-06-04: Tip created

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Ireland Ireland
C# / SQL Server developer
Microsoft MVP (Azure) 2017
Microsoft MVP (Visual Basic) 2006, 2007

Comments and Discussions

 
-- There are no messages in this forum --