index > Visual Studio Team System - Domain-Specific Language Tools > Changing elements from properties

Changing elements from properties


Hi all.~ Slowly but surely coming around on DSL tools. =)

Assume I have a Bar and a Baz element, both of inherit from Foo element. Ideally, I'd like to be able to change a property on a Bar element to switch it to a Baz element. I'd have to imagine that it's not too easy with connections and property information transfer.

What are the possibilities for addressing this situation? Thanks in advance.

-B Tucker
Neumont University
SleipOdin

The property grid support in the DSL uses the new .NET Framework 2.0 TypeDescriptionProvider class to proffer the properties shown in the grid. You need to create a new class which knows how to re-direct either Bar or Baz model element (based on your own context). When the PropertyGrid control asks you for the type descriptor, you need to supply a provider in your shape. When the shape is selected, your provider will be called and you can proffer the right model element accordingly... The following is the code snippet you need.

Hope this helps!

Patrick Tseng

DSL Tools - SDE

[TypeDescriptionProvider(typeof(MyShapeTypeDescriptionProvider))]
public partial class MyShape { }

internal class MyShapeTypeDescriptionProvider : ElementTypeDescriptionProvider
{
protected override ElementTypeDescriptor CreateTypeDescriptor(ICustomTypeDescriptor parent, ModelElement element)
{
PresentationElement pel = element as PresentationElement;
if (pel != null)
{
// See if we can find the MEL. PresentationElementTypeDescriptionProvider is meant for PresentationElement so we should
// be able to find it.
ModelElement mel = pel.ModelElement;

// From the selected ModelElement object, find Bar or Baz object and feed into the 2nd parameter in the following calls
return new MyShapeTypeDescriptor(parent, element);
}

Debug.Fail("Un-recongize object selected, calling base");
return base.CreateTypeDescriptor( parent, element);
}
}

/// <summary>
/// Specialized type descriptor for the CommentShape class.
/// </summary>
public class MyShapeTypeDescriptor : ElementTypeDescriptor
{
/// <summary>
/// Creates a new CommentShapeTypeDescriptor.
/// </summary>
public MyShapeTypeDescriptor(ICustomTypeDescriptor parent, ModelElement selectedElement) :
base(parent, selectedElement)
{
}
}




Patrick Tseng
Patrick Tseng
Patrick's right, and with the new path-based mapping we support, it's relatively simple to have the immutable part of your class (call it FooHolder) hang on to whichever kind of sub-Foo is currently instanced and point decorator maps and other elements to it as well. I believe Coplien called this pattern "letter-envelope" back before the term pattern was even fashionable in software, but I think the GOF would call it the "State" pattern.


Gareth Jones - Developer - DSL Tools & Software Factories Platform [MSFT]
GarethJ - MSFT
reply 3

You can use google to search for other answers

 

More Articles

Walkthrough distinguish visually between start pages and normal p...
Drop-down list to edit 1-* relationships
Cannot add Reference shape to DSL Diagram
IsSerializing property
Getting validation results
Installing June 2006 VS SDK CTP side-by-side with April 2006 VS S...
HELP!!!...There is no: File > Export Template
A minor gotcha: reserved words
November release Designers compile errors
academic distribution of a DSL
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

How to access to the shape connectors by…
TextTemplatingFileGenerator now fails to…
November release Designers compile errors
property graphical representation
Setup & life cycle
Designing ClassDesigner in DSL Tools?
CMDS: Missing package guid for commands …
Reordering items in compartments?
Can Visual Studio DSL Designers be hosted?
Change a connector's from and to endpoin…
User Domain Model Displayed as XML
Domain model designer toolbox items disa…
DSL Tools November CTP now available
How to get a programmatic reference on t…
Reflecting domain property value on shap…

Hot Articles

DSL Tools November CTP and VS SDK Decemb…
How to move shapes within diagram progra…
Experience report: Building my own DSL
some question In DSL Tools
Troubleshooting: replicating toolbox items
Come Join the World's Largest Software F…
'security error'
Context menu item localization
How to get a programmatic reference on t…
Inheritance Restriction?
Reading and writing models in June relea…
Custom Command improvements
How to set compartment's default expande…
Come join the largest group on the DSL a…
Atrributes with particular properties

Recommend Articles

Stability of Modeling API
Prevent generated DSL code from producin…
Problems loading package
Unable to Replace Old Files by New ones
filtering reference dropdowns in the pro…
Fixed diagram layout
How to know if OnShapeInserted was initi…
Reading and writing models in June relea…
No 'add new...' on Compartment
Nested Shapes
CompartmentShapeMap
General Questions
Popup dialog in DSL
Custom connector target (June CTP)
Localization