Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

How to get a EMF Ecore model into a Papyrus class diagram

Revision as of 20:24, 13 April 2015 by Paul.roubekas.org (Talk | contribs) (Delete the class)

Th.jpg

Create an Ecore model

Create an empty Ecore project

The There is no EMF Perspective. Therefore an EMF Ecore mode project can be created from any Eclipse perspective that allows creation of a project. These steps create an EMF project from within the Java Eclipse perspective. From the Package Explorer bring up the context menu with a right mouse click. Pick "New" then from the sub-popup "Project...". New EMF model context & popout.jpg

From the "Eclipse Modeling Framework" group of Wizards pick the "Empty EMF Project" wizard. New empty EMF Project.jpg

The "EMF Project" wizard is not used because that wizard assumes that an existing model (Rose, Ecore, UML or XML schema) will be the base for the new EMF model. This example starts from scratch therefore the "Empty EMF Project" wizard is used. In the "New Empty EMF Project" dialog enter "software.foo.emf.core" at the "Project name:" prompt.

Give the EMF project a name.jpg

Leave the "Use default location" check box checked. To keep this example simple the EMF project will not be added to a "Working set". So leave the "Add project to working sets" check box unchecked. Press the "Finish" button. The project will have a warning that "No required execution environment has been set". Ignore the warning for this demo. The demo does not need a execution environment.

Create a package

Open the "Sample Ecore model editor" by double clicking the "foo.ecore" file in the Package Explorer. Don't get confused by the word "Sample" in the name of the editor. For some reason, that must have made sense at the time, the EMF team has put the lead word "Sample" in the name of the editor. The "Sample" editor is THE primary EMF Ecore model editor.

Nothing can be added to the "platform:/resource/software.foo.emf.core/model/foo.ecore" root node of the mode hierarchy. Expand the root node to expose a empty node one level below the root node. Give focus to the empty node.

Empty foo ecore.jpg

Go to the Eclipse "properties". Notice there are three properties. Name, Ns prefix and Ns URI. Populate each of the fields as follows.

  • Name = fooEMFMode
  • Ns prefix = foo
  • Ns URI = software.foo

Open the context menu for the fooEMFMode node just created. Select "New Child" then Epackage. Populate the three properties as follows.

  • Name = foo.emf.core
  • Ns prefix = fooc
  • Ns URI = software.foo.emf.core

Create a class

Open the context menu for the foo.emf.core node just created. Select "New Child" then EClass. Populate the six properties as follows.

  • Abstract = false
  • Default Value = null
  • ESuper Types = null
  • Instance Type Name = null
  • Interface = false
  • Name = Foo

Create an attribute in the class

Open the context menu for the Foo node just created. Select "New Child" then EAttribute. Populate the fourteen properties as follows.

  • Changeable = true
  • Default Value Literal = null
  • Derived = false
  • EAttribute Type = null
  • EType = null
  • ID = false
  • Lower Bound = 0
  • Name = fooThing
  • Ordered = true
  • Transient = false
  • Unique true = null
  • Unsettable = false
  • Upper Bound = 1
  • Volatile = false

Create a containment reference in the class

Open the context menu for the Foo node just created. Select "New Child" then EReference. Populate the fourteen properties as follows.

  • Changeable = true
  • Container = false
  • Containment = false
  • Default Value Literal = null
  • Derived = false
  • EKeys = null
  • EOpposite = null
  • EType = null
  • Lower Bound = 0
  • Name = fooPointsTo
  • Ordered = true
  • Resolve Proxies = true
  • Transient = false
  • Unique = true
  • Unsettable = false
  • Upper Bound = 1
  • Volatile = false

Create a non-containment reference in the class

Open the context menu for the Foo node just created. Select "New Child" then EReference. Populate the fourteen properties as follows.

  • Changeable = true
  • Container = true
  • Containment = false
  • Default Value Literal = null
  • Derived = false
  • EKeys = null
  • EOpposite = null
  • EType = null
  • Lower Bound = 0
  • Name = fooOwns
  • Ordered = true
  • Resolve Proxies = true
  • Transient = false
  • Unique = true
  • Unsettable = false
  • Upper Bound = 1
  • Volatile = false

Save the model

Give the "Sample Ecore model editor" focus and press CTL+s

Convert Ecore model to UML Model

ConvertToUMLModel.jpg

From the "Package Explorer" select the "foo.ecore" node. From the "Sample Ecore model editor" select the "fooEMFModel" node. Then from the Eclipse menu bar select the "Sample Ecore editor" option. From the drop down menu select the "Convert to UML Model" option. From the "Convert Package To UML model" dialog just leave the defaults and press the "Ok" button. This step will take a few seconds to complete. Once done a "Convet To UML Operation Was Successful" message will appear. Press the "Ok" button to close the message. OneNewFileFourNewNodes.jpg

