Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Tutorial
1 1.1 1.2 2 2.1 2.2 3 3.1 3.2 3.3 3.4 3.4.1 3.4.2 3.5 3.5.1 3.5.2 3.6 3.6.1 3.6.2 4 4.1 4.2 4.2.1 4.2.2 4.2.3
Introduction ................................................................................................................ 3 Aim of this tutorial ........................................................................................................... 3 Prerequisites .................................................................................................................... 4 Creating a module development project ....................................................................... 5 In Modelio Free Edition and Modelio Java Express Edition ............................................. 5 In Modelio Enterprise Edition .......................................................................................... 7 Creating the TODO module .......................................................................................... 9 Creating the module......................................................................................................... 9 Creating stereotypes and note types ............................................................................. 13 Adding an external jar to the module ............................................................................ 17 Creating the "AddTODO" command .............................................................................. 19 Creating the "AddTODO" command ............................................................................ 19 Implementing the "AddTODO" command ................................................................... 24 Creating the "List" command ......................................................................................... 26 Creating the "List" command....................................................................................... 26 Implementing the "List" command ............................................................................. 27 Creating a property page ............................................................................................... 30 Creating a property page ............................................................................................. 30 Implementing property editors ................................................................................... 31 Compiling, Packaging and Testing ............................................................................... 34 Compiling and packaging the module ............................................................................ 34 Deploying and testing the module ................................................................................. 36 Deploying the module ................................................................................................. 36 Testing the module ...................................................................................................... 37 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" text. 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 customized properties page enabling the user to display and modify the description of a "TODO".
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) Download here: http://www.modeliosoft.com/ A JDK 1.6 Download here: http://java.sun.com/javase/downloads/index.jsp The UMLTODORessources.zip archive containing the resources necessary to the implementation of this tutorial. 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.
Page 4
Tutorial
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
4. Click on the "Create" button. The "UMLTODO" project is then created and the MDA explorer opened.
Page 6
Tutorial
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
4. Install the MDA Designer Light module using the dedicated command. Menu command: MDA > Install a module
Page 8
Tutorial
5. Select the "MdaDesignerLight.jmdac" file. 6. Use the "Views" menu to open the MDA explorer (Menu command: Views > Show MDA explorer).
Page 9
Tutorial
2. Enter a name and a description for the module, and choose an icon that will graphically represent it: a. Module name: "UMLTODO" b. Description: "Module to manage TODOs on UML model elements" c. Icon: UMLTODOResources\eye1.bmp
Page 10
Tutorial
3. Click on "Next". 4. Check the modules namespace and the path of the JDK. If no JDK is indicated, select the directory where your JDK1.6 is installed.
Page 11
Tutorial
5. Click on "Create module" to launch the module creation operation. The UMLTODO module is created in the MDA explorer view.
Page 12
Tutorial
Page 13
Tutorial
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
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
Page 15
Tutorial
2. A new note type is then created. Change its name (F2 or double-click on the objects text) to "TODO_NoteType".
Page 16
Tutorial
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.
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
2. Select the ReportUtils.jar jar. This jar is then added to the project.
Page 18
Tutorial
In our example, the ReportUtils.jar jar mainly contains display services (GUI) for a TODO list.
Page 19
Tutorial
2. Enter a name and a description for the command, and choose an icon to represent it: a. Name: AddTODO b. Description: Add a TODO to a metamodel element c. Icon: UMLTODOResources\report_plus.png
Page 20
Tutorial
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
5. Select ObModelTree from the list of metaclasses and click on the green arrow. 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
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 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
Page 24
Tutorial
// Commit transaction commit = true; session.commit(tr); } catch (Exception e) { e.printStackTrace(); if (!commit) session.rollback(tr); }
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)
For the addition of the TODO_NOTETYPE note type to the selected element, the ObUtils service class again facilitates the writing of the code.
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; } }
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 cant modify the model".
Page 27
Tutorial
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 elements sub-elements.
// 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.
// 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); }
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 name of the model element and its description stored in the "TODO_NOTETYPE" note. We retrieve the name of the element.
String name = element.getName();
We retrieve the contents of the "TODO_NOTETYPE" note using a service provided by the ObUtils class.
String value = ObUtils.getNoteContent(element,UMLTODONoteTypes.TODO_NOTETYPE);
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; } }
Page 30
Tutorial
1. In the MDA explorer, right-click on the "Properties" directory and run the property page creation command. 2. Enter a name for the property page o Name: "TODO"
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.
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 }
public class TODO extends AbstractMdacPropertyPage { public TODO(IJavaMdac module, String name, String label, String bitmap) { super(module, name, label, bitmap); } /**
Page 32
Tutorial
* 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
2. Indicate the modules 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
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: Menu command: Configuration > Settings > MDA Designer Light > JAVA > JDK
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.
If the packaging operation has been successful, the following window will appear. The UMLTODO_1.0.00.jmdac file has been created.
Page 35
Tutorial
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. Menu command: MDA > Activate/Deactivate modules
Page 37
Tutorial
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.
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 better However, 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.
Page 39