Behavior in previous versions of the DSL Tools
In previous versions of the DSL Tools, the copy/cut/paste of model elements did not work very well. There were limitations, and even bugs that prevented very elaborate scenarios. In case you are interested, you can have to the posts on the forum describing these problems, and the pain there was in this area. Some people in the community were successful on some models (See for instance Pascal Recchia and Anthony Guérot’s article on toolbox prototypes, which uses the copy/paste mechanism: http://netfxfactory.org/blogs/papers/archive/2008/06/25/snip-your-dsl-into-prototypes.aspx), but the feature needed reworking and this is what we had done.
New behavior in VS2010
From the VS2010 DSL SDK, the copy/paste as an image is available to all the new designers, and it’s easy to provide the feature for existing migrated designers.
What is the behavior for the DSL user?
The DSL user will be able to copy model elements, compartments items, or anything that the DSL Author thought about, or cut them, and paste them in a compatible shape, in the same, or in different designers. and this in a very natural way.
How does the DSL author control this?
If you create a new graphical designer, you don’t need to do anything, the copy/paste is enabled by default.
If you migrate an existing designer, you can benefit from this new feature very simply:
- Having opened the DslDefinition.dsl, go to the DSL Explorer; in the Editor node, you’ll find a new property named “Enable Copy Paste”,
- Set “Enable Copy Paste” to CopyPasteOnly (the default is NoGeneratedCopyPaste in case of migrated designers because we did not want to break your designers in case you were successful in implementing the copy/paste already, and CopyPasteOnly for new designers)
- On each domain role, determine if you want the “copy closure” to pass trough the role. For this you have a property named “Propagates Copy” that values:
– Do Not Propagate Copy, if you don’t want to “navigate” through the role when copying from the opposite domain class
– Propagate Copy To Link Only, if you want to copy the link, but not the targeted domain class
– Propagates Copy To Link And Opposite Role Player, if you want to copy the link, and the targeted domain class
In new designers, the default is Propagates Copy To Link And Opposite Role Player for embeddings, and Do Not Propagate Copy for the others
- Transform All Templates
Example on the DSL class diagram template
More concretely. Let’s take the example of a class diagram unfolded form a Class diagram DSL template. The following screen shot shows a portion of the domain model (Class has attributes), and you can see that being an embedding, by default, Propagates Copy is set for the Attributes role to Propagates Copy To Link And Opposite Role Player.
What this means is each time you copy a ModelClass, you’ll copy its attributes at the same time, which is, really what most people expect.
Now let’s go a bit further, and change the behavior a bit. Let’s assume we have a base class Moveable, and copy the derived class (Plane), and paste it on the diagram. By default, you end up with a new class (Plane1) whose attributes and methods were cloned:
Now let’s assume that, as a DSL author, I want, each time we copy and paste a class (such as Plane), the inheritance, if any, to be copied as well (thus keeping the link with the base class):
To achieve this I need to:
- Figure out which role I navigate through when I copy Plane to get the inheritance: this is Superclass.
- Change the PropagateCopy property value of the Superclass role to Propagate Copy To Link Only
- Transform all templates
Now, when the designer user copies the class “Plane”, he gets a clone, with the inheritance relationship still linking to the same base class … just what I wanted.