Pablo Galiano : Monday, August 18, 2008 - Posts

Subscriptions

<December 2008>
SuMoTuWeThFrSa
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

News

Subscribe to Pablo Galiano by Email

Post Categories

Monday, August 18, 2008 - Posts

How do I select a DSL shape via API

My second How do I is up.

Scenario

Let's say that we want to synchronize the DSL model explorer with the DSL designer. Somehow we need to select a particular shape every time a node in the tree is selected. The focus of this How do I tackles this scenario.

 

Interfaces and classes needed

 

Code snippet

    public void SelectShape(ModelElement modelElement)

    {

        ShapeElement modelElementShape = PresentationViewsSubject.GetPresentation(modelElement).FirstOrDefault() as ShapeElement;

 

        Diagram diagram = modelElement.Store.ElementDirectory.AllElements.OfType<Diagram>().FirstOrDefault();

        DiagramItem diagramItem = new DiagramItem(modelElementShape);

        diagram.ActiveDiagramView.Selection.Set(diagramItem);

    }

Assemblies needed

  • Microsoft.VisualStudio.Modeling.Sdk
  • Microsoft.VisualStudio.Modeling.Sdk.Diagrams

 

Stay tuned,

Pablo

posted Monday, August 18, 2008 2:54 PM by pga with 1 Comments