07/04/2011

Creating an MDG – Part 2: Creating diagrams

 

When extending Sparx EA with your own elements (see Creating an MDG - Part 1: Create an UML Profile), you probably also want to create your own type of diagrams. In our series about creating an MDG Technology, we will discuss now how to create or extend diagrams.

Open the file

First of all, open the the eap-file created in our previous topic. Create a package “MdgDiagrams” and stereotype it as “profile”. Add a class diagram to the package.

image

As mentioned before, you can give your package an alias and some description.

image

Create a new diagram

Drag a “stereotype” element from the Profile-toolbox on the diagram and name it “MyDiagram1”.

image

Again give it an alias and some description of what the diagram is used for. This description displays in the bottom right-hand corner of the New Diagram dialog in EA.

image 

On the diagram drag a Metaclass-item from the Profile-toolbox and drop it on the diagram. In the window that appears, choose a “Boundary”-element. This will create an empty metaclass-element on the diagram. Select the element and name it as one of the Built-In Diagram Types prefixed with “Diagram_”, for example “Diagram_Logical” or “Diagram_Use Case”. For a list of Built-In Diagram Types, see the help topic of EA. In our example name it “Diagram_Class”. Your custom diagrams will inherit from the Diagram_Class metaclass.

image

Now select the newly created element on the diagram, select the little arrow symbol that appears and drag/drop it on the metaclass-item. Choose “Extend”.

image

Now add two attributes to the metaclass element:

  • alias: string = Type (where “Type” appears before the word ‘Diagram’ on the diagram title bar, so give it the same value as the alias-field in the properties of the MyDiagram1-stereotype, “My Diagram 1”).
  • diagramID: string = abc (where “abc” is the diagram type that appears in the diagram frame label, so give it the value “MD1”)

This should now look like:

image

Another attribute that we will use in a future blog post, is the toolbox: string = ToolboxName, where ToolboxName is the name of the toolbox profile for the toolbox that opens automatically each time a diagram is opened.

Saving your profile

Save your diagram as an UML profile just like you did for the profile, and open the saved file in a notepad editor. The file should look like:

<?xml version="1.0" encoding="windows-1252"?>
<UMLProfile profiletype="uml2">
    <Documentation id="C3C4B4EC-4" name="MdgDiagrams" version="1.0" alias="MDG Diagrams" notes="Some description for MDG Diagrams"/>
    <Content>
        <Stereotypes>
            <Stereotype name="MyDiagram1" alias="My Diagram 1" notes="Some description for My Diagram 1." cx="90" cy="70" bgcolor="-1" fontcolor="-1" bordercolor="-1" borderwidth="-1" hideicon="0">
                <AppliesTo>
                    <Apply type="Diagram_Class">
                        <Property name="alias" value="My Diagram 1"/>
                        <Property name="diagramID" value="MD1"/>
                    </Apply>
                </AppliesTo>
            </Stereotype>
        </Stereotypes>
        <TaggedValueTypes/>
    </Content>
</UMLProfile>

You can’t test this like we did in the previous post, but you can test it by creating an MDG Technology.

Creating an MDG Technology

In the menu bar click Tools >> Generate MDG Technology File (alternatively use Alt+T followed by T). Click Next.

For the first time, choose “Create a new MTS file” and click Next.

image

Browse to a folder and give the file a proper name.

Give the MDG Technology a proper name, for instance “MdgManual”. In the filename-field, browse to “C:\Program Files\Sparx Systems\EA\MDGTechnologies” and give your file a name. Fill in the ID-field, the Version-field and the Notes-field. Click Next.

image

In the help-file of EA you can find the following description about the fields you can use:

image

Remember to increment version and release number during subsequent changes. EA chooses the one with the highest number which is good during testing.

Add “Diagram Types” to the selection list. Click Next.

image

Navigate to your folder containing the profile-file. Move the Profile.xml to the right side. Click Next.

image

Navigate to your folder containing the diagram-file. Move the Diagram.xml to the right side. Click Next.

image

Finish.

To test your MDG Technology, start a new instance of EA.

Navigate to Settings >> MDG Technologies… A new window opens and in the list of Technologies, you should see your newly created Technology. Close the window.

image

Now navigate to a package and add a diagram. You will find the “MDG Diagrams” on the left hand side. When you select it, you’ll find your newly created diagram on the right hand side. Click ok.

image

As you can see, the default toolbox associated with a Class Diagram is opened. To use your element created in a previous post, you have to select “More Tools…” and then you’ll find the MdgProfile toolbox. Now you can start using your element.

Very nice, but it would be even nicer if the toolbox opens automatically when opening your custom diagram. We will cover that in the next post.