Pablo Galiano : Monday, August 18, 2008 - Posts

Subscriptions

<September 2010>
SuMoTuWeThFrSa
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

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 2 Comments