blob: 17105ff3273cc288b27cf41166e17989c8ede633 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<cheatsheet
title="Create a script that runs on a Papyrus UML Model">
<intro>
<description>
This cheat sheet shows how to create a simple python script that shows the name of the selected element in a UML model.
This guide supposes you've already have a Papyrus UML model.
</description>
</intro>
<item
title="Open the model">
<description>
If you're not already in the Papyrus perspective, in the main meny select <b>Window</b> &gt; <b>Open Perspective</b> &gt; <b>Java</b> or click on the "Click to Perform" link below.
<br></br>
After you are in the Papyrus perspective, select the model where you want to execute a script.
</description>
<command
required="false"
serialization="org.eclipse.ui.perspectives.showPerspective(org.eclipse.ui.perspectives.showPerspective.perspectiveId=org.eclipse.papyrus.infra.core.perspective)"/>
</item>
<item
title="Create a script folder">
<description>
One way of organizing the structure of the project is having a separate folder for the script files that will contain the functionalities used.
<br></br>
In the Project Explorer view, go to your Papyrus project and create a new folder called "Scripts".
</description>
</item>
<item
title="Mark the folder as a script location">
<description>
You need to indicate that the folder you've just created contains scripts that need to be available to the EASE environment. In order to do that go to <b>Window</b> &gt; <b>Preferences</b> &gt; <b>Scripting</b> &gt; <b>Script Locations</b>
<br></br>
There click on the <b>Add Workspace...</b> button and pick the folder created in the previous step.
</description>
<command
required="true"
serialization="org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ease.preferences.scriptLocations)"/>
</item>
<item
title="Create the script">
<description>
Now you are set up for creating the script and specifying a new simple functionality.
<br></br>
Create the file "script.py" in your script folder, and add the following code:
<br></br>
<br> </br>
<b># name: Show Name</b>
<br> </br>
<b># papypopup : enableFor(org.eclipse.uml2.uml.Element)</b>
<br> </br>
<b># sengine: org.eclipse.ease.javascript.nashorn</b>
<br> </br>
<br> </br>
<b>PAPYRUS = loadModule("/Modeling/Papyrus")</b>
<br> </br>
<b>UI = loadModule("/System/UI")</b>
<br> </br>
<br> </br>
<b>elm = PAPYRUS.getSelectionElement()</b>
<br> </br>
<b>UI.showInfoDialog(elm.getName(), "Element Name...")</b>
<br> </br>
</description>
</item>
<item
title="Run the script">
<description>
You should now be able to test the script. The entry point of the sample script is configured to be at a contextual menu when you right-click any UML element.
<br></br>
So, in the Model Explorer, go to any UML Element, click with the right button and you should see a new command called "Show Element Name".
</description>
</item>
</cheatsheet>