Sirius/Tutorials/StarterTutorial
Contents
Overview
This tutorial explains how to create your first modeling workbench with Sirius.
These instructions are based on a simple Domain Model which describes basic concepts about families.
The modeling workbench created with this tutorial will allow users to visualize the members of a family and their parental relationships on a graphical diagram. It will also provide tools to edit the model from the diagram.
Note: The screenshots have been updated with Obeo Designer 8.1 (based on Sirius 3.1)
Install the sample Domain Model
A modeling workbench allows users to create or visualize models of a given Domain Model defined with EMF (Ecore model).
This tutorial relies on a Domain Model (DSL) defining the basic concepts of families:
- A family is composed of several persons.
- Persons are men or women.
- A person has:
- a name,
- children,
- two parents
- a father and a mother.
Import the projects containing the sample Domain Model
The domain model is implemented with several EMF projects that you need to import into your workspace.
These projects can be easily installed from the provided examples (menu File > New > Example... : select Basic Family Metamodel Definition).
If you don't find these projects from this wizard, please install the Sirius Samples feature from Sirius updatesite (see the list of Sirius udpate sites for the latest release).
And then go back to the Examples wizard.
A third solution to get these projects consists in importing them from this archive: http://eclipse.org/sirius/doc/resources/getstarted/basicfamily.zip (menu File > Import > Existing Projects into Workspace to install these projects).
Launch a new runtime from your Eclipse
To launch a new eclipse application click on Run / Run Configurations and double click on Eclipse Application to get a New_configuration. In order to comfortably run Sirius in your new runtime, you should add this option in your VM arguments :
-XX:MaxPermSize=256m
Select the Sirius perspective
In the new Eclipse runtime, select the Sirius perspective.
This perspective provides specific Sirius menus and a new kind of project (Modeling Project). A Modeling Project contains models and the corresponding graphical representations created with Sirius.
Import a sample model
A sample model is available from the provided examples (menu File > New > Example... : select Basic Family Sample Model).
The wizard then installs a Modeling Project containing a file named example.basicfamily.
Double-clicking on this sample model opens a tree editor generated by EMF.
This editor allows you to see the properties and relationships of the model elements.
If you don't find these projects from this wizard:
Please install the Sirius Samples (see Import the projects containing the sample Domain Model)
A third solution to get this sample model consists in creating a new Modeling Project from the Model Explorer:
Give a name to this sample project.
Then download the XMI file example.basicfamily: http://eclipse.org/sirius/doc/resources/getstarted/example.basicfamily
And import this sample file into the new Modeling Project (menu File > Import > File System).
Start creating a diagram editor with Sirius
Let’s start creating your first modeling workbench with Sirius.
In this tutorial, we will create a diagram editor that allows users to visualize and edit a family with its members and their relationships (father and mother).
The sample model imported previously will be used to test this editor.
Create a Viewpoint Specification Project
A Viewpoint Specification Project will contain the definition of your modeling workbench. It can be created in a development workspace or in a runtime one.
In order to facilitate the test of the designer, we recommend to create this project in the same Eclipse runtime launched previously.
Give a name to this project.
The Viewpoint Specification Project creation wizard creates a new project containing a .odesign file that describes a modeling workbench which can be interpreted by the Sirius runtime.
Sirius automatically opens this file with a specific editor.
Define a Viewpoint
A .odesign file contains viewpoints. Each viewpoint defines a set of representations (diagrams, tables or trees).
That’s why you need to define at least one viewpoint in the .odesign file (menu New... / Viewpoint).
Do not forget to specify the Id of the added viewpoint.
The Model File Extension property defines the kind of models associated to the designer. We encourage you to set the extension associated to your domain model.
Properties of a Viewpoint
- Id: The identifier of this element. Must be unique. Changing this identifier will break existing user models which reference the old identifier.
- Label: The label used to display this to the end-user.
- Model File Extension: This field allows to associate this viewpoint to one or more semantic resource file extension(s), for several file extensions, they must be space separeted. For example to associate this viewpoint to uml and ecore metamodels, put «uml ecore».
Define a Diagram
Add a first Diagram to your Viewpoint (menu New Representation... / Diagram Description).
A diagram must be associated to a Domain Class: the diagram will graphically represent instances of this Domain Class.
At this step, create Persons Diagram which will display the persons of a family.
Properties of a Diagram
- Id: The identifier of this element. Must be unique. Changing this identifier will break existing user models which reference the old identifier.
- Label: The label used to display this to the end-user.
- Domain Class: The type of the root diagram element. For instance you may want to create an UML2 Class diagram, then the root domain class will probably be ‹Package›. On the other side if you want a Class Diagram displaying the whole model, then the root domain class is ‹Model› in UML2.
- Initialisation: If set to true, the representation will be automatically created when creating a new session.
- Enable Popup Bars: If true, creation tools which are visible in the palette will also be available as pop-up toolbars in the diagram itself.
- Precondition Expression: The precondition is an expression preventing the creation of a diagram. If the precondition is set and the expression returns false on the root diagram element, then the diagram won’t be created.
- Show on Startup: If true, existing representations of this type will be automatically opened when a session is opened.
Add a Node to the Layer
A Diagram shows Nodes which are elements of the model. To create a new Node to the diagram, right-click on the Layer and select the menu New Diagram Element... / Node.
Note: Before Sirius 3.0, you have to manually create the layer.
All created nodes must have an Id and must be associated to a Domain class.
Properties of a Node
- Id: The identifier of this element. Must be unique. Changing this identifier will break existing user models which reference the old identifier.
- Label: The label used to display this to the end-user.
- Domain Class: The type of the root diagram element. For instance you may want to create an UML2 Class diagram, then the root domain class will probably be ‹Package›. On the other side if you want a Class Diagram displaying the whole model, then the root domain class is ‹Model› in UML2.
- Semantic Candidates Expression: Restrict the list of elements to consider before creating the graphical elements. If it is not set, then all semantic models in session will be browsed and any element of the given type validating the precondition expression will cause the creation of a graphical element. If you set this attribute then only the elements returned by the expression evaluation will be considered.
The Semantic Candidates Expression can be an AQL (Acceleo Query Language) expression prefixed by aql: . This expression is evaluated on the object associated to the diagram (here: an instance of Family).
Note: To improve the performance of your modeling tool, we encourage you to declare your metamodel in your project. Just open the MANIFEST.MF file and add the plug-in that defines your metamodel in the list of the Required Plug-ins (in the Dependencies tab). It is required if your AQL expressions refers types of the metamodel (ex: basicfamily::Man
).
Sirius expressions can also be written in Acceleo 3, contained between [ and /].
You can also use three interpreters dedicated to very simple expressions, by using specific tags ( feature: , service: and var:) followed by the name of the feature, service or variable.
Auto-completion is available on an empty Semantic Candidates Expression property by placing the cursor in the empty field and hitting Ctrl+Space.
The completion will correspond to the empty expression for the installed query language (e.g. [/] for Acceleo 3). It will also place the cursor at the expected place where it is ready to start typing the expression.
Now, the completion proposal will correspond to the variables which are available in the expression’s context, and all the features, services, etc. which are available on the current element.
Set a Style to the Node
To define the way the node is graphically represented on the diagram, it must declare a Style (menu New Style).
Here, we have chosen a square to represent a Man.
The Style defines the graphical attributes of the Node (e.g. its color).
The Style also defines the label of the Node. By default the label is calculated with the expression feature :name.
By using AQL syntax you can enter your own expression. For example, you could display the name to upper case by specifying the Label Expression to aql:self.name.toUpper()
Properties of a Node Style
- Label Format: The font formatting style to use for the label
- Label Position: Pick either ‹node› position which mean ‹inside the node› or ‹border› to put the label around the node.
- Hide Label By Default: Define the default visibility status of this label (available only if label position is «border»). A change of this option does not affect already existing elements.
- Label Alignment: The alignment of the label.
- Label Expression:
- Expected return type: a string.
- Available variables:
- diagram: viewpoint.DDiagram | the current DSemanticDiagram.
- view: viewpoint.DDiagramElement | the current view for which the label is calculated.
Test the diagram
To test this first diagram, right-click in the Model Explorer view on the Modeling project and select the menu Viewpoint Selection.
You should see the new viewpoint persons. You must activate this viewpoint to be able to create the representations which are defined by this viewpoint.
Then right-click on the sample model and select the menu New Representation / new Persons diagram.
When the diagram opens it displays all the instances of Man contained in the sample model.
They are represented as blue squares with uppercase names as a label, as it is defined in the definition of the diagram.
Improve the Style of the Node
To improve the rendering of the diagram, it is possible to display nodes with images.
In our example, delete the Square style created previously and replace it by a Workspace Image.
Specify the Workspace Path to define the image (the image can be placed in a specific folder of your project).
Download this archive File:Png-files.zip and unzip its content (man32.png and woman32.png) into a new icons folder.
Properties of a Workspace Image:
- Workspace Path: Path for the image in the form of /myProjectID/path/to/image.png. If the image is not found in the workspace the tooling will look for it in the plugins.
- Tooltip Expression: An optional expression which should return the text of the element’s tool-tip.
In the Label tab, deselect the Show icon option to avoid displaying two images for each node.
Add a second Node
Proceed the same way to create nodes for instances of Woman. Choose a different image for this node.
Saving the .odesign file immediately updates the current diagram to reflect the changes.
Add a Relation Based Edge
To display relations between Nodes, create a Relation Based Edge.
Enter the Source and Target Mappings of the relation: Sirius will select each instance of the concerned nodes which are visible on the current diagram.
Then, Sirius will evaluate the Target Finder Expression on each Source Mapping to detect the corresponding Target Mapping.
Properties of a Relation Based Edge
- Id: The identifier of this element. Must be unique. Changing this identifier will break existing user models which reference the old identifier.
- Source Mapping: Mapping from which the edge should start.
- Target Mapping: Mapping from which the edge should end.
- Target Finder Expression: Expression which should return, starting from the target element (which may be the domain class if the edge is domain based, otherwise it’s the target of the source node) the target semantic element.
Edit the Style of the Relation
Edges are initialized with a default style which defines its graphical appearance (color, line style, etc.). You can edit this style to display father relations in blue.
Then create a second Edge to display mother relations in light purple.
Save the .odesign file, refresh the diagram and click on the Arrange All button to see the changes.
Add a Palette for edition tools
In the previous steps, we have created a modeling workbench which can display an existing model.
Let’s complete this designer with a palette containing tools to allow users to create new model elements.
Create a Section
Add a new Section to the Layer (menu New tool... / Section).
Add a Node Creation
The palette is composed of tools which will allow the user to create new objects.
To create new instances of Domain Classes, add a Node Creation element to the Section (menu New Element Creation... / Node Creation Description).
To define which kind of nodes will be created by the tool, the Node Creation Description element must be associated to an existing node (e.g. ManNode).
Properties of a Node Creation
- Id: The identifier of this element. Must be unique. Changing this identifier will break existing user models which reference the old identifier.
- Label: The label used to display this to the end-user.
- Node Mappings: Node mappings you may need to create once the tool has been executed.
- Precondition:
- Expected return type: a boolean.
- Available variables:
- container: ecore.EObject | the container.
Define the actions performed by the Create Node tool
When the user will use the tool, actions will be executed. You have to define them.
The first step consists in adding a Change Context element to define the context of the actions.
The Change Context element contains an expression which allows Sirius to find the model element which will be the context.
To write the expression, you can use the variable container which references the object holding the current diagram (e.g. a Family instance).
Properties of a Change Context
- Browse Expression : Expression to navigate in the model to a new element.
Then, add a Create Instance which will create a new instance of Man.
Specify the type of the new instance and how it will be attached to the context.
Properties of a Create Instance
- Reference Name : Reference name in which the new instance will be stored. This reference should be part of the container element.
- Type Name: Type name of the instance to create.
- Variable Name : Once the instance is created, a new variable with the given name will exist binding to the newly created object.
To specify the name of the created element, you can also add a Set Value operation.
For example, the following AQL expression will compute a default name depending on the number of men already created.
aql:'man'+container.members->filter(basicfamily::Man)->size()
Properties of a Set Value
- Feature Name: Name of the feature to set.
- Value Expression: Expression returning the value to set on the current element.
Test the Create Node tool
When you go back to the diagram which displays your sample model, you can notice that the palette contains a section and a createMan tool
You can click on this tool and move the cursor to the diagram.
The cursor will automatically change to indicate that you can click on the diagram to create a new object.
Once you have clicked on the diagram, a new Man is created and displayed on the diagram.
Its properties can be edited using the Properties view.
Going Further
This starter tutorial is now finished, congratulations! If you wish to go further and explore advanced Sirius features, you can continue with the advanced tutorial which builds on this example.