Sei sulla pagina 1di 39
MDA Designer Light Tutorial Creating the UMLTODO module Version: 1.0 Publication: 30/04/2010 Copyright: Modeliosoft

MDA Designer Light Tutorial

Creating the UMLTODO module

Version: 1.0 Publication: 30/04/2010

Copyright: Modeliosoft

MDA Designer Light Tutorial Creating the UMLTODO module Version: 1.0 Publication: 30/04/2010 Copyright: Modeliosoft
MDA Designer Light Tutorial Creating the UMLTODO module Version: 1.0 Publication: 30/04/2010 Copyright: Modeliosoft
MDA Designer Light Tutorial Creating the UMLTODO module Version: 1.0 Publication: 30/04/2010 Copyright: Modeliosoft

Tutorial

Tutorial 1 Introduction 3 1.1 Aim of this tutorial 3 1.2 Prerequisites 4 2 Creating a
Tutorial 1 Introduction 3 1.1 Aim of this tutorial 3 1.2 Prerequisites 4 2 Creating a
Tutorial 1 Introduction 3 1.1 Aim of this tutorial 3 1.2 Prerequisites 4 2 Creating a
Tutorial 1 Introduction 3 1.1 Aim of this tutorial 3 1.2 Prerequisites 4 2 Creating a

1

Introduction

3

1.1

Aim of this tutorial

3

1.2

Prerequisites

4

2

Creating a module development project

5

2.1

In Modelio Free Edition and Modelio Java Express Edition

5

2.2

In Modelio Enterprise Edition

7

3

Creating the TODO module

9

3.1

Creating the module

9

3.2

Creating stereotypes and note types

13

3.3

Adding an external jar to the module

17

3.4

Creating the "AddTODO" command

19

3.4.1

Creating the "AddTODO" command

19

3.4.2

Implementing the "AddTODO" command

24

3.5

Creating the "List" command

26

3.5.1

Creating the "List" command

26

3.5.2

Implementing the "List" command

27

3.6

Creating a property page

30

3.6.1

Creating a property page

30

3.6.2

Implementing property editors

31

4

Compiling, Packaging and Testing

34

4.1

Compiling and packaging the module

34

4.2

Deploying and testing the module

36

4.2.1

Deploying the module

36

4.2.2

Testing the module

37

4.2.3

And what about MDA Designer Enterprise Edition?

39

 

Page 2

Tutorial

1

Introduction

1.1 Aim of this tutorial

This tutorial presents the different steps involved in the creation of a MDA module with MDA Designer Light and Modelio 1.2.00.

The example presented is the creation of the UMLTODO module. This module must first enable "TODOs" to be added to UML model elements. Later, a listing feature will enable all the "TODOs" defined in the module to be displayed.

To realize this module, we are going to create the following:

A « TODO » stereotype which will be used to type notes containing the "TODO"

A « TODO » stereotype which will be used to type notes containing the "TODO" text.

A command to add a "TODO" to a UML metamodel element, in other words a

A command to add a "TODO" to a UML metamodel element, in other words a command to

add to an element a note stereotyped « TODO », whose content is the description of the "TODO".

A command to list and display all existing "TODOs".

A

command to list and display all existing "TODOs".

customized properties page enabling the user to display and modify the description of a "TODO".

customized properties page enabling the user to display and modify the description of a "TODO".

A

customized properties page enabling the user to display and modify the description of a "TODO". A
customized properties page enabling the user to display and modify the description of a "TODO". A
customized properties page enabling the user to display and modify the description of a "TODO". A
customized properties page enabling the user to display and modify the description of a "TODO". A

Page 3

Tutorial

1.2

Prerequisites

We strongly recommend that you read the MDA Designer Light user guide before you start this tutorial.

Before you begin, make sure you have the following elements:

Modelio v 1.2.00 (Enterprise Edition, Free Edition or Java Edition)Before you begin, make sure you have the following elements: Download here: http://www.modeliosoft.com/ A JDK 1.6

A JDK 1.6or Java Edition) Download here: http://www.modeliosoft.com/ Download here:

The UMLTODORessources.zip archive containing the resources necessary to the implementation of this tutorial.here: http://java.sun.com/javase/downloads/index.jsp Note: If you are in a hurry, a complete implementation of

Note:

If you are in a hurry, a complete implementation of the UMLTODO module is available in the form of

a Modelio project that you can import. To install this implementation in your Modelio workspace, carry out the following operations:

1. Start Modelio.

2. Run the "File/Import project" command.

3. Import the "UMLTODO.zip" project.

1. Start Modelio. 2. Run the "File/Import project" command. 3. Import the "UMLTODO.zip" project. Page 4
1. Start Modelio. 2. Run the "File/Import project" command. 3. Import the "UMLTODO.zip" project. Page 4
1. Start Modelio. 2. Run the "File/Import project" command. 3. Import the "UMLTODO.zip" project. Page 4
1. Start Modelio. 2. Run the "File/Import project" command. 3. Import the "UMLTODO.zip" project. Page 4

Page 4

Tutorial

2 Creating a module development project

2.1 In Modelio Free Edition and Modelio Java Express Edition

