index > Visual Studio Team System - Domain-Specific Language Tools > Custom connect code not getting called

Custom connect code not getting called


I have in my diagram an element (call it ElementA) that is represented in the diagram as a compartment item in a compartment shape. ElementA has a 1-1 reference relationship to another element (ElementB). Neither ElementB nor the relationship have a visual representation in the diagram (other than the TreeView). The reference from ElementA to ElementB is set via a drop-down in the properties window.

I want to to perform some custom logic when the ElementA -> ElementB relationship is first created. I provided a custom implementation of ConnectSourceToTarget for the (RelationshipName)Builder class. When establishing the relationship via the properties window, ConnectSourceToTarget is never called. In fact, no methods in the builder class are called.

Should this have worked? Is there another place I can implement this logic? I considered providing a custom setter for the associated property on ElementA, but would that get called during deserialization?

Thanks,

Daniel

Daniel Pratt

The connection builder is usually only called when you use a connection tool. If you set the relationship through the properties window, or through custom code where you do something like elementA.B = elementB, then no connection builder is called: it just sets up an instance of the relationship.

So what you need is an AddRule on the relationship. It will look something like this:

[RuleOn(ABRelationship, FireTime = TimeToFire.TopLevelCommit)]
private class ABrelationshipAddRule : AddRule
{
public override void ElementAdded(ElementAddedEventArgs e)
{
base.ElementAdded(e);
ABRelationship newLink = e.ModelElement as ABRelationship;
// etc with newLink.A, newLink.B - use the relationship's Role Names
}
}

public partial class YourLanguageDomainModel
{
/// <summary>
/// You must register your custom rules.
/// </summary>
/// <returns></returns>
protected override Type[] GetCustomDomainModelTypes()
{
return new System.Type[] { typeof(ABrelationshipAddRule ) }; // must include all your custom rules
}
}




- Alan [Microsoft]
Alan Cameron Wills
reply 2

You can use google to search for other answers

 

More Articles

DSL Tools outside VS?
Adding items to compartment
DSL Tools Team HIRING in Cambridge, UK
Codegen templates selected at build time
How to expose domain model objects through DTE
Two way synchronization
Join the World's Largest User Group on Software Factories in VS 2...
accessing relations (and its value properties) from a domain clas...
domain class inheritance, where types are represented by differen...
Custom connector target (June CTP)
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

Minor gotcha in the Adding a Compartment…
Text template load a file
Problem starting new DSL-project
How to Use Path Syntax and Element Merge…
Multiplicity Value Property
fatal error CTC2013: Can't start preproc…
Open a new Document
Transitions shapes not draggable/Package…
CTC Problem
How to Export diagram as image
Problems with DSL Tools walk-through
How to make Tree's?
Inherited classes and their compartment …
DoubleClick in Compartment item
designer definition toolbox item - compa…

Hot Articles

Unable to intercept double click on deco…
DMD -> DD
Inherited classes and their compartment …
Where do I place text for a captionId?
N-ary Relationships
How to add a custom rule that listens on…
Outline Pen Width
How to access the Session in subdomain?
Production quality planning of MS DSL to…
Customize DirectiveProcessor
Default values not stored
Generating Code From a Model Walkthrough
Using existing Enumerations
How can i associate a textfield with a p…
Getting validation results

Recommend Articles

how can i get a Service into T4 textempl…
How adequate-rich or suffitient-complete…
How to create multiple diagrams associat…
Adding/Removing elements in domain model
GAC support in Templating Engine (Featur…
how can i use the DiagramView to develop…
Error : Value cannot be null ,Parameter …
How to migrate / implement CustomStorage…
Package Load Failure Again
designer definition toolbox item - compa…
problem when following "Walkthrough…
How to Add context menu to shapes
Domain model designer
cannot drag & drop shape from toolbox
Is there documentation for the T4 engine…