11/04/2011

Creating an MDG – Part 3: Creating toolboxes

 

OK, so far we have seen how to create custom elements (see Creating an MDG - Part 1: Create an UML Profile) and custom diagrams (see Creating an MDG - Part 2: Creating diagrams), but it would be nice if we could create a custom toolbox that opens automatically when we open our custom diagram, showing our custom elements.

This is how to do it.

Open the file

First of all, open the the eap-file created in our previous topic. Create a package “MyToolbox1” and stereotype it as “profile”. Add a class diagram to the package. In our series, we will make several toolboxes, so it is best if you gather them in a package called “MyToolboxes”.

image

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

image

Create a new toolbox

Drag a Metaclass-item on the diagram, choose the type “Boundary” and name it “ToolboxPage”.

image

Drag a Stereotype-item on the diagram, and name it “MyToolbox1”. Add an alias and a description.

image

Adding elements to toolbox

In the attributes-window of the toolbox-stereotype, add an attribute with a name of “MdgProfile::MyElement” and an initial value of “My Element”.

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

Associating toolbox with diagram

Now open the class-diagram “MdgDiagrams” and add an attribute to the “Diagram_Class”-element. Give it a name of “toolbox”, a type of “string” and an initial value of “MyToolbox1”.

image

Saving your profile

Save your toolbox as an UML profile just like you did for the profile and the diagram, 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="09F304F7-B" name="MyToolbox1" version="1.0" alias="My Toolbox 1" notes="Some description for My Toolbox 1"/>
    <Content>
        <Stereotypes>
            <Stereotype name="MyToolbox1" alias="My Toolbox 1" notes="Some description for My Toolbox 1" cx="90" cy="70" bgcolor="-1" fontcolor="-1" bordercolor="-1" borderwidth="-1" hideicon="0">
                <AppliesTo>
                    <Apply type="ToolboxPage"/>
                </AppliesTo>
                <TaggedValues>
                    <Tag name="MdgProfile::MyElement" type="" description="" unit="" values="" default="My Element"/>
                </TaggedValues>
            </Stereotype>
        </Stereotypes>
        <TaggedValueTypes/>
    </Content>
</UMLProfile>

You can test this like we did in the previous post. Save the profile, the diagram and the toolbox as an UML Profile, and recreate the MDG-file (Alt+T followed by T). Click Next.

Open an existing file and choose the .mts file you saved in the previous post. Click Next. Next. Next. Select Toolboxes (Profiles and Diagrams should already be selected).

image

Click Next. Next. Next. Navigate to where you saved your toolbox profile and add it the right side.

Click Next. Finish.

When you browse to C:\Program Files\Sparx Systems\EA\MDGTechnologies you should see an xml-file created by the MDG Technology Creation Wizard, “MDG Manual.xml”. Open it in an notepad-editor. Your file should look like:

<MDG.Technology version="1.0"><Documentation id="MM" name="MDG Manual" version="0.1" notes="Some description"/><UMLProfiles><UMLProfile profiletype="uml2">
            <Documentation id="70F009FC-A" name="MdgProfile" version="1.0" alias="MDG Profile" notes="MDG Technology for MDG Manual"/>
            <Content>
                <Stereotypes>
                    <Stereotype name="MyElement" alias="My Element" metatype="myElement" notes="Some description for MyElement" cx="90" cy="70" bgcolor="255" fontcolor="-1" bordercolor="-1" borderwidth="1" hideicon="0">
                        <AppliesTo>
                            <Apply type="Class">
                                <Property name="isActive" value=""/>
                            </Apply>
                        </AppliesTo>
                        <TaggedValues>
                            <Tag name="Disable" type="boolean" description="" unit="" values="true,false" default="false"/>
                            <Tag name="UsingMyEnumeration" type="enumeration" description="" unit="" values="value1,value2,value3" default="value1"/>
                        </TaggedValues>
                    </Stereotype>
                </Stereotypes>
                <TaggedValueTypes/>
            </Content>
        </UMLProfile>
    </UMLProfiles><DiagramProfile><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"/>
                                <Property name="toolbox" value="MyToolbox1"/>
                            </Apply>
                        </AppliesTo>
                    </Stereotype>
                </Stereotypes>
                <TaggedValueTypes/>
            </Content>
        </UMLProfile>
    </DiagramProfile><UIToolboxes><UMLProfile profiletype="uml2">
            <Documentation id="09F304F7-B" name="MyToolbox1" version="1.0" alias="My Toolbox 1" notes="Some description for My Toolbox 1"/>
            <Content>
                <Stereotypes>
                    <Stereotype name="MyToolbox1" alias="My Toolbox 1" notes="Some description for My Toolbox 1" cx="90" cy="70" bgcolor="-1" fontcolor="-1" bordercolor="-1" borderwidth="-1" hideicon="0">
                        <AppliesTo>
                            <Apply type="ToolboxPage"/>
                        </AppliesTo>
                        <TaggedValues>
                            <Tag name="MdgProfile::MyElement" type="" description="" unit="" values="" default="My Element"/>
                        </TaggedValues>
                    </Stereotype>
                </Stereotypes>
                <TaggedValueTypes/>
            </Content>
        </UMLProfile>
    </UIToolboxes></MDG.Technology>

Open a new instance of Sparx. Add a diagram somewhere and on the left, navigate to “MDG Diagrams” and select your custom diagram on the right side. Notice that when the custom diagram is created, the default custom toolbox is opened with our custom element.

Finished.

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.

06/04/2011

Creating an MDG – Part 1: Create an UML Profile

 