2.1 In Modelio Free Edition and Modelio Java Express Edition 1. Start Modelio Free Edition (or
2.1 In Modelio Free Edition and Modelio Java Express Edition 1. Start Modelio Free Edition (or
2.1 In Modelio Free Edition and Modelio Java Express Edition 1. Start Modelio Free Edition (or
2.1 In Modelio Free Edition and Modelio Java Express Edition 1. Start Modelio Free Edition (or

1. Start Modelio Free Edition (or Java Express Edition).

2. Create a new module development project:

Menu command: File > New module development project

Menu command: File > New module development project 3. Enter the name of the project and

3. Enter the name of the project and a description of it:

a. Project name: "UMLTODO"

b. Description: "UMLTODO module development project"

Page 5

Tutorial

Tutorial 4. Click on the "Create" button. The "UMLTODO" project is then created and the MDA

4. Click on the "Create" button. The "UMLTODO" project is then created and the MDA explorer opened.

4. Click on the "Create" button. The "UMLTODO" project is then created and the MDA explorer
4. Click on the "Create" button. The "UMLTODO" project is then created and the MDA explorer
4. Click on the "Create" button. The "UMLTODO" project is then created and the MDA explorer
4. Click on the "Create" button. The "UMLTODO" project is then created and the MDA explorer
4. Click on the "Create" button. The "UMLTODO" project is then created and the MDA explorer

Page 6

Tutorial

Tutorial 2.2 In Modelio Enterprise Edition 1. Start Modelio Enterprise Edition. 2. Create a standard UML
Tutorial 2.2 In Modelio Enterprise Edition 1. Start Modelio Enterprise Edition. 2. Create a standard UML
Tutorial 2.2 In Modelio Enterprise Edition 1. Start Modelio Enterprise Edition. 2. Create a standard UML
Tutorial 2.2 In Modelio Enterprise Edition 1. Start Modelio Enterprise Edition. 2. Create a standard UML

2.2 In Modelio Enterprise Edition

1. Start Modelio Enterprise Edition.

2. Create a standard UML project.

Enterprise Edition. 2. Create a standard UML project. 3. Enter the name of the project and

3. Enter the name of the project and a description of it:

a. Project name: "UMLTODO"

b. Description: "UMLTODO module development project"

c. Click on the "Create the project" button. The "UMLTODO" project is then created.

Page 7

Tutorial

Tutorial 4. Install the MDA Designer Light module using the dedicated command. Menu command: MDA >
Tutorial 4. Install the MDA Designer Light module using the dedicated command. Menu command: MDA >
Tutorial 4. Install the MDA Designer Light module using the dedicated command. Menu command: MDA >
Tutorial 4. Install the MDA Designer Light module using the dedicated command. Menu command: MDA >
Tutorial 4. Install the MDA Designer Light module using the dedicated command. Menu command: MDA >

4. Install the MDA Designer Light module using the dedicated command. Menu command: MDA > Install a module

Page 8

Tutorial

Tutorial 5. Select the "MdaDesignerLight.jmdac" file. 6. Use the "Views" menu to open the MDA explorer
Tutorial 5. Select the "MdaDesignerLight.jmdac" file. 6. Use the "Views" menu to open the MDA explorer
Tutorial 5. Select the "MdaDesignerLight.jmdac" file. 6. Use the "Views" menu to open the MDA explorer
Tutorial 5. Select the "MdaDesignerLight.jmdac" file. 6. Use the "Views" menu to open the MDA explorer
Tutorial 5. Select the "MdaDesignerLight.jmdac" file. 6. Use the "Views" menu to open the MDA explorer

5. Select the "MdaDesignerLight.jmdac" file.

6. Use the "Views" menu to open the MDA explorer (Menu command: Views > Show MDA explorer).

3 Creating the TODO module

At this stage, we have created a module development project in Modelio. We are now going to continue by creating the different elements that will define our module, starting with the module itself.

3.1 Creating the module

1. Create a new module using the dedicated menu command:

Menu command: MDA > Create a module

Page 9

Tutorial

Tutorial 2. Enter a name and a description for the module, and choose an icon that

2. Enter a name and a description for the module, and choose an icon that will graphically represent it:

and choose an icon that will graphically represent it: a. Module name: " UMLTODO " b.
and choose an icon that will graphically represent it: a. Module name: " UMLTODO " b.
and choose an icon that will graphically represent it: a. Module name: " UMLTODO " b.
and choose an icon that will graphically represent it: a. Module name: " UMLTODO " b.

a. Module name: "UMLTODO"

b. Description: "Module to manage TODOs on UML model elements"

c. Icon: UMLTODOResources\eye1.bmp

Page 10

Tutorial

Tutorial 3. Click on "Next". 4. Check the module’s namespace and the path of the JDK.

3. Click on "Next".

4. Check the module’s namespace and the path of the JDK. If no JDK is indicated, select the directory where your JDK1.6 is installed.

namespace and the path of the JDK. If no JDK is indicated, select the directory where
namespace and the path of the JDK. If no JDK is indicated, select the directory where
namespace and the path of the JDK. If no JDK is indicated, select the directory where
namespace and the path of the JDK. If no JDK is indicated, select the directory where

Page 11

Tutorial

Tutorial 5. Click on "Create module" to launch the module creation operation. The UMLTODO module is

5. Click on "Create module" to launch the module creation operation. The UMLTODO module is created in the MDA explorer view.

module" to launch the module creation operation. The UMLTODO module is created in the MDA explorer
module" to launch the module creation operation. The UMLTODO module is created in the MDA explorer
module" to launch the module creation operation. The UMLTODO module is created in the MDA explorer
module" to launch the module creation operation. The UMLTODO module is created in the MDA explorer

Page 12

Tutorial

Tutorial 3.2 Creating stereotypes and note types Stereotypes are new modeling elements that extend the semantics
Tutorial 3.2 Creating stereotypes and note types Stereotypes are new modeling elements that extend the semantics
Tutorial 3.2 Creating stereotypes and note types Stereotypes are new modeling elements that extend the semantics
Tutorial 3.2 Creating stereotypes and note types Stereotypes are new modeling elements that extend the semantics
Tutorial 3.2 Creating stereotypes and note types Stereotypes are new modeling elements that extend the semantics

3.2 Creating stereotypes and note types

Stereotypes are new modeling elements that extend the semantics of a UML metamodel element. We are going to create a stereotype that will enable us to represent a UML metamodel element on which there is a TODO.

1. Right-click on the "UMLTODOProfile" and run the dedicated stereotype creation command:

Menu command: Create MDA element > Stereotype

Page 13

Tutorial

Tutorial 2. Enter a name for the new stereotype, and indicate the metaclass on which it
Tutorial 2. Enter a name for the new stereotype, and indicate the metaclass on which it
Tutorial 2. Enter a name for the new stereotype, and indicate the metaclass on which it
Tutorial 2. Enter a name for the new stereotype, and indicate the metaclass on which it
Tutorial 2. Enter a name for the new stereotype, and indicate the metaclass on which it

2. Enter a name for the new stereotype, and indicate the metaclass on which it will apply. In practice, this indicates to which model elements the stereotype will be applicable. In our example, we have chosen "ModelTree", which means that we will be able to apply a TODO to packages, classes, use cases, and so on, but not to attributes or operations, for example. This choice is made by consulting the metamodel documentation according to the desired result and by using the metamodel inheritance graph.

a. Stereotype name: "TODO"

b. Metaclass: "ModelTree"

Page 14

Tutorial

Tutorial 3. Click on "Create": The new TODO stereotype is then created. It is visible inside

3. Click on "Create": The new TODO stereotype is then created. It is visible inside the "UMLTODOProfile" profile in the MDA explorer view.

We are now going to create a type of note in the "TODO" stereotype. This note will contain the description associated with a TODO.

1. Right-click on the "TODO" stereotype to activate the note creation command:

Menu command: Create MDA element > Note type

"TODO" stereotype to activate the note creation command: Menu command: Create MDA element > Note type
"TODO" stereotype to activate the note creation command: Menu command: Create MDA element > Note type
"TODO" stereotype to activate the note creation command: Menu command: Create MDA element > Note type
"TODO" stereotype to activate the note creation command: Menu command: Create MDA element > Note type

Page 15

Tutorial

Tutorial 2. A new note type is then created. Change its name (F2 or double-click on

2. A new note type is then created. Change its name (F2 or double-click on the object’s text) to "TODO_NoteType".

type is then created. Change its name (F2 or double-click on the object’s text ) to
type is then created. Change its name (F2 or double-click on the object’s text ) to
type is then created. Change its name (F2 or double-click on the object’s text ) to
type is then created. Change its name (F2 or double-click on the object’s text ) to

Page 16

Tutorial

Tutorial We now have two UML extensions – a « TODO » stereotype that can be

We now have two UML extensions a « TODO » stereotype that can be applied to any ModelTree type element, and associated with this stereotype, a "TODO_NoteType" note type, which will enable us to recognize notes that contain the text of our TODOs.

us to recognize notes that contain the text of our TODOs. 3.3 Adding an external jar
us to recognize notes that contain the text of our TODOs. 3.3 Adding an external jar
us to recognize notes that contain the text of our TODOs. 3.3 Adding an external jar
us to recognize notes that contain the text of our TODOs. 3.3 Adding an external jar

3.3 Adding an external jar to the module

To realize the implementation of the module’s commands, we are going to use the services provided by an external jar, namely the ReportUtils.jar jar (available in the resources provided with this tutorial). This approach is not indispensable here, and this part of the code could also be developed within our module. However, this approach is useful here, since it demonstrates two operations:

- We will demonstrate how to integrate external services available in the form of an API in a jar into our module.

- We will also demonstrate a practice which is recommended in certain complex situations, where a big part of the code, more linked to the "business" or to particular processing that to the actual module itself, is finally developed outside the module and is then transferred into and used by the module.

Page 17

Tutorial

In order to use this jar, we must first add it to the project.

1. Right-click on the "Library" directory and run the dedicated external jar addition command:

Menu command: Create MDA Designer Light element > External Jar

Create MDA Designer Light element > External Jar 2. Select the ReportUtils.jar jar. This jar is
Create MDA Designer Light element > External Jar 2. Select the ReportUtils.jar jar. This jar is
Create MDA Designer Light element > External Jar 2. Select the ReportUtils.jar jar. This jar is
Create MDA Designer Light element > External Jar 2. Select the ReportUtils.jar jar. This jar is
Create MDA Designer Light element > External Jar 2. Select the ReportUtils.jar jar. This jar is

2. Select the ReportUtils.jar jar. This jar is then added to the project.

Page 18

Tutorial

Tutorial In our example, the ReportUtils.jar jar mainly contains display services (GUI) for a TODO list.

In our example, the ReportUtils.jar jar mainly contains display services (GUI) for a TODO list.

jar mainly contains display services (GUI) for a TODO list. 3.4 Creating the "AddTODO" command At
jar mainly contains display services (GUI) for a TODO list. 3.4 Creating the "AddTODO" command At
jar mainly contains display services (GUI) for a TODO list. 3.4 Creating the "AddTODO" command At
jar mainly contains display services (GUI) for a TODO list. 3.4 Creating the "AddTODO" command At

3.4 Creating the "AddTODO" command

At this stage, our module contains the elements we need to model TODOs (the stereotype and the note type) and the elements required to display them in the form of a list (the external ReportUtils.jar jar). We are now going to complete the module by creating the user commands which will make it usable.

3.4.1 Creating the "AddTODO" command

Adding a TODO to an element currently consists, at model level, of adding the « TODO » stereotype and a « TODO_NoteType » note to the element, and of defining the content of this note. This sequence of operations is not practical for someone using our module, and as a consequence, and in order to facilitate these operations, we are now going to create the command that will enable a user to simply add a TODO to a UML metamodel element.

1. Right-click on the "Commands" directory and run the dedicated command creation command:

Menu command: Create MDA Designer Light element > Command

Page 19

Tutorial

Tutorial 2. Enter a name and a description for the command, and choose an icon to

2. Enter a name and a description for the command, and choose an icon to represent it:

for the command, and choose an icon to represent it: a. Name: AddTODO b. Description: Add
for the command, and choose an icon to represent it: a. Name: AddTODO b. Description: Add
for the command, and choose an icon to represent it: a. Name: AddTODO b. Description: Add
for the command, and choose an icon to represent it: a. Name: AddTODO b. Description: Add

a. Name: AddTODO

b. Description: Add a TODO to a metamodel element

c. Icon: UMLTODOResources\report_plus.png

Page 20

Tutorial

Tutorial 3. Click on the "Next" button. 4. The window which then appears (shown below) is
Tutorial 3. Click on the "Next" button. 4. The window which then appears (shown below) is
Tutorial 3. Click on the "Next" button. 4. The window which then appears (shown below) is
Tutorial 3. Click on the "Next" button. 4. The window which then appears (shown below) is
Tutorial 3. Click on the "Next" button. 4. The window which then appears (shown below) is

3. Click on the "Next" button.

4. The window which then appears (shown below) is used to determine which stereotype and/or which metaclass the command will applicable to. A command can be applicable to several metaclasses and stereotypes.

Page 21

Tutorial

Tutorial 5. Select ObModelTree from the list of metaclasses and click on the green arrow. 6.

5. Select ObModelTree from the list of metaclasses and click on the green arrow.

from the list of metaclasses and click on the green arrow. 6. Click on the "Next"
from the list of metaclasses and click on the green arrow. 6. Click on the "Next"
from the list of metaclasses and click on the green arrow. 6. Click on the "Next"
from the list of metaclasses and click on the green arrow. 6. Click on the "Next"

6. Click on the "Next" button.

7. The window which then appears (shown below) is used to determine the menus/views where the command will be available, and also to define certain properties belonging to the command:

Page 22

Tutorial

Tutorial a. You want the command to appear in the context menu: => Tick the "Add

a. You want the command to appear in the context menu:

=> Tick the "Add command to contextual menu" box

b. You want the command to appear in the property page:

=> Tick the "Add command to property page" box

=> Tick the "Add command to property page" box c. The command will result in the
=> Tick the "Add command to property page" box c. The command will result in the
=> Tick the "Add command to property page" box c. The command will result in the
=> Tick the "Add command to property page" box c. The command will result in the

c. The command will result in the model being modified through the addition of a stereotype to a metamodel element:

=>Select "The command can modify the model".

8. Click on the "Create command" button. The command is then created and the corresponding Java editor automatically opened.

Page 23

Tutorial

Tutorial 3.4.2 Implementing the "AddTODO" command The "AddTODO" command is implemented in Java using the
Tutorial 3.4.2 Implementing the "AddTODO" command The "AddTODO" command is implemented in Java using the
Tutorial 3.4.2 Implementing the "AddTODO" command The "AddTODO" command is implemented in Java using the
Tutorial 3.4.2 Implementing the "AddTODO" command The "AddTODO" command is implemented in Java using the
Tutorial 3.4.2 Implementing the "AddTODO" command The "AddTODO" command is implemented in Java using the

3.4.2 Implementing the "AddTODO" command

The "AddTODO" command is implemented in Java using the dedicated editor. At any time you can open this command editor, using the "Open editor" command available in the contextual menu on the "AddTODO" command.

The "AddTODO" command enables the user to add a TODO to the UML model element currently selected in the UML view. In the case of our command, this will add a «TODO » stereotype and a "TODO_NOTETYPE" note type to the selected element.

Warning: Since the addition of a stereotype represents a modification to the UML model, it must, like any other model modification in Modelio, be carried out inside a transaction.

Creating a transaction in Modelio

boolean commit = false;

IModelingSession session = Modelio.getInstance().getModelingSession(); // Create a transaction ITransaction tr = session.createTransaction("Add a TODO"); try {

// Implementation

Page 24

Tutorial

// Commit transaction commit = true; session.commit(tr); } catch (Exception e) { e.printStackTrace(); if (!commit) session.rollback(tr);

}

if (!commit) session.rollback(tr); } We are going to use the services of the ObUtils service

We are going to use the services of the ObUtils service class to add the TODO stereotype and the note to the selected element.

o Adding the « TODO » stereotype to the element:

// Add the TODO stereotype to the selected element ObUtils.addStereotype(session, element, UMLTODOStereotypes.TODO)

o For the addition of the TODO_NOTETYPE note type to the selected element, the ObUtils service class again facilitates the writing of the code.

// Create a note on the element ObUtils.putNoteContent(session, element, UMLTODONoteTypes.TODO_NOTETYPE, "");

element, UMLTODONoteTypes.TODO_NOTETYPE, ""); Complete implementation of the AddTODO command package
element, UMLTODONoteTypes.TODO_NOTETYPE, ""); Complete implementation of the AddTODO command package
element, UMLTODONoteTypes.TODO_NOTETYPE, ""); Complete implementation of the AddTODO command package
element, UMLTODONoteTypes.TODO_NOTETYPE, ""); Complete implementation of the AddTODO command package

