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

Difference between revisions of "How to get a EMF Ecore model into a Papyrus class diagram"

(Change the package name)
(Change the package name)
Line 232: Line 232:
  
 
===Change the package name===
 
===Change the package name===
 
+
Text
[[File:EnableWriteOnfooEMFModelMenu.jpg|text-top]]
+
 
+
Select the fooEMFModel class in the Papyrus Model Explorer panel.  Right click to get the pop-out context menu.  Select "Enable write".
+
 
+
[[File:EnableWriteOnfooEMFModelMessage.jpg|text-top]]
+
 
+
A message will pop up asking to confirm making fooEMFModel writable.  Press the "Ok" button.
+
 
+
[[File:FooOwnsName.jpg|text-top]]
+
 
+
Give focus to the "fooOwns" attribute in the diagram.  Navigate down to the properties panel and give focus to the Name field.
+
 
+
[[File:FooOwnsNameAdd_P.jpg|text-top]]
+
 
+
Change the Name from "fooOwns" to "fooOwns_P".  Give focus back to the diagram and save the diagram with CTL+S.
+
  
 
===Save the Papyrus class diagram===
 
===Save the Papyrus class diagram===

Revision as of 20:19, 20 April 2015

Th.jpg

Create an Ecore model

Create an empty Ecore project

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 "Other...".

New Other.jpg


From the "Eclipse Modeling Framework" group of Wizards pick the "Empty EMF Project" wizard. 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.

New Eclipse Modeling Framework Empty EMF Project.jpg

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, this How-To example does not need a execution environment.

Create a model

From the "software.foo.emf.core" EMF project pick the "Model" node and right click to get the context menu. Pick "New" then "Other..."

New EMF model context & popout 02.jpg

From the "Eclipse Modeling Framework" group of Wizards pick the "Ecore Model" wizard, then click the "Next >" button.

New Ecore Model.jpg

Give the model the name "foo.ecore"

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 = fooEMFModel
  • Ns prefix = foo
  • Ns URI = software.foo

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 = EString[java.lang.String]
  • EType = EString[java.lang.String]
  • ID = false
  • Lower Bound = 0
  • Name = FooThing
  • Ordered = true
  • Transient = false
  • Unique = true
  • Unsettable = false
  • Upper Bound = 1
  • Volatile = false

Create a containment reference in the class

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

  • Changeable = true
  • Container = false
  • Containment = true
  • Default Value Literal = null
  • Derived = false
  • EKeys = null
  • EOpposite = null
  • EType = EObject[org.eclipse.emf.ecore.EObject]
  • Lower Bound = 0
  • Name = fooOwns
  • 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 = false
  • Containment = false
  • Default Value Literal = null
  • Derived = false
  • EKeys = null
  • EOpposite = null
  • EType = EObject[org.eclipse.emf.ecore.EObject]
  • Lower Bound = 0
  • Name = fooPointsTo
  • 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.

ConvertPackageToUMLmodel.jpg

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.

ConvetToUMLOperationWasSuccessful.jpg

Once done a "Convet To UML Operation Was Successful" message will appear. Press the "Ok" button to close the message. OneNewFileSixNewNodes.jpg

There will now be six 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_LIBRARIES/EcorePrimitiveTypes.library.uml"
  • "pathmap://UML_PROFILES/Standard.profile.uml"
  • "pathmap://UML_PROFILES/Ecore.profile.uml"
  • "pathmap://UML_METALMODELS/UML.metamodel.uml"
  • "platform://resource/software.foo.emf.core/model/fooEMFModel.uml"
  • "platform://resource/software.foo.emf.core/model/ecore.uml"

WarningsThatCanBeIgnored.jpg

There will be two warning messages. One that says "build.properties does not exist". The other will say "No required execution environment has been set". Both warning messages can both be ignored.

Create EMF Generator Model

EMF Generator Model.jpg

From the Package Explorer select the "foo.ecore" node in the "software.foo.emf.core" project. Right click to get the pop-out context menu. From the context menu select "New" -> "Other..." From the "Eclipse Modeling Framework" group pick "EMF Generator Model". Press the "Next >" button. From the "Create the Generator model" panel press the "Next >" button.

CreateTheEcoreModelBasedOnOtherEcoreOrEMOFModels.jpg

Check that the "Ecore model" Model Importer is selected. Press the "Next >" button. From the "Specify one or more '.ecore' or '.emof' URIs and try to load them" panel.

SpecifyOneOrMoreEcoreOrEMOFURIsAndTryToLoadThem.jpg

Press the "Load >" button. It will seem like nothing happened, but notice how the "Next >" button is now enabled. Press press the "Next >" button.

RootPackages.jpg

From the "root" packages panel press the "Finish" button.

Foo GenModel.jpg

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.

Open Papyrus persective.jpg

From the list of perspectives pick the Papyrus perspective. The click will open the Papyrus perspective in Eclipse.

New Papyrus Project.jpg

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.

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".

Papyrus Diagram name and kind.jpg

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 two more nodes in the "foo.ecore" editor at the top of the window

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

PapyrusModelExplorerFooEMFModel.jpg

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.

IrrevocableLinkofEcoreToPapyrus.jpg

A word of caution at this point. If the Papyrus project is deleted the six "pathmap" entries and two "platform" nodes in the Ecore model are not automatically deleted. They can not be manually deleted through the context pop-out menu either. What can be done? It is possible to delete the Papyrus project. Then repeat the steps from Create a Papyrus project on down. Maybe at some future date someone who knows more will update this wiki page. Another possibility is that the delete feature will be implemented at some future date.

Drag and Drop the class

ClickAndDragEClassOntoPapyrusModel.jpg

Click and drag the EClass "Foo" from the Papyrus "Model Explorer" into the "fooEMFModel" package of the "model.di" canvas. 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

ClickAndDragEAttributeOntoPapyrusModel.jpg

Drag and Drop the non-containment reference

ClickAndDragEReferenceNonContainOntoPapyrusModel.jpg

Drag and Drop the containment reference

ClickAndDragEReferenceContainOntoPapyrusModel.jpg

Save the Papyrus class diagram

SavePapyrusProject.jpg

Propagate a change from Papyrus to Ecore

A change to the Papyrus class diagram will also change the corresponding Ecore *.uml file for the class in the ECore "software.foo.emf.core" project. A change to the Papyrus class diagram will not also change the corresponding ECore *.genmodel file in the "software.foo.emf.core" project. A change to the Papyrus class diagram will not also change the corresponding ECore *.ecore file in the "software.foo.emf.core" project.

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

Back to the top