Why creating UML Profiles in Sparx EA? According to the Help-file in Sparx:

“UML Profiles provide a means of extending the UML Language, which enables you to build UML models in particular domains. They are based on additional stereotypes and Tagged Values that are applied to UML elements, connectors and their components. A Profile is a collection of such extensions that together describe some particular modeling problem and facilitate modeling constructs in that domain. UML Profiles for Enterprise Architect are specified in XML files, with a specific format. These XML files can be imported into Enterprise Architect through the Resources window.

The imported Profile also automatically generates a page of elements and relationships in the Enterprise Architect UML Toolbox.

The Resources window contains a tree structure with entries for items such as MDG Technologies, Documents, Style sheets, Matrix profiles and UML Profiles. The UML Profiles node initially contains no entries; to be able to use Profiles you must import them into Enterprise Architect from supplied XML files.

Items in the Profile represent stereotypes. UML supports a large number of stereotypes, which are an inbuilt mechanism for logically extending or altering the meaning, display, appearance and syntax of a model element. Different model elements have different stereotypes associated with them.”

The profile will tell you which model elements are available for modeling in EA. The model elements can be created by drag and drop from the toolbox. But how to do it?

Create the file

First of all, create a new eap-file and add a package to the model that will contain your profile (in this case the package “MDG Profile”). Open the properties of the folder and stereotype it as “profile”. Add a Class-diagram to the folder.

image

Make sure not to use spaces in the names of the packages or the diagrams. If you need to use spaces, you can alias your package while using spaces. You should also add a description to the notes-field for clarity.

image

Create a new element

If you want to create new elements, add a Class-item to the diagram and stereotype it as a “metaclass”. Alternatively, drag a Metaclass-item from the Profile-toolbox and drop it on the diagram. In the window that appears, choose a “Class”-element (or something else if you want to inherit from another existing element). Your new element will eventually inherit from the Class-metaclass.

image

To create your own new element, drag a Stereotype-item on the diagram and give it a name of “MyElement”.

image

Optionally give it an alias and a description.

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

Create tagged values

Right now you have created your own element which in the end you could use for your modeling. But if you don’t add new functionality to your newly created element, then it wouldn’t make sense to extend the Class-element. So now we are going to stereotype our new element as “myElement”, add an attribute (which will eventually appear in the Tagged Values window) with a boolean type and add an attribute with a custom enumeration-type.

Standard tagged values

To create a stereotype for your element, add an attribute with the name ‘_metatype’, and fill in the name in the Initial-field. Make sure you don’t change the Type-field!!

image

Custom tagged values – standard type

To create a Disable-field with a boolean-value, add an attribute as in the picture below. If you want, you can give it a default value in the Initial-field.

image

Custom tagged values – custom enumeration type

First drag an enumeration-item on the diagram, give it a proper name, and add the possible values via the attributes-window (without ‘Typing’ them).

image

Then, in our new element, add an attribute called “UsingMyEnumeration”. In the Type-field, select “Select Type…” and browse to your newly created enumeration. If wanted, give the attribute a default value.

image

Appearance

If you want, you can give your new element a custom default appearance (for example a red color).

image

Alternatively, you can create shape-scripts to change the appearance of your element. You can even adapt the appearance of your shape depending on attribute-values.

For that, you add an attribute with a name of “_image” (again don’t change the Type-field) and click on the ellipsis-button.

image

A new window will appear where you can add a shape-script. On the right side you can preview the result.

image

Using your profile

We now need to export the profile to be able to use it in future modeling. Right click the MdgProfile package and select “Save Package as UML Profile”. Navigate to the folder where you want to save the profile, and give the file a meaningful name (which will receive the extension .xml).

A new window appears. The Profile Name-field is default populated with the name of the package, and the Notes-field is populated with the value of the Notes-field in the package-properties. Click “Save” with the default settings.

image

If you open the file in a notepad-editor, your file should look like this:

<?xml version="1.0" encoding="windows-1252"?>
<UMLProfile profiletype="uml2">
    <Documentation id="FE160B62-2" name="MdgProfile" version="1.0" alias="MDG Profile" notes="MDG Technology for MDG Manual."/>
    <Content>
        <Stereotypes>
            <Stereotype name="MyElement" alias="My Element" metatype="myElement" notes="Some description for MyElement" cx="90" cy="70" bgcolor="255" fontcolor="-1" bordercolor="-1" borderwidth="1" hideicon="0">
                <AppliesTo>
                    <Apply type="Class">
                        <Property name="isActive" value=""/>
                    </Apply>
                </AppliesTo>
                <TaggedValues>
                    <Tag name="Disable" type="boolean" description="" unit="" values="true,false" default="false"/>
                    <Tag name="UsingMyEnumeration" type="enumeration" description="" unit="" values="value1,value2,value3" default="value1"/>
                </TaggedValues>
            </Stereotype>
        </Stereotypes>
        <TaggedValueTypes/>
    </Content>
</UMLProfile>

Now you can test your profile by importing it via the Resources window (View >> Other Project Tools >> Resources). Right click the UML Profile folder in the Resources window and select “Import Profile”. Browse to the previously saved file and click “Import” and notice the new entry “MdgProfile” with one element in the tree: MyElement.

image

Now test the profile by dragging the element on the diagram. It should color red, and if you select the element on the diagram, you should see the previously created attributes in the Tagged Values window.

image

Notice the stereotype of our element (in yellow) and the two attributes with a picklist, “Disable” with a true/false picklist, and “UsingMyEnumeration” with our custom enumeration-picklist.

Finished.