Complete implementation of the AddTODO command

package com.modeliosoft.modelio.umltodo.command;

import com.modeliosoft.modelio.api.Modelio; import com.modeliosoft.modelio.api.mda.app.IModelingSession; import com.modeliosoft.modelio.api.mda.gui.commands.DefaultMdacContextualCommand; import com.modeliosoft.modelio.api.mda.model.ObUtils; import com.modeliosoft.modelio.api.mdac.IJavaMdac; import com.modeliosoft.modelio.api.model.ObElement; import com.modeliosoft.modelio.api.model.ObModelTree; import com.modeliosoft.modelio.api.model.utils.ObList; import com.modeliosoft.modelio.core.jni.ITransaction; import com.modeliosoft.modelio.umltodo.api.UMLTODONoteTypes; import com.modeliosoft.modelio.umltodo.api.UMLTODOStereotypes;

public class AddTODO extends DefaultMdacContextualCommand {

@Override public void actionPerformed(ObList<ObElement> selectedElements, IJavaMdac module) { boolean commit = false;

IModelingSession session = Modelio.getInstance().getModelingSession(); ITransaction tr = session.createTransaction("Transaction"); try { ObModelTree element = (ObModelTree)selectedElements.get(0);

// Add the TODO stereotype to the selected element ObUtils.addStereotype(session, element, UMLTODOStereotypes.TODO);

// Create a note on the element ObUtils.putNoteContent(session, element, UMLTODONoteTypes.TODO_NOTETYPE, "");

Page 25

Tutorial

commit = true; Modelio.getInstance().getModelingSession().commit(tr); } catch (Exception e) { e.printStackTrace(); if (!commit) session.rollback(tr);

}

}

/**

* This methods authorizes a command to be displayed in a defined context.

* The commands are displayed, by default, depending on the kind of metaclass on which the command has been launched. */ @Override public boolean accept(ObList<ObElement> selectedElements, IJavaMdac module) { // TODO Define the dynamic filtering conditions to display the command, in order to refine the command activation depending on specific markers that can be defined on the

selection (tagged value, specific properties return true;

).

}

/**

* This method specifies whether or not a command must be deactivated.

* If the command has to be displayed (which means that the accept method has returned a

positive value, it is sometimes needed to desactivate the command depending on specific

constraints that are specific to the module. */ @Override public boolean isActiveFor(ObList<ObElement> selectedElements, IJavaMdac module) { return true;

}

}

