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"

(Overview)
(The method does not apply. Page removed.)
Line 1: Line 1:
[[File:th.jpg]]
 
=Overview=
 
At this time, the ways that exist to get an EMF model into Papyrus -- that are designed to work -- all have severe limitations.  There are even ways that work by accident, not by design.  And the ways that "work by accident" also have most of the same limitations.  This page is written to save others from having to discover this on there own and loose precious time.
 
  
A possible positive outcome is that this list of EMF(ecore)-to-UML(papyrus) methods builds support for a product that does not have the limitations.  To that end Bugzilla feature requests [https://bugs.eclipse.org/bugs/show_bug.cgi?id=469430 Bug 469430] and [https://bugs.eclipse.org/bugs/show_bug.cgi?id=469431 Bug 469431 ] has been added to Papyrus.  If you are willing, and have a Eclipse Bugzilla account, take the time to vote for the feature please.
 
 
Below is a quick description of each method and its limitations.  Each method is shown in more detail as a sequence of screen captures further down on this page.
 
 
==Method 01==
 
===Ecore -> UML -> Papyrus===
 
:Strengths
 
::Great Java Code generation
 
:Limitations
 
::One way one time.
 
::No context aware support of Ecore properties on the Applied Stereotypes
 
::Poor Java Code generation
 
 
==Method 02==
 
===Papyrus using EMF Stereotypes===
 
:Strengths
 
::No need to round trip with EMF
 
:Limitations
 
::No context aware support of Ecore properties on the Applied Stereotypes
 
::Poor Java Code generation
 
 
==Method 02.01==
 
::Use the EMF Java code generator, not the Papyrus Java code generator Limitations
 
::It does work, but, it is not suppose to work.
 
 
==Method 03==
 
===Click and drag the EMF UML model onto the Papyrus editor===
 
:Strengths
 
::No need to round trip with EMF
 
:Limitations
 
::No context aware support of Ecore properties on the Applied Stereotypes
 
::It does work, but, it is not suppose to work.
 
 
==Method 04==
 
===Fully EMF in Papyrus without the Stereotype blot and use the EMF Java code generator===
 
:Strengths
 
::No need to round trip with EMF
 
::Great Java Code generation
 
:Limitations
 
::Does not exist.  Please vote if you like this method so the team can measure demand.
 
 
==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...". 
 
 
::[[File:New_Other.jpg|text-top]]
 
 
 
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.
 
 
::[[File:New_Eclipse_Modeling_Framework_Empty_EMF_Project.jpg|text-top]]
 
 
In the "New Empty EMF Project" dialog enter "software.foo.emf.core" at the "Project name:" prompt.
 
 
::[[File:give the EMF project a name.jpg|text-top]]
 
 
 
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..."
 
 
::[[File:New_EMF_model_context_&_popout_02.jpg|text-top]]
 
 
From the "Eclipse Modeling Framework" group of Wizards pick the "Ecore Model" wizard, then click the "<u>N</u>ext >" button.
 
 
::[[File:New_Ecore_Model.jpg|text-top]]
 
 
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.
 
 
::[[File:Empty_foo_ecore.jpg|text-top]]
 
 
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==
 
::[[File:ConvertToUMLModel.jpg|text-top]]
 
 
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. 
 
 
::[[File:ConvertPackageToUMLmodel.jpg|text-top]]
 
 
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. 
 
 
::[[File:ConvetToUMLOperationWasSuccessful.jpg|text-top]]
 
 
Once done a "Convet To UML Operation Was Successful" message will appear.  Press the "Ok" button to close the message. 
 
::[[File:OneNewFileSixNewNodes.jpg|text-top]]
 
 
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"
 
 
::[[File:WarningsThatCanBeIgnored.jpg|text-top]]
 
 
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===
 
 
::[[File:EMF_Generator_Model.jpg|text-top]]
 
 
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 "<u>N</u>ext >" button.  From the "Create the Generator model" panel press the "<u>N</u>ext >" button. 
 
 
::[[File:CreateTheEcoreModelBasedOnOtherEcoreOrEMOFModels.jpg|text-top]]
 
 
Check that the "Ecore model" Model Importer is selected.  Press the "<u>N</u>ext >" button.  From the "Specify one or more '.ecore' or '.emof' URIs and try to load them" panel.
 
 
::[[File:SpecifyOneOrMoreEcoreOrEMOFURIsAndTryToLoadThem.jpg|text-top]]
 
 
Press the "<u>L</u>oad >" button.  It will seem like nothing happened, but notice how the "<u>N</u>ext >" button is now enabled.
 
Press press the "<u>N</u>ext >" button. 
 
 
::[[File:RootPackages.jpg|text-top]]
 
 
From the "root" packages panel press the "<u>F</u>inish" button.
 
 
::[[File:Foo_GenModel.jpg|text-top]]
 
 
===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. 
 
 
::[[File:Open Papyrus persective.jpg|text-top]]
 
 
From the list of perspectives pick the Papyrus perspective.  The click will open the Papyrus perspective in Eclipse.
 
 
::[[File:New Papyrus Project.jpg|text-top]]
 
 
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. 
 
::[[File:UML Diagram Language.jpg|text-top]]
 
 
Pick "UML" radio button for the Diagram Language, not the "Project" or "SysML" options.  Press the "Next" button.  Enter "FooClassDiagram" as the "Diagram Name". 
 
 
::[[File:Papyrus Diagram name and kind.jpg|text-top]]
 
 
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.
 
 
 
::[[File:Foo_ecore_&_model_di.jpg|text-top]]
 
 
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".
 
 
::[[File:foo_ecore on top model_di on bottom.jpg|text-top]]
 
 
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===
 
::[[File:Click_and_Drag_EPackage_Model_fooEMFModel.jpg|text-top]]
 
 
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"
 
 
::[[File:PapyrusModelExplorerFooEMFModel.jpg|text-top]]
 
 
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.
 
 
::[[File:irrevocableLinkofEcoreToPapyrus.jpg|text-top]]
 
 
'''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 [[How_to_get_a_EMF_Ecore_model_into_a_Papyrus_class_diagram#Create a Papyrus project | 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===
 
 
::[[File:ClickAndDragEClassOntoPapyrusModel.jpg|text-top]]
 
 
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===
 
::[[File:ClickAndDragEAttributeOntoPapyrusModel.jpg|text-top]]
 
 
===Drag and Drop the non-containment reference===
 
::[[File:ClickAndDragEReferenceNonContainOntoPapyrusModel.jpg|text-top]]
 
 
===Drag and Drop the containment reference===
 
::[[File:ClickAndDragEReferenceContainOntoPapyrusModel.jpg|text-top]]
 
 
===Save the Papyrus class diagram===
 
::[[File:FooEMFModeldiBeforeAnyChanges.jpg|text-top]]
 
 
=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===
 
 
::[[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.
 
 
Give focus to the "fooEMFModel" package name in the diagram.  Navigate down to the properties panel and give focus to the Name field.
 
 
::[[File:fooEMFModelecoreBefore_PChangeOffooEMFModel.jpg|text-top]]
 
 
Change the Name from "fooEMFModel" to "fooEMFModel_P".  Give focus back to the diagram and save the diagram with CTL+S.
 
 
::[[File:fooEMFModelumlAfter_PChangeOffooEMFModel.jpg|text-top]]
 
 
Notice how the "fooEMFModel.uml" file has changed.
 
 
::[[File:fooEMFModelgenmodelAfter_PChangeOffooEMFModel.jpg|text-top]]
 
 
Notice how the "foo.genmodel" file has not changed.
 
 
::[[File:fooEMFModelecoreAfter_PChangeOffooEMFModel.jpg|text-top]]
 
 
Notice how the "foo.ecore" file has not changed.
 
 
===Save the Papyrus package name change===
 
::[[File:fooEMFModelumlAfter_PSaveOffooEMFModel.jpg|text-top]]
 
 
===Change the class name===
 
 
::[[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:fooEMFModelumlBefore_PChangeOfFoo.jpg|text-top]]
 
 
Give focus to the "Foo" class name in the diagram.  Navigate down to the properties panel and give focus to the Name field.
 
 
::[[File:fooEMFModeleCoreAfter_PChangeOfFoo.jpg|text-top]]
 
 
Change the Name from "Foo" to "Foo_P".  Give focus back to the diagram and save the diagram with CTL+S.
 
 
::[[File:fooEMFModelumlAfter_PChangeOfFoo.jpg|text-top]]
 
 
Notice how the "fooEMFModel.uml" file has changed.
 
 
 
::[[File:fooEMFModelgenmodelAfter_PChangeOfFoo.jpg|text-top]]
 
 
Notice how the "foo.genmodel" file has not changed.
 
 
 
::[[File:fooEMFModelecoreAfter_PChangeOfFoo.jpg|text-top]]
 
 
Notice how the "foo.ecore" file has not changed.
 
 
===Save the Papyrus class name change===
 
Give focus to the Papyrus diagram and press CTL+S to save the Papyrus diagram changes.
 
 
::[[File:fooEMFModelumlAfter_PSaveOfFoo.jpg|text-top]]
 
 
===Change the fooThing attribute name===
 
 
::[[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:FooEMFModeldiBefore_PChangeOffooThing.jpg|text-top]]
 
 
Give focus to the "fooThing" attribute in the diagram. Navigate down to the properties panel and give focus to the Name field.
 
 
::[[File:FooEMFModeldiAfter_PChangeOffooThing.jpg|text-top]]
 
 
Change the Name from "fooThing" to "fooThing_P". Give focus back to the diagram and save the diagram with CTL+S.
 
 
Notice how fooThing in the "fooEMFModel.uml" file has changed.
 
 
::[[File:fooEMFModelumlAfter_PSaveOffooThing.jpg|text-top]]
 
 
Notice how the "foo.genmodel" file has not changed.
 
 
::[[File:fooEMFModelgenmodelAfter_PChangeOffooThing.jpg|text-top]]
 
 
Notice how the "foo.ecore" file has not changed.
 
 
::[[File:fooEMFModelecoreAfter_PChangeOfFoo.jpg|text-top]]
 
 
===Save the Papyrus fooThing name change===
 
::[[File:FooEMFModeldiAfter_PChangeOffooThing.jpg|text-top]]
 
 
===Change the fooOwns containment reference name===
 
 
::[[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.
 
 
::[[File:FooEMFModeldiAfter_PChangeOffooOwns.jpg|text-top]]
 
 
Notice how the "fooEMFModel.uml" file has changed.
 
 
::[[File:fooEMFModelumlAfter_PChange.jpg|text-top]]
 
 
Notice how the "foo.genmodel" file has not changed.
 
 
::[[File:fooEMFModelgenmodelAfter_PChange.jpg|text-top]]
 
 
Notice how the "foo.ecore" file has not changed.
 
 
::[[File:fooEMFModelecoreAfter_PChange.jpg|text-top]]
 
 
===Save the Papyrus fooOwns name change===
 
::[[File:FooEMFModeldiAfter_PChangeOffooOwns.jpg|text-top]]
 
 
===Change the non-containment reference name===
 
::[[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:FooEMFModeldiBefore_PChangeOffooPointsTo.jpg|text-top]]
 
 
Give focus to the "fooPointsTo" attribute in the diagram.  Navigate down to the properties panel and give focus to the Name field.
 
 
::[[File:FooEMFModeldiAfter_PChangeOffooPointsTo.jpg|text-top]]
 
 
Change the Name from "fooPointsTo" to "fooPointsTo_P".  Give focus back to the diagram and save the diagram with CTL+S.
 
 
::[[File:fooEMFModelumlAfter_PChangeOfFooPointsTo.jpg|text-top]]
 
 
Notice how the "fooEMFModel.uml" file has changed.
 
 
 
::[[File:fooEMFModelgenmodelAfter_PChangeOfFooPointsTo.jpg|text-top]]
 
 
Notice how the "foo.genmodel" file has not changed.
 
 
 
::[[File:fooEMFModelecoreAfter_PChangeOfFooPointsTo.jpg|text-top]]
 
 
Notice how the "foo.ecore" file has not changed.
 
 
===Save the Papyrus fooPointsTo name change===
 
::[[File:FooEMFModeldiAfter_PChangeOffooPointsTo.jpg|text-top]]
 
 
=Propagate changes from Ecore to Papyrus=
 
::[[File:WillNotClickAndDrag.jpg|text-top]]
 
==Delete the class==
 

Revision as of 14:15, 15 July 2015

Back to the top