Difference between revisions of "Extending the Rodin database (How to extend Rodin Tutorial)"
imported>Tommy m (→In this part) |
imported>Tommy m (→In Brief) |
||
(29 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | {{Navigation|Previous= [[ | + | {{Navigation|Previous= [[Creating_a_new_plug-in_using_eclipse_(How_to_extend_Rodin_Tutorial)|Creating our plug-in]]|Next=[[Extend_Rodin_Structured_Editor_(How_to_extend_Rodin_Tutorial)|Extending the structured editor]] | Up= [[Plug-in_Tutorial|How to extend Rodin Tutorial (Index)]]}} |
=== In this part === | === In this part === | ||
We will explain how to add a new attribute to events elements and add a new element in the database. | We will explain how to add a new attribute to events elements and add a new element in the database. | ||
− | Here are the steps we will detail : | + | Here are the steps we will detail: |
− | # | + | # Add dependencies to the plug-ins providing the extension services and interfaces we want to use. |
− | # | + | # Add the extension points we will use, and define our extensions. |
− | # | + | # Implement required classes to specify newly added elements. |
− | # | + | # Create an interface using Eclipse content assist. |
− | For more information about the database extension, please refer to : [[Extending_the_Rodin_Database| Extending the Rodin Database]] | + | For more information about the database extension, please refer to: [[Extending_the_Rodin_Database| Extending the Rodin Database]]. |
=== Step 1 === | === Step 1 === | ||
− | When one wants to use extension points provided by a | + | When one wants to use extension points provided by a plug-in, one has to add a dependency to this plug-in. |
− | We will use | + | We will use three extension points to extend the database, so we should add a dependency to the plug-in <tt>org.rodinp.core</tt> which defines them. |
− | Moreover, | + | Moreover, we want to manipulate Event-B elements: we will manipulate interfaces and public classes provided by the Event-B plug-in. Thus we alse have to add a dependency to the plug-in <tt>org.eventb.core</tt>.<br /> |
− | + | To do this, open the MANIFEST.MF file (with the Plug-in Manifest Editor) in the folder META-INF of the plug-in to get the following: | |
− | To do this, open the MANIFEST.MF file in the | ||
[[Image:Extend_Rodin_Tuto_1_5_Manifest_dependencies.png|500px]] | [[Image:Extend_Rodin_Tuto_1_5_Manifest_dependencies.png|500px]] | ||
− | 1. Click on the "Dependencies" Tab, <br> | + | 1. Click on the "Dependencies" Tab, <br /> |
− | 2. Click on the Add button.<br> | + | 2. Click on the Add button.<br /> |
− | A dialog appears, start to enter <tt>org.rodinp.core</tt> and select this | + | A dialog appears, start to enter <tt>org.rodinp.core</tt> and select this plug-in, press "OK" to add it to the dependencies.<br> |
− | |||
− | |||
− | You should now have the | + | You should now have the <tt>org.rodinp.core</tt> dependency added to the plug-in: |
[[Image:Extend_Rodin_Tuto_1_5_Added_Dependencies.png|200px]] | [[Image:Extend_Rodin_Tuto_1_5_Added_Dependencies.png|200px]] | ||
+ | |||
+ | Repeat step 1 and 2 to add a dependency on <tt>org.eventb.core</tt>. | ||
=== Step 2 === | === Step 2 === | ||
− | We will add | + | We will now add the extensions points that we want to use, and define extensions using them. |
[[Image:Extend_Rodin_Tuto_1_6_Add_Extension_Point.png|400px]] | [[Image:Extend_Rodin_Tuto_1_6_Add_Extension_Point.png|400px]] | ||
Line 41: | Line 40: | ||
As we will start by extending the database by adding the attribute "probabilistic", we will create an extension for <tt>org.rodinp.core.attributeTypes</tt> extension point. Hence, we need to add this extension point first before creating an extension with it. | As we will start by extending the database by adding the attribute "probabilistic", we will create an extension for <tt>org.rodinp.core.attributeTypes</tt> extension point. Hence, we need to add this extension point first before creating an extension with it. | ||
To do so... on the wizard that appeared (see picture above):<br> | To do so... on the wizard that appeared (see picture above):<br> | ||
− | 1. | + | 1. Start to type the extension point name <tt>org.rodinp.core.attributeTypes</tt>, to reveal it in the list of available extension points,<br> |
2. select it in the list, and click on "Finish" to add it. | 2. select it in the list, and click on "Finish" to add it. | ||
− | The extension point <tt>org.rodinp.core.attributeTypes</tt> now appears in the list on the "Extensions" page of the MANIFEST.MF of our | + | The extension point <tt>org.rodinp.core.attributeTypes</tt> now appears in the list on the "Extensions" page of the MANIFEST.MF of our plug-in. |
=== Step 3 === | === Step 3 === | ||
− | We will now add the attribute "probabilistic" in the database, creating an extension for <tt>org.rodinp.core.attributeTypes</tt>. | + | We will now add the attribute "probabilistic" in the database, creating an extension for <tt>org.rodinp.core.attributeTypes</tt> and registering its relationship with Event-B elements by creating an extension for <tt>org.rodinp.core.itemRelations</tt>. |
+ | |||
+ | Let's start with the first contribution.<br /> | ||
Right click on the extension point, select <tt>New > attributeType</tt> as in the picture below : | Right click on the extension point, select <tt>New > attributeType</tt> as in the picture below : | ||
Line 54: | Line 55: | ||
A new extension <tt>attributeType</tt> has been added. We will edit it to add our "probabilistic" attribute.<br> | A new extension <tt>attributeType</tt> has been added. We will edit it to add our "probabilistic" attribute.<br> | ||
As an event can be probabilistic or not, we set the kind of this attribute to <tt>boolean</tt>. | As an event can be probabilistic or not, we set the kind of this attribute to <tt>boolean</tt>. | ||
− | Give a unique ID to this attribute (here <tt> | + | Give a unique ID to this attribute (here <tt>probabilistic</tt>) and a name (here <tt>Event-B Probabilistic Attribute</tt>). |
You should now have something similar to what appears in the picture below : | You should now have something similar to what appears in the picture below : | ||
− | [[Image: | + | [[Image:Extend_Rodin_Tuto_1_7_Add_Attibute_Relation_Extension1.png|640px]] |
+ | Now let's define that "probabilistic" attributes are owned by Event-B Events.<br /> | ||
+ | As done in step 2, add the <tt>org.rodinp.core.itemRelations</tt> extension point to our plug-in. | ||
+ | By default, an empty relationship element has been created (see picture below). We will edit it.<br /> | ||
+ | |||
+ | Edit the <tt>parentTypeId</tt> with the id of the Event-B Event type which is <tt>org.eventb.core.event</tt>. | ||
+ | Then right click on the relationship extension and add a <tt>New > attributeType</tt> (as on the picture below). | ||
+ | |||
+ | [[Image:Extend_Rodin_Tuto_1_7_Add_Attibute_Relation_Extension2.png|640px]] | ||
+ | |||
+ | You just have to modify the <tt>typeId</tt> to refer to our attribute id which is <tt>fr.systerel.rodinextension.sample.probabilistic</tt>. | ||
+ | |||
+ | Congratulations! Now the probabilistic attributes will be available on Event-B Events!! | ||
=== Step 4 === | === Step 4 === | ||
Line 70: | Line 83: | ||
As in the picture above :<br> | As in the picture above :<br> | ||
− | 1. give the element a unique ID (here <tt> | + | 1. give the element a unique ID (here <tt>bound</tt>)<br> |
− | 2. give a name to this element (here Bound)<br> | + | 2. give a name to this element (here Event-B Bound Element)<br> |
3. now things differ, as this extension point (<tt>org.rodinp.core.internalElementTypes</tt>) requires us to provide a class describing the element.<br> | 3. now things differ, as this extension point (<tt>org.rodinp.core.internalElementTypes</tt>) requires us to provide a class describing the element.<br> | ||
Click on the "class*:" link to open a wizard that will help us to create this class. | Click on the "class*:" link to open a wizard that will help us to create this class. | ||
Line 88: | Line 101: | ||
=== Step 5 === | === Step 5 === | ||
− | + | When opening the class ''Bound.java'', we see that we need to implement the method <tt>getElementType()</tt> inherited from the superclass.<br> | |
− | As the type of element might be needed from outside, and is common to all Bound element, we will create a | + | As the type of element might be needed from outside, and is common to all Bound element, we will create a constant in a new interface <tt>IBound</tt> that we have to create.<br> |
Enter in the method body the following code : | Enter in the method body the following code : | ||
return IBound.ELEMENT_TYPE; | return IBound.ELEMENT_TYPE; | ||
− | [[Image:Extend_Rodin_Tuto_1_7_Create_Interface_Menu.png]] | + | [[Image:Extend_Rodin_Tuto_1_7_Create_Interface_Menu.png|400px]] |
− | Then use the quick assist (while you go over IBound underlined in red), to create the interface IBound. | + | Then use the quick assist (while you go over <tt>IBound</tt> underlined in red), to create the interface <tt>IBound</tt>. |
The following wizard appears : | The following wizard appears : | ||
[[Image:Extend_Rodin_Tuto_1_7_Create_Interface_Wizard.png|400px]] | [[Image:Extend_Rodin_Tuto_1_7_Create_Interface_Wizard.png|400px]] | ||
− | Use here the "Extended Interfaces" field to specify that the element '''Bound''' should be commented (thus shall implement ICommentedElement) and will carry an expression (thus shall implement IExpressionElement) for the value of the bound. | + | Use here the "Extended Interfaces" field to specify that the element '''Bound''' should be commented (thus shall implement <tt>ICommentedElement</tt>) and will carry an expression (thus shall implement <tt>IExpressionElement</tt>) for the value of the bound. |
public interface IBound extends ICommentedElement, IExpressionElement { | public interface IBound extends ICommentedElement, IExpressionElement { | ||
Line 107: | Line 120: | ||
} | } | ||
+ | Modify the class <tt>Bound.java</tt> to add <tt>implements IBound</tt>.<br> | ||
At this point of the development, you should have the following extensions : | At this point of the development, you should have the following extensions : | ||
[[Image:Extend_Rodin_Tuto_1_7_Used_Extensions.png]] | [[Image:Extend_Rodin_Tuto_1_7_Used_Extensions.png]] | ||
− | and you should have the following contents in your | + | and you should have the following contents in your plug-in : |
[[Image:Extend_Rodin_Tuto_1_7_ProjectExplorer2.png.png]] | [[Image:Extend_Rodin_Tuto_1_7_ProjectExplorer2.png.png]] | ||
− | + | === Step 6 === | |
+ | Now everything seems complete! But it is not yet. Look, we did not tell the Rodin Database were can our Bound elements appear.<br /> | ||
+ | To fix that, right click on the <tt>org.rodinp.core.itemRelations</tt> extension, that we used before to register "probabilistic" attributes as Event-B Event attributes, and define a <tt>New > relationship</tt> between <tt>org.eventb.core.machineFile</tt> and our element which id is <tt>fr.systerel.rodinextension.sample.bound</tt>. | ||
+ | |||
+ | Now the Rodin Database will accept our new element "'''Bound'''" as a valid child of any Event-B machine. | ||
=== In Brief === | === In Brief === | ||
− | + | You should have something that looks like this : | |
+ | |||
+ | [[Image:Extend_Rodin_Tuto_DB_ExtensionResult.png]] | ||
− | {{Navigation|Previous= [[ | + | We saw how to use Eclipse to add extension points that will be used in our plug-in and created our extensions using some helpful Eclipse automatic actions (wizard, content assist...). |
+ | As we had a detailed view (captures) of all the actions further needed, the next parts of this tutorial will focus only on the extensions. | ||
+ | |||
+ | {{Navigation|Previous= [[Creating_a_new_plug-in_using_eclipse_(How_to_extend_Rodin_Tutorial)|Creating our plug-in]]|Next= [[Extend_Rodin_Structured_Editor_(How_to_extend_Rodin_Tutorial)|Extending the structured editor]] | Up= [[Plug-in_Tutorial|How to extend Rodin Tutorial (Index)]]}} | ||
[[Category:Developer documentation|*Index]] | [[Category:Developer documentation|*Index]] | ||
[[Category:Rodin Platform|*Index]] | [[Category:Rodin Platform|*Index]] | ||
[[Category:Tutorial|*Index]] | [[Category:Tutorial|*Index]] |
Latest revision as of 17:44, 4 September 2013
In this part
We will explain how to add a new attribute to events elements and add a new element in the database. Here are the steps we will detail:
- Add dependencies to the plug-ins providing the extension services and interfaces we want to use.
- Add the extension points we will use, and define our extensions.
- Implement required classes to specify newly added elements.
- Create an interface using Eclipse content assist.
For more information about the database extension, please refer to: Extending the Rodin Database.
Step 1
When one wants to use extension points provided by a plug-in, one has to add a dependency to this plug-in.
We will use three extension points to extend the database, so we should add a dependency to the plug-in org.rodinp.core which defines them.
Moreover, we want to manipulate Event-B elements: we will manipulate interfaces and public classes provided by the Event-B plug-in. Thus we alse have to add a dependency to the plug-in org.eventb.core.
To do this, open the MANIFEST.MF file (with the Plug-in Manifest Editor) in the folder META-INF of the plug-in to get the following:
1. Click on the "Dependencies" Tab,
2. Click on the Add button.
A dialog appears, start to enter org.rodinp.core and select this plug-in, press "OK" to add it to the dependencies.
You should now have the org.rodinp.core dependency added to the plug-in:
Repeat step 1 and 2 to add a dependency on org.eventb.core.
Step 2
We will now add the extensions points that we want to use, and define extensions using them.
1. Click on the "Extensions" Tab,
2. and click on the "Add" button.
As we will start by extending the database by adding the attribute "probabilistic", we will create an extension for org.rodinp.core.attributeTypes extension point. Hence, we need to add this extension point first before creating an extension with it.
To do so... on the wizard that appeared (see picture above):
1. Start to type the extension point name org.rodinp.core.attributeTypes, to reveal it in the list of available extension points,
2. select it in the list, and click on "Finish" to add it.
The extension point org.rodinp.core.attributeTypes now appears in the list on the "Extensions" page of the MANIFEST.MF of our plug-in.
Step 3
We will now add the attribute "probabilistic" in the database, creating an extension for org.rodinp.core.attributeTypes and registering its relationship with Event-B elements by creating an extension for org.rodinp.core.itemRelations.
Let's start with the first contribution.
Right click on the extension point, select New > attributeType as in the picture below :
A new extension attributeType has been added. We will edit it to add our "probabilistic" attribute.
As an event can be probabilistic or not, we set the kind of this attribute to boolean.
Give a unique ID to this attribute (here probabilistic) and a name (here Event-B Probabilistic Attribute).
You should now have something similar to what appears in the picture below :
Now let's define that "probabilistic" attributes are owned by Event-B Events.
As done in step 2, add the org.rodinp.core.itemRelations extension point to our plug-in.
By default, an empty relationship element has been created (see picture below). We will edit it.
Edit the parentTypeId with the id of the Event-B Event type which is org.eventb.core.event. Then right click on the relationship extension and add a New > attributeType (as on the picture below).
You just have to modify the typeId to refer to our attribute id which is fr.systerel.rodinextension.sample.probabilistic.
Congratulations! Now the probabilistic attributes will be available on Event-B Events!!
Step 4
We will now add a new element "Bound" to set the upper bound of the probabilistic variant.
Repeat the step 2, to add the extension point : org.rodinp.core.internalElementTypes.
Create an extension to specify our new element "Bound" using the right click as previously.
You shall now specify the details for this new extension element :
As in the picture above :
1. give the element a unique ID (here bound)
2. give a name to this element (here Event-B Bound Element)
3. now things differ, as this extension point (org.rodinp.core.internalElementTypes) requires us to provide a class describing the element.
Click on the "class*:" link to open a wizard that will help us to create this class.
The following wizard appears :
1. First specify a package where you want this class to be stored. As we want to organise a bit the project, we will say that all elements that we add will be part of a new package called fr.systerel.rodinextension.sample.basis,
2. Give the name of the class : "Bound",
3. We see that the superclass of this element is org.rodinp.core.basis.InternalElement but we know that we will implement an element specific to Event-B, so we put here org.eventb.core.basis.EventBElement,
4. You can optionnaly add comments automatically to the created class, if you set them in "Preferences > Java > Code Style > Code Templates",
5. Click on "Finish" to create the class.
The class Bound.java has now been created. We can open it and review its contents that we anyway shall modify now.
Step 5
When opening the class Bound.java, we see that we need to implement the method getElementType() inherited from the superclass.
As the type of element might be needed from outside, and is common to all Bound element, we will create a constant in a new interface IBound that we have to create.
Enter in the method body the following code :
return IBound.ELEMENT_TYPE;
Then use the quick assist (while you go over IBound underlined in red), to create the interface IBound. The following wizard appears :
Use here the "Extended Interfaces" field to specify that the element Bound should be commented (thus shall implement ICommentedElement) and will carry an expression (thus shall implement IExpressionElement) for the value of the bound.
public interface IBound extends ICommentedElement, IExpressionElement { IInternalElementType<IBound> ELEMENT_TYPE = RodinCore .getInternalElementType(QualProbPlugin.PLUGIN_ID + ".bound"); }
Modify the class Bound.java to add implements IBound.
At this point of the development, you should have the following extensions :
and you should have the following contents in your plug-in :
Step 6
Now everything seems complete! But it is not yet. Look, we did not tell the Rodin Database were can our Bound elements appear.
To fix that, right click on the org.rodinp.core.itemRelations extension, that we used before to register "probabilistic" attributes as Event-B Event attributes, and define a New > relationship between org.eventb.core.machineFile and our element which id is fr.systerel.rodinextension.sample.bound.
Now the Rodin Database will accept our new element "Bound" as a valid child of any Event-B machine.
In Brief
You should have something that looks like this :
We saw how to use Eclipse to add extension points that will be used in our plug-in and created our extensions using some helpful Eclipse automatic actions (wizard, content assist...). As we had a detailed view (captures) of all the actions further needed, the next parts of this tutorial will focus only on the extensions.