Ask a questionAsk a question
 

AnswerInitialize Diagram Property in a DSL

  • Monday, October 26, 2009 2:31 PMNicolas Roux Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    I have a DSL, and I would like to initialize a Property defined on the Diagram element.

    I have tried to add an AddRule on the Diagram Class, but I don't want this code to be called each time the File is loaded. Instead, I would like only the first time the Diagram is created. 

    And my property default value depend on the FileName filled in the AddNew Box by the User.

    Thanks for any help to do that.

    Nico 
    •  

Answers

  • Tuesday, November 03, 2009 3:02 PMDuncanPMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    You might be able to create a Visual Studio item template that does what you want.

    The generated target designer package contains a "ProjectItemsTemplates" folder that contains the sample model file and diagram file that are used to produce the project item template for the new language. The model file is called [MyLanguage].[MyLanguage], and the diagram file is called [MyLanguage].diagram.

    By default, the model and diagram file are both empty, and the DSL tools take this is an indication that it should create a root model element and diagram. However, you can populate these files with data for your model and diagram. The easiest way to do this is to use your target designer to create the model you want to use as the item template and save it. You would then copy the data from those files into the [MyLanguage].[MyLanguage] / [MyLanguage].diagram files.

    The files you have just created might contain hard-coded guids (depending on how you have defined your language) which you don't really want. However, Visual Studio item templates support parameter subsitution for guids and certain other well-defined properties. You could edit your templates to replace the guids and other values the parameters, so that Visual Studio will substitute in the appropriate values when the item template is used.

    The MSDN reference for VS item templates is at http://msdn.microsoft.com/en-us/library/6db0hwky(VS.100).aspx, and the list of parameters that you use is at http://msdn.microsoft.com/en-us/library/eehb4faa(VS.100).aspx.

    Regards,
    Duncan

    • Marked As Answer byNicolas Roux Wednesday, November 04, 2009 10:57 AM
    •  

All Replies

  • Tuesday, November 03, 2009 3:02 PMDuncanPMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    You might be able to create a Visual Studio item template that does what you want.

    The generated target designer package contains a "ProjectItemsTemplates" folder that contains the sample model file and diagram file that are used to produce the project item template for the new language. The model file is called [MyLanguage].[MyLanguage], and the diagram file is called [MyLanguage].diagram.

    By default, the model and diagram file are both empty, and the DSL tools take this is an indication that it should create a root model element and diagram. However, you can populate these files with data for your model and diagram. The easiest way to do this is to use your target designer to create the model you want to use as the item template and save it. You would then copy the data from those files into the [MyLanguage].[MyLanguage] / [MyLanguage].diagram files.

    The files you have just created might contain hard-coded guids (depending on how you have defined your language) which you don't really want. However, Visual Studio item templates support parameter subsitution for guids and certain other well-defined properties. You could edit your templates to replace the guids and other values the parameters, so that Visual Studio will substitute in the appropriate values when the item template is used.

    The MSDN reference for VS item templates is at http://msdn.microsoft.com/en-us/library/6db0hwky(VS.100).aspx, and the list of parameters that you use is at http://msdn.microsoft.com/en-us/library/eehb4faa(VS.100).aspx.

    Regards,
    Duncan

    • Marked As Answer byNicolas Roux Wednesday, November 04, 2009 10:57 AM
    •  
  • Wednesday, November 04, 2009 10:36 AMNicolas Roux Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello Duncan,

    Thanks for your reply.

    I understand the Template technology, and I can see what you mean. But I don't know where is my file [MyLanguage].[MyLanguage] (Entities.Entities in my cas).

    I do have a Entities.Entities file, but it is empty, and I don't think it is this one used by the DSLPackage. I thought this file was generated from scratch by the DSLPackage.
  • Wednesday, November 04, 2009 10:57 AMNicolas Roux Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I think I get it !

    My file Entities.Entities was effectively empty and I just filt it with my initial values, and it works !

    Many thanks, Duncan.