3.5 Creating the "List" command

We are now going to user of our module with a "List" command that will display the all the TODOs that currently exist in his model.

display the all the TODOs that currently exist in his model. 3.5.1 Creating the "List" command
display the all the TODOs that currently exist in his model. 3.5.1 Creating the "List" command
display the all the TODOs that currently exist in his model. 3.5.1 Creating the "List" command
display the all the TODOs that currently exist in his model. 3.5.1 Creating the "List" command

3.5.1 Creating the "List" command

We are now going to create the "List" command that will enable us to display a list of all the TODOs that have been defined in the model.

To create this command, we are going to carry out the same operations as those carried out when creating the "AddTODO" command in the previous chapter.

1. Enter a name and a description for the command, and choose an icon to represent it:

a. Name: List

b. Description: List all TODOs

c. Icon: UMLTODOResources\Report.png

2. Click on the "Next" button.

3. Select ObModelTree from the list of metaclasses and click on the green arrow.

Page 26

Tutorial

4. Click on the "Next" button.

a. You want the command to appear in the context menu:

=> Tick the "Add command to contextual menu" box

b. You want the command to appear in the property page:

=> Tick the "Add command to property page" box

c. The command will not result in the model being modified:

=> Select "The command can’t modify the model".

3.5.2 Implementing the "List" command

