Skip to content

2015_sirius

raimy29 edited this page May 21, 2015 · 13 revisions

Sirius

The logo of Sirius

homesite: http://eclipse.org/sirius/

Install Sirius

Install from eclipse market place: search for Sirius -> Click Install -> etc.

Eclipse Marketplace... inside Help menu

Output of the laboratory

  • Modified metamodel can be downloaded from here
  • Created design project can be downloaded from here

Setup the laboratory

  1. Import the original metamodel projects from here.
  2. (Generate *.edit and *.editor from the appropriate *.genmodel file in the model folder.)
  3. Run as Eclipse Application.
  4. Import the project from here to the runtime Eclipse and check the instance model.
  5. We will work in Runtime Eclipse

Viewpoint specificiation

In the Runtime Eclipse

  1. Create a new Viewpoint Specification Project and name it as _hu.bme.mit.mdsd.erdiagram.design while the Viewpoint specification model would be called erdiagram.odesign. Note: this is a Sirius related project type to describe a Sirius editor

  2. Switch to Modeling perspective Note: Window -> Open perspective -> Other... -> Modeling

  3. In odesign editor, add a new view point: right click on the viewpoint (in the editor) -> New -> Viewpoint. Set its Model File Extension property to "erdiagram". Viewpoint added

  4. Under the viewpoint, create a diagram representation (right click on the viewpoint -> New Representation -> New Diagram Representation) and set its domain class to our root metamodel class: EntityRelationDiagram. Diagram added

  5. Create a default layer under the diagram representation (right click on the representation -> New Diagram Element -> Default Layer). Layer added

Visualizing objects

Under the default layer:

  1. Create a Node typed diagram element (right click on the layer -> New Diagram Element -> Node) and set its domain class to Entity and its semantic candidates expression to feature:entities. Note: the Semantic Candidate Expression describes the navigation path from the parent domain class to the selected ones. In this the parent is EntityRelationDiagram and we select all the object on its entities reference. Note: the feature: selects a structural feature (attribute or reference) from a domain class

  2. Define a style for the Node (right click on the Node -> New Style -> Square). You can change its properties if you want. Entity + Style added

  3. Create a Node typed diagram element and set its domain class to Attribute and set its semantic candidate expression to [self.entities.attributes->addAll(self.temporary->filter(Attribute))/] Note: inside the squre brackets you can acceleo expressions - acceleo

  4. Create styles and conditional styles for attributes based on the isKey properties. The condition will be the following: [self.isKey/] Note: A default style is alway required. Note: Create Conditional Style - right click on the Node -> New Conditional Style -> Conditional Style and then you can create a new style under the conditional style element. Note: Do not forget to fill the predicate expression in the conditional style. Note: If the predicate expression is true the conditional style will be applied.

    Style + Conditional Style added

Visualizing edges

Under the default layer:

  1. Display connections between an entity and its attributes

    1. Create a Relation Based Edge typed diagram element (right click on the layer -> New Diagram Element -> Relation Based Edge).
    2. Set its source mapping to Entity (defined previous)
    3. Set its target mapping to Attribute (defined also previous)
    4. Set its target finder expression to "feature:attributes" Note: the target finder expression is related to the source mapped objects
    5. By default, a simple edge style is create which is good for us now, but you can check its properties.

    Relation Based Edge added

  2. Display connections between entities based on the relation objects

    1. Create an Element Based Edge typed diagram element (right click on the layer -> New Diagram Element -> Element Based Edge).
    2. Set its domain class to Relation
    3. Set its source mapping to Entity (defined previous)
    4. Set its source finder expression to "[self.leftEnding.target/]"
    5. Set its target mapping to Entity (defined also previous)
    6. Set its source finder expression to "[self.rightEnding.target/]"
    7. We left the semantic candidates expression empty, but we should fill it with "feature:relations" Note: for the proper functioning, this is not required but recommended
    8. By default, a simple style is provided for the edge, but define additional conditional styles based on the multiplicity of a relation:
      • [self.leftEnding.multiplicity.toString() = 'One' and self.leftEnding.multiplicity.toString() = 'One'/]
      • [self.leftEnding.multiplicity.toString() = 'Many' and self.leftEnding.multiplicity.toString() = 'One'/]
      • [self.leftEnding.multiplicity.toString() = 'One' and self.leftEnding.multiplicity.toString() = 'Many'/]
      • [self.leftEnding.multiplicity.toString() = 'Many' and self.leftEnding.multiplicity.toString() = 'Many'/]
    9. Change the ending of the edges alse based the multiplicity (inside properties of an edge style, check the decorators tab)

    Element Based Edge added

Creating Objects

