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.