The "List" command is implemented in Java using the dedicated editor. At any time you can open this command editor, using the "Open editor" command available in the contextual menu on the "List" command.

The "List" command enables the user to obtain a list of all the model elements that have a TODO and to present this list to the user. Display of this list is realized using the ReportUtils class, which is provided by the ReportUtils.jar jar that we added to the project earlier. The ReportUtils class creates a report (dialog box) and adds all the elements to display to this report.

We are going to start by writing a method that will enable us to browse all sub-elements stereotyped « TODO » present inside the selected element. This method is recursive.

The API used to browse the UML model is based on the Modelio metamodel.

to browse the UML model is based on the Modelio metamodel. To find the name of
to browse the UML model is based on the Modelio metamodel. To find the name of
to browse the UML model is based on the Modelio metamodel. To find the name of
to browse the UML model is based on the Modelio metamodel. To find the name of

To find the name of the method used to retrieve all ModelTree type elements (Class , Package …) defined inside a ModelTree, you can simply consult the Modelio metamodel documentation (which is available here: http://www.modeliosoft.com).

Page 27

Tutorial

Tutorial In the documentary diagram of the ModelTree metaclass, we can see that a composition relationship

In the documentary diagram of the ModelTree metaclass, we can see that a composition relationship named "Context" exists between ModelTrees.

The role on the component side of the composition is called "OwnedElement". This therefore indicates that there exists in the API a method on ObModelTree that retrieves sub-elements of ModelTree type. This method is called "getOwnedElement()". This rule for the construction of the accessor name is universal in the Modelio metamodel API.

To retrieve the sub-elements of a ModelTree type model element, we therefore recursively browse the list of all the current element’s ModelTree type model element, we therefore recursively browse the list of all the current element’s sub-elements.

the list of all the current element’s sub -elements. // Loop on ModelTree sub-elements for (ObModelTree
the list of all the current element’s sub -elements. // Loop on ModelTree sub-elements for (ObModelTree
the list of all the current element’s sub -elements. // Loop on ModelTree sub-elements for (ObModelTree
the list of all the current element’s sub -elements. // Loop on ModelTree sub-elements for (ObModelTree

// Loop on ModelTree sub-elements for(ObModelTree subElement : owner.getOwnedElement()){ res.addAll(listTODO(subElement));

}

If the element is stereotyped « TODO », we add it to the list of elements returned by the method. To find out whether or not an element is stereotyped « TODO », we use the isStereotyped(StereotypeName) service on the element to be tested . isStereotyped(StereotypeName) service on the element to be tested .

