How to: Integrate UML Models with Other Models and Tools

UML models can be integrated with other models and with domain-specific languages.

You can integrate models in the following ways by writing extension code to perform a variety of functions:

  • Attach references from any element to other items such as files or to elements in other models.
    In a UML element, you can store links to other UML elements, files, or other objects by encoding their identities as strings.

    For example, you could write an extension that can link any UML action (that is, an element in an activity diagram) to another activity diagram. When the user double-clicks the action, the other diagram opens. This lets the user provide a more detailed view of the action.

    There are two ways in which you can store strings and other data in any element:

    • Stereotype properties. You can define a UML profile, in which you define a stereotype that adds properties to specified kinds of UML element. For example, you could define a profile that adds a property named MoreDetail to a UML action. You could write extension code that stores link data in an action by applying the stereotype to the action, and then storing the data in the property.

      The stereotype and its properties are visible to the user in the Properties window.

      To deploy this extension, you would package the profile definition and the extension code in a single Visual Studio Extension.

      For more information, see How to: Define a Profile to Extend UML.

      For a sample project in which a profile is deployed together with menu commands and gesture handlers, see Sample: UML Profiles.

    • References. You can attach a set of strings to any UML element. You could write code that stores the information such as a filename or the GUID of another element. This can be done without providing additional definitions. References are not directly visible to the user.

      For more information, see How to: Attach Reference Strings to Model Elements. For a sample, see Link UML Elements to Diagrams or other Files.

    There are two ways to encode references to model elements:

    • GUID and Filename of the target model element and the model that contains it, or a particular diagram that displays it.

      For an example, see Link UML Elements to Diagrams or other Files.

    • ModelBus References. ModelBus is a framework for creating and resolving references between models. It includes the ModelBus Picker, which lets the user select an element in a model. It also helps the user to resolve references that are lost because of changes in the target model.

      For more information, see Integrating Models by using Visual Studio Modelbus.

  • Propagate changes from one model to another.
    For example, you could synchronize the name of an element with the name of the linked diagram, so that if the user changes one, the other also changes. There are two mechanisms for doing this:

    1. VMSDK Rules can be used to propagate changes inside the same model.

      For an example, see Link UML Elements to Diagrams or other Files.

    2. VMSDK Events can be used to propagate changes outside the model – for example, to change the filename of a linked document, or to change an element in another model.

    For information about both these mechanisms, see How to: Respond to Changes in a UML Model.

  • Drag elements to copy them from one model to another
    You can let the user create elements by dragging items onto a UML diagram. The created element does not have to be a copy of the original. For example, you could let the user drag an activity diagram from solution explorer onto another activity diagram, to create a new action.

    For more information see How to: Define a Gesture Handler on a Modeling Diagram and How to: Add a Drag-and-Drop Handler.

Samples

Please see the code sample Link UML Elements to Diagrams or other Files. The sample lets users drag a file onto any UML element, and later open the file by double-clicking the element. For example, you could link an activity diagram to a use case element. An icon shows which elements have links.

This code sample demonstrates the following techniques:

For an example in which a UML model is be read by a DSL, see How to: Add a Drag-and-Drop Handler.

See Also

Concepts

How to: Define a Menu Command on a Modeling Diagram

How to: Define a Gesture Handler on a Modeling Diagram

How to: Add a Drag-and-Drop Handler

How to: Respond to Changes in a UML Model

Other Resources

Sample: UML Profiles

Link UML Elements to Diagrams or other Files