There will now be four new top level nodes in the "foo.ecore" editor. The one new file in the "Project Explorer" in the "model" folder of the "software.foo.emf.core" project will have the name "fooEMFModel.uml". The four new nodes in the "Sample Ecore editor" will have the names

  • "pathmap://UML_PROFILES/Ecore.profile.uml"
  • "pathmap://UML_METALMODELS/UML.metamodel.uml"
  • "pathmap://UML_ PROFILES/Standard.profile"
  • "platform://resource/software.foo.emf.core/model/fooEMFModel.uml"

Create a Papyrus Project and Class Diagram

Create a Papyrus project

From the top right hand part the Eclipse Workspace click the "Open Perspective" icon. The hover help will display " Open Perspective" when the cursor is over the "Open Perspective" icon. Click the icon. From the list of perspectives pick the Papyrus perspective. The click will open the Papyrus perspective in Eclipse.

From the Project Explorer bring up the context menu with a right mouse click. Pick "New" then from the sub-popup "Project...". From the "Papyrus" group of Wizards pick the "Papyrus Project" wizard. New Papyrus Project.jpg

Press the "Next" button. Give the project the name "software.foo.papyrus.core" in the "New Papyrus Project" dialog. Press the "Next" button. UML Diagram Language.jpg

Pick "UML" radio button for the Diagram Language, not the "Project" or "SysML" options. Press the "Next" button. Enter "FooClassDiagram" as the "Diagram Name". Check the "UML Class Diagram" check box. Leave the "You can load a template" check box unchecked. Also leave the "Remember current selection" check box unchecked. Press the "Finish" button.

Expand the "software.usque.emf.core.papyrus" Papyrus project's hierarchy in the Project Explorer window. Double click on the "di" node to open the "Papyrus Editor Core" editor. At this point, if the instructions were followed, there will be two editors open in the Eclipse editor window. Foo ecore & model di.jpg

The "Sample Ecore model editor" and the "Papyrus Editor Core". The "Papyrus Editor Core" window will be further subdivided by a tab at the bottom with the label "FooClassDiagram". Foo ecore on top model di on bottom.jpg

Split the Eclipse editor window. Click and drag the "model.di" editor tab so it is in the bottom half of the editor window. See the screen capture for reference.

Drag and Drop the Package

Click and Drag EPackage Model fooEMFModel.jpg

Now that all the setup work is done the ecore model UML parts can be clicked and dragged from the "Sample Ecore model editor" editor to the "Papyrus Editor Core" editor. Expand the "platform://resource/software.foo.emf.core/model/fooEMFModel.uml" node. Click and drag the "<<EPackage>> <Model> fooEMFModel" node under the "platform://resource/software.foo.emf.core/model/fooEMFModel.uml" node onto the model.di editor. Notice, even without doing a drop, there are three more nodes in the "foo.ecore" editor at the top of the window

  • "pathmap://UML_LIBRARIES/EcorePrimativeTypes.library.uml"
  • "pathmap://UML_METAMODELS/Ecore.metamodel.uml"
  • "pathmap://UML_LIBRARIES/UMLPrimativeTypes.library.uml"

Also notice, again, even with out doing a drop, that the "Model Explorer" has a new node named "<<EPackage>> fooEMFModel". Drop the "<<EPackage>> <Model> fooEMFModel" on the Papyrus editor.

Now for the disappointing news. Notice how the click and drag did not travel down the hierarchy of the package and also paste the class and its attributes? The good new is that in the "Model Explorer" window the full hierarchy of the package did get copied. Also notice that the package can not be deleted or Unloaded. The only thing that can be done is a cut without a paste.

Drag and Drop the class

Because of the current limitation every single part of the Ecore model "fooEMFModel" must be clicked and dragged manually. For large EMF models that can be very time consuming.

Drag and Drop the attribute

Text

Drag and Drop the containment reference

Text

Drag and Drop the containment reference

Text

Drag and Drop the non-containment reference

Text

Save the Papyrus class diagram

Text

Propagate a change from Papyrus to Ecore

Change the package name

Text

Save the Papyrus class diagram

Text

Change the class name

Text

Save the Papyrus class diagram

Text

Change the attribute name

Text

Save the Papyrus class diagram

Text

Change the containment reference name

Text

Save the Papyrus class diagram

Text

Change the non-containment reference name

Text

Save the Papyrus class diagram

Text

Counter intuitive behavior of the Papyrus editor

Ecore parts can not be deleted from the Papyrus class diagram Any part of the Ecore model that has been put in the "Papyrus" diagram can't be deleted or unloaded.

Propagate changes from Ecore to Papyrus

Delete the class

Text

ConvetToUMLOperationWasSuccessful.jpg

Expanded empty Papyrus project.jpg

IrrevocableLinkofEcoreToPapyrus.jpg

Model di Drop01.jpg

Model di Drop02.jpg

Open Papyrus persective.jpg

Papyrus Diagram name and kind.jpg

Back to the top