Partager via


Constraints and Restrictions in MS DSL Tools

I do get irritated by over-officious tools. "You can't use that name, you've used it already over there." Well, I know, but I'm going to change that in a moment, and it'll be alright in the end, really.

In the DSL Tools Customization Samples & Guide, there is a section showing you how to prevent the user from making undesirable connections, such as loops in inheritance graphs. As the user moves the mouse to complete the last link in a loop, a tooltip pops up saying "that connection would create a loop" and the arrow changes to a not-allowed sign. This is quite effective, but of course you might prefer to let your user make the loop, and then cut it somewhere else later.

Also, the computation to find the loop - or whatever other restriction - has to be fast, to respond to the user's mouse movements in real time. In some cases, that might prohibit this method.

The solution is to use the new Validation framework, which is coming in the next version of DSL Tools. It allows you to specify constraints on any class (or superclass, or relation, or the whole model). These are applied to all instances of the type when the model is opened or saved, or on the user's explicit command. Error messages appear in the VS task list, and clicking on an error selects the offending objects. You write just the C# code for the constraint itself, and the framework applies it as required.

This means you have a choice of when to apply a constraint - at the moment it is about to be contravened, or at validation time.

Comments

  • Anonymous
    October 31, 2005
    Just was I was waiting for. Thanks !