index > Visual Studio Team System - Domain-Specific Language Tools > Custom TargetEndStyle

Custom TargetEndStyle


Hi,

 

Can anyone tell me how to create a custom Targetendstyle for a connector line?

Thanks

Dan

Danmeland

Hi Dan,

You can create TargetEndStyles for connector by writing some custom code. If your connector is called MyConnector, you need to first mark MyConnector as HasDoubleDerived=true in the property grid for the connector and then regenerate the code by Transforming all templates.

This will create a BaseClass for your connector named MyConnectorBase in the generated Connector.cs as well as the connector class itself MyConnector. Next, create a custom class (say MyLinkDecorator) that will be the Customized Target End Style for your connector. This class will inherit from Modeling.Sdk.Diagrams.LinkDecorator class and must implement the GetPath method that returns the lines that should be drawn for the connector.

Next, write a partial class extending the MyConnector class and override the InitializeInstanceResources() method with implementation exactly as base but the only change will be that this.SetDecorators should be passed an instance of your newly created MyLinkDecorator instead of one of the default TargetEndStyle Decorators.

Recompile your project and you are all set to go!

Here is some sample code snippet to get you going:

using DslModeling = global::Microsoft.VisualStudio.Modeling;

using DslDesign = global::Microsoft.VisualStudio.Modeling.Design;

using DslDiagrams = global::Microsoft.VisualStudio.Modeling.Diagrams;

using System.Drawing.Drawing2D;

namespace Microsoft.Language6

{

/// <summary>

/// Double-derived base class for DomainClass ExampleConnector

/// </summary>

public partial class ExampleConnector : ExampleConnectorBase

{

/// <summary>

/// Initializes resources associated with this connector instance.

/// </summary>

protected override void InitializeInstanceResources()

{

base.InitializeInstanceResources();

this.SetDecorators(null, new MyLinkDecorator(), false);

}

}

public partial class MyLinkDecorator : DslDiagrams.LinkDecorator

{

protected override System.Drawing.Drawing2D.GraphicsPath GetPath(Microsoft.VisualStudio.Modeling.Diagrams.RectangleD bounds)

{

GraphicsPath path = DecoratorPath;

float centerX = (float)(bounds.Left + bounds.Width / 2);

float centerY = (float)(bounds.Top + bounds.Height / 2);

path.AddLine(centerX, (float)bounds.Y, (float)bounds.Right, centerY);

path.AddLine(centerX, (float)bounds.Y, (float)bounds.Left, centerY);

return path;

}

}

}

Bhavin B
reply 2

You can use google to search for other answers

 

More Articles

Infopath as editor
Show or Hide icon decorator at runtime
How can i force the placement of a port on its parent ?
Making a reference from a connector class
Abstract classes in minimal language
DSL Tools V1 Released
How to implement Rules in DSL
Where do I place text for a captionId?
Add shapes and connectors to diagram programmatically
Designer and File Associations
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

Can't run project (DSL November)
Starting with DSL Tools
Show more than one Property in a Compart…
More than one Diagram / File - Extension…
Customising standard context menu items
Additional DSL documentation?
How to control order of transformation s…
Properties on Relationship
Category feedback
Multiple DSL's using the same file exten…
DoubleClick in Compartment item
Can we host DSL designer in a custom hos…
Is there someone on the DSL tools team I…
IsSerializing property
Fixed diagram layout

Hot Articles

timescale for DSL additions
Getting Validation State
Custom Modeler Code
UML Sequence diagram in DSL?
Category feedback
Can I make two DSL models interact ?
Have problem for the DSL walk-through st…
Using existing Enumerations
Dynamically generate and "install&q…
Opening an existing DSL in a fresh insta…
How to determine if a model passes valid…
Two way synchronization
Problems with DSL Tools Version 1
Container Shape
Domain Model Definition Schema

Recommend Articles

Unable to intercept double click on deco…
Upgrade bug: Only 8.1 version of TextTem…
property graphical representation
Experience report: Building my own DSL
DSL Tools Licensing
DSL and GAT demo
Walkthrough distinguish visually between…
When will a release be made available fo…
Welcome to the Domain-Specific Language …
Infopath as editor
class factory
Announcing DSL Tools May 2005 CTP for Vi…
Licensing & pricing
Can't run project (DSL November)
On Stores, Editors & Models.