// Check « TODO » stereotype, not the use of the UMLTODOStereotype // interface that provides the string constants naming the different // stereotypes of our UMLTODO module if(owner.isStereotyped(UMLTODOStereotypes.TODO)){ res.add(owner);

}

The listTODO method

private List<ObModelTree> listTODO(ObModelTree owner){

Page 28

Tutorial

List<ObModelTree> res = new ArrayList<ObModelTree>();

// If the element is stereotyped « TODO », add it to the TODO list if(owner.isStereotyped(UMLTODOStereotypes.TODO)){ res.add(owner);

}

// Loop on model elements for(ObModelTree subElement : owner.getOwnedElement()){ res.addAll(listTODO(subElement));

}

return res;

}

To display the list of TODOs, we use the ReportUtils class provided by the ReportUtils.jar jar . A TODO is made up of the ReportUtils class provided by the ReportUtils.jar jar. A TODO is made up of the name of the model element and its description stored in the "TODO_NOTETYPE" note.

We retrieve the name of the element.its description stored in the "TODO_NOTETYPE" note. String name = element.getName(); We retrieve the contents of

String name = element.getName();

We retrieve the contents of the "TODO_NOTETYPE" note using a service provided by the ObUtils class.the name of the element. String name = element.getName(); String value =

String value = ObUtils.getNoteContent(element,UMLTODONoteTypes.TODO_NOTETYPE);

Complete implementation of the List command package
Complete implementation of the List command package
Complete implementation of the List command package
Complete implementation of the List command package

Complete implementation of the List command

package com.modeliosoft.modelio.umltodo.command;

import java.util.ArrayList; import java.util.List;

import com.modeliosoft.modelio.api.mda.gui.commands.DefaultMdacContextualCommand; import com.modeliosoft.modelio.api.mda.model.ObUtils; import com.modeliosoft.modelio.api.mdac.IJavaMdac; import com.modeliosoft.modelio.api.model.ObElement; import com.modeliosoft.modelio.api.model.ObModelTree; import com.modeliosoft.modelio.api.model.utils.ObList; import com.modeliosoft.modelio.report.ReportUtils; import com.modeliosoft.modelio.umltodo.api.UMLTODONoteTypes; import com.modeliosoft.modelio.umltodo.api.UMLTODOStereotypes;

public class Lister extends DefaultMdacContextualCommand {

@Override public void actionPerformed(ObList<ObElement> selectedElements, IJavaMdac module) { ReportUtils report = new ReportUtils(); ObModelTree root = (ObModelTree)selectedElements.get(0);

// Retrieval of ModelTrees stereotyped "TODO" for(ObModelTree element : listTODO(root)){ String name = element.getName(); String value = ObUtils.getNoteContent(element,UMLTODONoteTypes.TODO_NOTETYPE);

// Addition of TODOs to the report report.addElement(name, value);

}

// Creation of the report report.createReport();

Page 29

Tutorial

}

private List<ObModelTree> listTODO(ObModelTree owner){ List<ObModelTree> res = new ArrayList<ObModelTree>();

// If the element is stereotyped "TODO", it is added to the list of TODOs if(owner.isStereotyped(UMLTODOStereotypes.TODO)){ res.add(owner);

}

// The list of model sub-elements is browsed for(ObModelTree subElement : owner.getOwnedElement()){ res.addAll(listTODO(subElement));

}

return res;

}

/**

* This methods authorizes a command to be displayed in a defined context.

* The commands are displayed, by default, depending on the kind of metaclass on which the command has been launched. */ @Override public boolean accept(ObList<ObElement> selectedElements, IJavaMdac module) { // TODO Define the dynamic filtering conditions to display the command, in order to refine the command activation depending on specific markers that can be defined on the

selection (tagged value, specific properties return true;

).

}

/**

* This method specifies whether or not a command must be deactivated.

* If the command has to be displayed (which means that the accept method has returned a

positive value, it is sometimes needed to desactivate the command depending on specific

constraints that are specific to the module. */ @Override public boolean isActiveFor(ObList<ObElement> selectedElements, IJavaMdac module) { return true;

}

}

selectedElements, IJavaMdac module) { return true; } } 3.6 Creating a property page 3.6.1 Creating a
selectedElements, IJavaMdac module) { return true; } } 3.6 Creating a property page 3.6.1 Creating a
selectedElements, IJavaMdac module) { return true; } } 3.6 Creating a property page 3.6.1 Creating a
selectedElements, IJavaMdac module) { return true; } } 3.6 Creating a property page 3.6.1 Creating a

3.6 Creating a property page

3.6.1 Creating a property page

A property page is a contextual view whose contents change in real time according to the element selected in the modeler. This view displays contextual commands and editors for the selected element.

Page 30

Tutorial

Tutorial 1. In the MDA explorer, right-click on the "Properties" directory and run the property page

1. In the MDA explorer, right-click on the "Properties" directory and run the property page creation command.

directory and run the property page creation command. 2. Enter a name for the property page
directory and run the property page creation command. 2. Enter a name for the property page
directory and run the property page creation command. 2. Enter a name for the property page
directory and run the property page creation command. 2. Enter a name for the property page

2. Enter a name for the property page

o Name: "TODO"

Enter a name for the property page o Name: " TODO " 3. Click on the

3. Click on the "Create property page" button.

3.6.2 Implementing property editors

The property page is implemented in Java using the dedicated editor. To open this editor, use the "Open editor" command available in the contextual menu on the "TODO" property page.

The implementation of property editors is carried out through two methods:

The "Update" method The "Update" method is called when an element is selected. It is used to create and initialize property editors.

public void update(ObList<ObElement> selectedElements, IMdacPropertyTable table)

Page 31

Tutorial

