Visual Studio Developer Center > Visual Studio Forums > Visual Studio Extensibility > Text Decorator Selection does not update Domain-Class Properties Window
Ask a questionAsk a question
 

AnswerText Decorator Selection does not update Domain-Class Properties Window

  • Tuesday, June 12, 2007 9:20 AMVillanova Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello all,

    when i select/activate a text decorator shape whithin its parent shape, the corresponding domain-class (of the text decorator) properties window is not shown/updated. This is in contrast to the behaviour, when i select a compartment within its parent shape. In this case the domain-class (of the compartment) properties window is shown.
    For example a problem with this behaviour arises, when i have a boolean text decorator. When i select the decorator in the diagram, it would be fine to to be able to update the decorators value with the help of the property-grid window. But the window is not shown. Instead i have to select the corresponding domain class via the model explorer or - if there is a corresponding shape - i have to select this shape first, to get the properties grid shown.
    Is there a way to programmatically activate the properties grid (belonging to the domain class which is associated with the text decorator) when i select/activate a text decorator within its parent shape?

    Thanks
    Villanova

    btw: However a more elegant solution to this problem would be to get an inplace combobox when i doubleclick the textdecorator. But i think that is too difficult to implement.

Answers

  • Sunday, June 17, 2007 7:04 PMDuncanPMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi there,

    One option is not to change the item that is selected, but instead to change the description of the properties that appear in the Properties Grid when your shape is selected.

     

    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.


    Hope this answers your question (or at least gives some hints) :-)

     

    Duncan

All Replies

  • Tuesday, June 12, 2007 9:30 AMVillanova Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello,

    i did forget to mention, that the above problem description is related to a 1:1 association between two classes A and B, where class B holds a boolean domain property which is shown in class A via a text-decorator.

    Regards
    Villanova
  • Sunday, June 17, 2007 7:04 PMDuncanPMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi there,

    One option is not to change the item that is selected, but instead to change the description of the properties that appear in the Properties Grid when your shape is selected.

     

    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.


    Hope this answers your question (or at least gives some hints) :-)

     

    Duncan

  • Monday, June 18, 2007 6:49 AMVillanova Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Duncan,

    thank you for that excellent answer. I love these (longer) answers, which provide the reader with this type of valuable background information. I tried the approach with the type descriptor and it works perfectly. Thank you again!

    Villanova