Under the Section (create one, if you don't have: right click on the layer -> New Tool -> Section)

  1. Create Entities

    1. Add a Node Creation (right click on Section -> New Element Creation -> Node Creation)
    2. Under the green arrow with the begin label, we can define an operation sequence to be executed.
      1. Create a new instance operation (right click on Begin -> New Operation -> Create Instance)
      2. Set its reference name to "entities" Note: without any prefix, only the reference name _Note: field is related to the domain class of the diagram (or the container node) where we add the new instance
      3. Set its type name to Entity, as we want to create a new Entity
      4. Set its variable name to "instance" _Note: we won't use this feature, but with its name, you can refer to this object later (var:)
    3. Under the new instance operation, create a Set operation (right click on Create Instance Entity -> New Operation -> Set)
      1. Set its feature name to "name"
      2. Set its value to "undefined" Note: this will set the name attribute of the new object to "undefined" by default

    Create Entity

  2. Create Attributes

    1. Add a Node Creation (right click on Section -> New Element Creation -> Node Creation)
    2. Under the green arrow with the begin label, define the operation sequence.
      1. Create a new instance operation (right click on Begin -> New Operation -> Create Instance)

      2. Despite the fact, that our EntityRelationDiagram class cannot contain Attribute typed objects in any of its features, we have to extend the metamodel.

        1. Stop the RuntimeEclipse.
        2. Open the erdiagram.ecore file.
        3. Add a new reference to EntityRelationDiagram
          • Name: temporary
          • Type: Attribute
          • Multiplicity: many (0..*)
        4. Save the metamodel
        5. Reload it in the genmodel.
        6. Regenerate the model, edit and editor code from the genmodel
        7. Start the Runtime Eclipse again.
          Modified metamodel
      3. Set its reference name to "temporary"

      4. Set its type name to Attribute

      5. Set its variable name to "instance"

    3. Under the new instance operation, create a Set operation (right click on Create Instance Entity -> New Operation -> Set)
      1. Set its feature name to "name"
      2. Set its value to "undefined"

    Create Attibute

Creating Edges

Under the Section (create one, if you don't have: right click on the layer -> New Tool -> Section)

  1. Create edge between Entity and Attribute

    1. Add a Edge Creation (right click on Section -> New Element Creation -> Edge Creation)
    2. Set its edge mapping to "entity_attribute" Note: this is the edge element that we defined previous (Visualizing edges/1st step)
    3. Set its connection start precondition to [self->selectByType(Attribute)/] _Note: this acceleo expression will select all attribute typed objects
    4. Set its connection end precondition to [self->selectByType(Entity)/] Note: these two precondition will restrict the editor to disable undesirable edges
    5. Add a Set operation under the Begin element
      1. Feature name: "attributes" Note: related to the source object
      2. Value expression: "target" Note: this is a variable created automatically and refers to the selected target object

    Create Edge between Attibute and Entity

  2. Create edge between Entities (using Java Code)

  3. Add a Edge Creation (right click on Section -> New Element Creation -> Edge Creation)

  4. Set its edge mapping to "Relation" Note: this is the edge element that we defined previous (Visualizing edges/2nd step)

  5. Set its connection start precondition to [self->selectByType(Entity)/]

  6. Set its connection end precondition to [self->selectByType(Entity)/]

  7. Add an External Java Action operation under the Begin element (right click on the Begin element -> New Extension -> External Java Action)

    1. Set its Java Action Id to "CreateRelation"
    2. Add parameters: source, target, container (right click on the External Java Action -> New -> External Java Action Parameter)
      • Set their properties:
        • name: source, value var:source
        • name: target, value var:target
        • name: container, value var:container

    Create Relation between Entities

    1. Open the plugin.xml of the project

    2. Switch to the extensions tab

    3. Add a new extension: org.eclipse.sirius.externalJavaAction

    4. Add a new java action under the extension

    5. Set its id to "CreateRelation" (same as Java Action Id!)

    6. Create an action class: CreateRelationOperation

      '''java public class CreateRelationOperation implements IExternalJavaAction {

      @Override public void execute(Collection<? extends EObject> selections, Map<String, Object> parameters) {

         Entity source = (Entity) parameters.get("source");
         Entity target = (Entity) parameters.get("target");
         EntityRelationDiagram diagram = (EntityRelationDiagram) parameters.get("container");
         
         Relation relation = ERDiagramFactory.eINSTANCE.createRelation();
         
         RelationEnding leftRelationEnding = ERDiagramFactory.eINSTANCE.createRelationEnding();
         RelationEnding rightRelationEnding = ERDiagramFactory.eINSTANCE.createRelationEnding();
         
         relation.setLeftEnding(leftRelationEnding);
         relation.setRightEnding(rightRelationEnding);
         
         leftRelationEnding.setTarget(source);
         rightRelationEnding.setTarget(target);
         
         leftRelationEnding.setName("undefined");
         rightRelationEnding.setName("undefined");
         
         diagram.getRelations().add(relation);
      

      }

      @Override public boolean canExecute(Collection<? extends EObject> selections) { for (EObject eObject : selections) { if(!(eObject instanceof Entity)) { return false; } } return true; }

    } ''' Note: the added parameters can be reached in the "parameters" map

    Extension points

Validation

  1. Create new validation for our diagram (right click on diagram element -> New Validation -> Validation)

  2. Create a new Semantic validation (right click on validation element -> New -> Semantic Validation)

    1. Set its level to "Information"

    2. Target class: "Attribute"

    3. Message: "Hi! I'm an Address." Note: this describes what will happen when our model has a problem

    4. Create an Audit under the semantic validation (right click semantic validation -> new -> audit)

      • Set its audit expression to "[self.name <> 'address'/]" Note: this describes whether our model is correct or not. If the expression returns false, the element is incorrect.
    5. Create an Quick Fix under the semantic validation (right click semantic validation -> new -> quick fix)

      • Create a Set operation under the Begin element _Note: this is also an operation sequence to be executed when someone click on the quick fix
        • feature: "name", value: "addresss"

    Extension points

Lab material

MDSD 2021

MDSD 2020

MDSD 2019

(Gradually replaced with updated content)

MDSD 2018

MDSD 2017

MDSD 2016

MDSD 2015

MDSD 2014

System Integration 2014

Clone this wiki locally