For our example, if the selected element is stereotyped « TODO », we have to create a property editor. This editor is initialized with the value contained in the "TODO_NOTETYPE" note.

// If the element is stereotyped « TODO

ObModelElement element = (ObModelElement)selectedElements.get(0); if(element.isStereotyped("TODO")){ // Create a property editor (a row in the property table) // and set its contents to the contents of the TODO_NoteType note String contents = ObUtils.getNoteContent(element,UMLTODONoteTypes.TODO_NOTETYPE); table.addProperty("TODO", contents);

}

The "changeProperty" method

The "changeProperty" method is called when the value of a property editor is modified by the used in the property table. It is used to update the model according to this new value.

public void changeProperty(ObList<ObElement> selectedElements, int row, String value)

In our case, if the selected element is stereotyped « TODO », we have to update the contents of the "TODO_NOTETYPE" note according to the "value" parameter.

Warning : This operation represents a modification to the UML model. A transaction must therefore be opened.

to the UML model. A transaction must therefore be opened. ObModelElement element =
to the UML model. A transaction must therefore be opened. ObModelElement element =
to the UML model. A transaction must therefore be opened. ObModelElement element =
to the UML model. A transaction must therefore be opened. ObModelElement element =

ObModelElement element = (ObModelElement)selectedElements.get(0); if(element.isStereotyped("TODO")){ // Change the TODO note contents ObUtils.putNoteContent(Modelio.getInstance().getModelingSession(), element, UMLTODONoteTypes.TODO_NOTETYPE, value); // ‘value’ is provided to the // changeProperty method by Modelio

}

Complete implementation of the TODO class

package com.modeliosoft.modelio.umltodo.properties;

import com.modeliosoft.modelio.api.Modelio; import com.modeliosoft.modelio.api.mda.gui.propertiesPage.AbstractMdacPropertyPage; import com.modeliosoft.modelio.api.mda.gui.propertiesPage.IMdacPropertyTable; import com.modeliosoft.modelio.api.mda.model.ObUtils; import com.modeliosoft.modelio.api.mdac.IJavaMdac; import com.modeliosoft.modelio.api.model.ObElement; import com.modeliosoft.modelio.api.model.ObModelElement; import com.modeliosoft.modelio.api.model.utils.ObList; import com.modeliosoft.modelio.core.jni.ITransaction; import com.modeliosoft.modelio.umltodo.api.UMLTODONoteTypes;

public class TODO extends AbstractMdacPropertyPage {

public TODO(IJavaMdac module, String name, String label, String bitmap) { super(module, name, label, bitmap);

}

/**

Page 32

Tutorial

Tutorial * This method is called when a value has been edited in the property box
Tutorial * This method is called when a value has been edited in the property box
Tutorial * This method is called when a value has been edited in the property box
Tutorial * This method is called when a value has been edited in the property box

* This method is called when a value has been edited in the property box in the 'row'

row.

* The 'selectedElements' parameter contains the list of the currently selected elements.

* The 'row' parameter is the row number of the modified value.

* The 'value' parameter is the new value the user has set to the given row.

*/ @Override public void changeProperty(ObList<ObElement> selectedElements, int row, String value) { boolean commit = false;

// Open the transaction ITransaction tr = Modelio.getInstance().getModelingSession().createTransaction("Transaction"); try { if(selectedElements.size() > 0 && selectedElements.get(0) instanceof ObModelElement){

ObModelElement element = (ObModelElement)selectedElements.get(0); if(element.isStereotyped("TODO")){ // Save the value entered in the TODO_NoteType note

ObUtils.putNoteContent(Modelio.getInstance().getModelingSession(), element, UMLTODONoteTypes.TODO_NOTETYPE, value);

}

}

// Commit the transaction commit = true; Modelio.getInstance().getModelingSession().commit(tr); } catch (Exception e) { e.printStackTrace(); if (!commit) Modelio.getInstance().getModelingSession().rollback(tr);

}

}

/**

* This method is called when the current selection changes and the property box content

requires an update.

* The 'selectedElements' parameter contains the list of the newly selected elements.

* The 'table' parameter is the table that must be filled with the updated contents of the property box before returning. */

@Override public void update(ObList<ObElement> selectedElements, IMdacPropertyTable table) { if(selectedElements.size() > 0 && selectedElements.get(0)instanceof ObModelElement){

// If the element is stereotyped TODO ObModelElement element = (ObModelElement)selectedElements.get(0); if(element.isStereotyped("TODO")){ // Creation of a TODO property editor initialized with the contents of

the TODO_NOTETYPE note

table.addProperty("TODO",

ObUtils.getNoteContent(element,UMLTODONoteTypes.TODO_NOTETYPE));

}

}

}

}

Page 33

Tutorial

4 Compiling, Packaging and Testing

4.1 Compiling and packaging the module

The act of packaging the module enables us to create a UMLTODO.jmdac file from the UMLTODO module creation project. During the packaging process, the module’s Java source files will be compiled.

process, the module’s Java source files will be compiled. 1. Right-click on the module and run
process, the module’s Java source files will be compiled. 1. Right-click on the module and run
process, the module’s Java source files will be compiled. 1. Right-click on the module and run
process, the module’s Java source files will be compiled. 1. Right-click on the module and run

1. Right-click on the module and run the "Packaging" command.

Menu command: MDA Designer Light > Packaging

command. Menu command: MDA Designer Light > Packaging 2. Indicate the module’s version number, jmdac file

2. Indicate the module’s version number, jmdac file production path and packaging options :

a. Module version number: "1 0 00"

b. Archive path: "Desktop\UMLTODO_1.0.00.jmdac"

3. Check the "Deploy module in local base" tickbox. The packaged module then automatically be deployed in the current base, which will allow you to immediately test it.

Page 34

Tutorial

