DSL Tools: Add a custom typed domain property

Source: http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/e2707136-8deb-4c2a-8ac7-30bc19b08a8d/

Stuart Kent, MSFT, Moderator – Posted on Mon May 19 2008 12:47:28 GMT+0300 (GTB Daylight Time)

To add a custom typed domain property, add a domain property as usual through the DSL designer, then create an external type (select top node in explorer, and choose ‘Add External Type’. You can enter a namespace and name for the type in the propertties of the object that is created The correct code to show this in the properties window etc. should then be generated. You may need to write some custom code (navigate to source of build error and there should be a comment telling you what to do), though, without checking I can’t quite remember. You’ll need to add the custom editor through an attribute, which you can add to the domain property in the Dsl Designer.

Posted in DSL. Tags: . Leave a Comment »

Displaying properties of related class in property editor

Source: http://social.msdn.microsoft.com/forums/en-US/vsx/thread/7758716d-9a41-44e4-8bee-e70099877bdb
Author: DuncanP, MSFT, Moderator

First, some background how the DSL Tools display items in the Properties Grid (apologies in advance for the length of this answer!). The DSL Tools don’t directly display properties in the properties grid; instead, what happens is as follows:

  • the DSL Tools use the ISelectionService to tell Visual Studio which item (or items) are currently selected;
  • the properties grid (if it is visible) asks the selection service for a list of the selected items;
  • the properties grid then asks each selected item in turn to describe itself i.e. to return the list of names and values that will be displayed in the properties grid. TypeDescriptors are used to provide the descriptions of the individual items.

TypeDescriptors are not specific to the DSL Tools – they are a more general mechanism in the .Net framework that provides an extensible way to describe a type. There is an excellent MSDN article that describes how TypeDescriptors work and how to write your own at http://msdn.microsoft.com/msdnmag/issues/05/05/NETMatters/default.aspx.
By default, a domain class in the DSL tools will be described using the DSL Tools-supplied ElementTypeDescriptor. However, you are free to provide your own type descriptor that adds, changes, or completely replaces the default implementation.

The DSL Tools give you a variety of ways to change the default behaviour, some of which you can set in the DSL Defintion, some of which require custom code. Take the following scenario (based on your question): ClassA has a 1-1 relationship with ClassB.

 If you just want to show some or all of the properties of ClassB in addition to the properties for ClassA when the user clicks on ClassA, you can do this without writing any custom code, just by changing the DSL definition as follows:

  • Open the DSL Explorer and expand the “Domain Classes” node.
  • Select your “ClassA” from the list of domain classes
  • Right-click on the class node, and select “Add New Domain Type Descriptor” from the context menu.
  • Now select the new “Custom Type Descriptor” node that has appeared under the ClassA node.
  • Right-click on the node and select “Add New Property Path”. A new PropertyPath child node will be added.

You now need to set the properties of this new Property Path to describe how to get from the instance of ClassA to the property you want to be display (exactly the same way you did when specifying the property to display in the text decorator). The most important properties are “Path to Property” and “Property”.

Regenerate the code for the DSL and then run it. When you select an instance of the ClassA on the design surface that has an associated ClassB, you should see an extra property in the properties grid for each PropertyPath you added to the custom type descriptor.

If you want to completely change the properties that are shown when ClassA is clicked (e.g. you want to show the properties for ClassB instead), you will need to provide a custom type descriptor, which will involve writing some code.

If you look at the properties for the “Custom Type Descriptor” node, you will see there is a “Custom Coded” flag that you can set to true. Unfortunately, in v1 of the DSL tools setting this flag to “true” did nothing i.e. no additional code was generated. However, in the latest CTP (VS SDK CTP 2 for Orcas Beta 1), setting “Custom Code=true” will actually generate a custom type descriptor for you. All you need to do is implement a single method that returns the descriptions of the properties you want to appear in the properties grid.

Posted in DSL. Tags: . Leave a Comment »