Tutorial If the following window appears, this means that the JDK has not been correctly configured.

If the following window appears, this means that the JDK has not been correctly configured. Modify the JDK configuration in the MDA Designer Light module parameters and then restart the packaging operation again:Tutorial Menu command: Configuration > Settings > MDA Designer Light > JAVA > JDK If the

Menu command: Configuration > Settings > MDA Designer Light > JAVA > JDK

> Settings > MDA Designer Light > JAVA > JDK If the following information window appears,
> Settings > MDA Designer Light > JAVA > JDK If the following information window appears,
> Settings > MDA Designer Light > JAVA > JDK If the following information window appears,
> Settings > MDA Designer Light > JAVA > JDK If the following information window appears,
> Settings > MDA Designer Light > JAVA > JDK If the following information window appears,

If the following information window appears, this means that there is an error in your Java code and therefore compilation of the sources has failed. To display a compilation error report, click on the "Yes" button. Once you have corrected the error, restart the packaging operation.> Settings > MDA Designer Light > JAVA > JDK If the packaging operation has been

have corrected the error, restart the packaging operation. If the packaging operation has been successful, the

If the packaging operation has been successful, the following window will appear. The UMLTODO_1.0.00.jmdac file has been created. UMLTODO_1.0.00.jmdac file has been created.

Page 35

Tutorial

Tutorial 4.2 Deploying and testing the module 4.2.1 Deploying the module If you have checked the

4.2 Deploying and testing the module

4.2.1 Deploying the module

If you have checked the "Deploy module in local base" option during the packaging process, the module is then automatically deployed in the current base and you can test it immediately.

It is also possible to deploy the new UMLTODO_1.0.00.jmdac module in any Modelio project, simply by carrying out the following steps :

1. Install the MDA Designer Light module using the dedicated command Menu command: MDA -> Install a module

: 1. Install the MDA Designer Light module using the dedicated command Menu command: MDA ->
: 1. Install the MDA Designer Light module using the dedicated command Menu command: MDA ->
: 1. Install the MDA Designer Light module using the dedicated command Menu command: MDA ->
: 1. Install the MDA Designer Light module using the dedicated command Menu command: MDA ->
: 1. Install the MDA Designer Light module using the dedicated command Menu command: MDA ->

Page 36

Tutorial

2. Select the "UMLTODO_1.0.00.jmdac" file.

3. Open the MDA explorer using the dedicated command Menu command: Views > Show MDA explorer

To check that the UMLTODO_1.0.00.jmdac has been correctly deployed, open the "Manage module activation" window. The UMLTODO module should appear there.

window. The UMLTODO module should appear there. Menu command: MDA > Activate/Deactivate modules 4.2.2
window. The UMLTODO module should appear there. Menu command: MDA > Activate/Deactivate modules 4.2.2
window. The UMLTODO module should appear there. Menu command: MDA > Activate/Deactivate modules 4.2.2
window. The UMLTODO module should appear there. Menu command: MDA > Activate/Deactivate modules 4.2.2

Menu command: MDA > Activate/Deactivate moduleswindow. The UMLTODO module should appear there. 4.2.2 Testing the module Test 1: You should now

there. Menu command: MDA > Activate/Deactivate modules 4.2.2 Testing the module Test 1: You should now

4.2.2 Testing the module

Test 1:

You should now see the following elements:

A new context menu dedicated to the UMLTODO module and containing the two commands

A

new context menu dedicated to the UMLTODO module and containing the two commands

we created, "AddTODO" and "List".

A property page named " TODO ".

A

property page named "TODO".

Page 37

Tutorial

Tutorial Test 2: The "AddTODO" command is used to create a new TODO. It is available
Tutorial Test 2: The "AddTODO" command is used to create a new TODO. It is available
Tutorial Test 2: The "AddTODO" command is used to create a new TODO. It is available
Tutorial Test 2: The "AddTODO" command is used to create a new TODO. It is available
Tutorial Test 2: The "AddTODO" command is used to create a new TODO. It is available

Test 2:

The "AddTODO" command is used to create a new TODO. It is available on elements of ModelTree type (packages, classes, …)

Similarly, the selection of an element on which a TODO has been added causes the "TODO" property page to appear with the description of the.

which a TODO has been added causes the "TODO" property page to appear with the description

Test 3:

Page 38

Tutorial

The "List" command displays the list of existing TODOs. Note that the "look" of the dialog box provided by ReportUtils.jar could be betterHowever, any developments we might want to make can be carried out outside our module. This is one of the advantages of our choice of having placed the "business" or pure application code outside our module project.

or pure application code outside our module project. 4.2.3 And what about MDA Designer Enterprise Edition?
or pure application code outside our module project. 4.2.3 And what about MDA Designer Enterprise Edition?
or pure application code outside our module project. 4.2.3 And what about MDA Designer Enterprise Edition?
or pure application code outside our module project. 4.2.3 And what about MDA Designer Enterprise Edition?
or pure application code outside our module project. 4.2.3 And what about MDA Designer Enterprise Edition?

4.2.3 And what about MDA Designer Enterprise Edition?

With MDA Designer Enterprise Edition, a complete model of the module is generated and maintained. This model is then transformed into Java code using the Modelio Java generator. In this way, we can model and develop all a module’s code, including the purely applicative or "business" parts, in model-driven mode (with or without roundtrip) with all the necessary tools integrated into a single, unique tool, Modelio.

The Enterprise Edition of MDA Designer also enables teamwork (SVN), which rapidly becomes indispensable when several people are working together on more ambitious, large-scale module projects .

Finally, it should be noted that all modules, whether developed with MDA Designer Light or with MDA Designer Enterprise Edition, are perfectly compatible and usable in any Modelio project (on condition that their version is compatible).

Page 39