https://wiki.event-b.org/index.php?title=How_to_create_Rodin_projects_programmatically&feed=atom&action=historyHow to create Rodin projects programmatically - Revision history2024-03-29T15:58:06ZRevision history for this page on the wikiMediaWiki 1.33.3https://wiki.event-b.org/index.php?title=How_to_create_Rodin_projects_programmatically&diff=14534&oldid=prevLaurent at 15:19, 21 August 20232023-08-21T15:19:43Z<p></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en-GB">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 15:19, 21 August 2023</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>The code snippets on this page are derived from the UML-B plugin 'ac.soton.umlb.eventB', package 'generator'.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>The code snippets on this page are derived from the UML-B plugin 'ac.soton.umlb.eventB', package 'generator'.</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>You can find this package in the Rodin projects sourceforge SVN repository : https://<del class="diffchange diffchange-inline">rodin-b-sharp.svn.</del>sourceforge.net/<del class="diffchange diffchange-inline">svnroot</del>/rodin-b-sharp/<del class="diffchange diffchange-inline">trunk/UML-B/ac.soton.umlb.eventB/src/ac/soton/umlb/eventB/generator/ (''[http://rodin-b-sharp.</del>svn<del class="diffchange diffchange-inline">.sourceforge.net</del>/<del class="diffchange diffchange-inline">viewvc</del>/<del class="diffchange diffchange-inline">rodin-b-sharp</del>/trunk/UML-B/ac.soton.umlb.eventB/src/ac/soton/umlb/eventB/generator/ <del class="diffchange diffchange-inline">Browse]'')</del></div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>You can find this package in the Rodin projects sourceforge SVN repository : https://sourceforge.net/<ins class="diffchange diffchange-inline">p</ins>/rodin-b-sharp/svn/<ins class="diffchange diffchange-inline">HEAD</ins>/<ins class="diffchange diffchange-inline">tree</ins>/trunk/UML-B/ac.soton.umlb.eventB/src/ac/soton/umlb/eventB/generator/ </div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[Some of the code could be improved wrt the use of monitors. An explanation of some of the parameters in the Rodin API could be added]</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[Some of the code could be improved wrt the use of monitors. An explanation of some of the parameters in the Rodin API could be added]</div></td></tr>
</table>Laurenthttps://wiki.event-b.org/index.php?title=How_to_create_Rodin_projects_programmatically&diff=5536&oldid=previmported>Mathieu: Link to SVN repo instead of CVS2009-03-31T11:52:30Z<p>Link to SVN repo instead of CVS</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en-GB">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 11:52, 31 March 2009</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>The code snippets on this page are derived from the UML-B plugin 'ac.soton.umlb.eventB', package 'generator'.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>The code snippets on this page are derived from the UML-B plugin 'ac.soton.umlb.eventB', package 'generator'.</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>You can find this package in the Rodin projects sourceforge <del class="diffchange diffchange-inline">CVS </del>repository.</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>You can find this package in the Rodin projects sourceforge <ins class="diffchange diffchange-inline">SVN </ins>repository <ins class="diffchange diffchange-inline">: https://rodin-b-sharp.svn.sourceforge.net/svnroot/rodin-b-sharp/trunk/UML-B/ac.soton.umlb</ins>.<ins class="diffchange diffchange-inline">eventB/src/ac/soton/umlb/eventB/generator/ (''[</ins>http://rodin-b-sharp.<ins class="diffchange diffchange-inline">svn</ins>.sourceforge.net<ins class="diffchange diffchange-inline">/viewvc</ins>/rodin-b-sharp<ins class="diffchange diffchange-inline">/trunk/UML-B</ins>/ac.soton.umlb.eventB/src/ac/soton/umlb/eventB/generator/ <ins class="diffchange diffchange-inline">Browse]'')</ins></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>http://rodin-b-sharp.<del class="diffchange diffchange-inline">cvs</del>.sourceforge.net/rodin-b-sharp/ac.soton.umlb.eventB/src/ac/soton/umlb/eventB/generator/</div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[Some of the code could be improved wrt the use of monitors. An explanation of some of the parameters in the Rodin API could be added]</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[Some of the code could be improved wrt the use of monitors. An explanation of some of the parameters in the Rodin API could be added]</div></td></tr>
</table>imported>Mathieuhttps://wiki.event-b.org/index.php?title=How_to_create_Rodin_projects_programmatically&diff=5535&oldid=previmported>Mathieu: Robot: Changing Category:Developer Documentation2008-09-10T21:26:43Z<p>Robot: Changing Category:Developer Documentation</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en-GB">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 21:26, 10 September 2008</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l122" >Line 122:</td>
<td colspan="2" class="diff-lineno">Line 122:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> invariant.setPredicateString(myPredicateString,null);</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> invariant.setPredicateString(myPredicateString,null);</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Developer <ins class="diffchange diffchange-inline">documentation</ins>]]</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Developer <del class="diffchange diffchange-inline">Documentation</del>]]</div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Rodin Platform]]</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Rodin Platform]]</div></td></tr>
</table>imported>Mathieuhttps://wiki.event-b.org/index.php?title=How_to_create_Rodin_projects_programmatically&diff=5534&oldid=previmported>Mathieu at 11:01, 10 July 20082008-07-10T11:01:40Z<p></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en-GB">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 11:01, 10 July 2008</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l121" >Line 121:</td>
<td colspan="2" class="diff-lineno">Line 121:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> invariant.setPredicateString(myPredicateString,null);</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> invariant.setPredicateString(myPredicateString,null);</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">[[Category:Developer Documentation]]</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">[[Category:Rodin Platform]]</ins></div></td></tr>
</table>imported>Mathieuhttps://wiki.event-b.org/index.php?title=How_to_create_Rodin_projects_programmatically&diff=5533&oldid=previmported>Colin: New page: The code snippets on this page are derived from the UML-B plugin 'ac.soton.umlb.eventB', package 'generator'. You can find this package in the Rodin projects sourceforge CVS repository. h...2008-07-10T10:23:44Z<p>New page: The code snippets on this page are derived from the UML-B plugin 'ac.soton.umlb.eventB', package 'generator'. You can find this package in the Rodin projects sourceforge CVS repository. h...</p>
<p><b>New page</b></p><div>The code snippets on this page are derived from the UML-B plugin 'ac.soton.umlb.eventB', package 'generator'.<br />
You can find this package in the Rodin projects sourceforge CVS repository.<br />
<br />
http://rodin-b-sharp.cvs.sourceforge.net/rodin-b-sharp/ac.soton.umlb.eventB/src/ac/soton/umlb/eventB/generator/<br />
<br />
[Some of the code could be improved wrt the use of monitors. An explanation of some of the parameters in the Rodin API could be added]<br />
<br />
== How to create a Rodin Project ==<br />
Here is a method to create a Rodin project of a given name. (This method overwrites any existing Rodin project of that name).<br />
The project handle is retrieved from the rodin database. if the project does not exist, it is created using the handle.<br />
The project is opened. The project is given the Rodin 'nature' (if not already).<br />
The project is set to derived (this is not strictly necessary but it can be used to distinguish projects that the user has created from ones that have been created programmatically). <br />
<br />
public static IRodinProject createRodinProject(final String projectName) {<br />
final IWorkspace workspace = ResourcesPlugin.getWorkspace(); <br />
try {<br />
final IRodinDB rodinDB = RodinCore.valueOf(workspace.getRoot());<br />
final IRodinProject rodinProject = rodinDB.getRodinProject(projectName);<br />
final IProject project = rodinProject.getProject();<br />
if (!project.exists()) project.create(null);<br />
project.open(null);<br />
<br />
// add the rodin nature if it isn't already there<br />
final IProjectDescription description = project.getDescription();<br />
final String[] natures = description.getNatureIds();<br />
boolean alreadyRodin = false;<br />
for (int i = 0; i < natures.length; ++i)<br />
if (RodinCore.NATURE_ID.equals(natures[i])) {<br />
alreadyRodin = true;<br />
break;<br />
}<br />
if (!alreadyRodin) { // Add the Rodin nature<br />
final String[] newNatures = new String[natures.length + 1];<br />
System.arraycopy(natures, 0, newNatures, 0, natures.length);<br />
newNatures[natures.length] = RodinCore.NATURE_ID;<br />
description.setNatureIds(newNatures);<br />
project.setDescription(description, null);<br />
}<br />
project.setDerived(true); // mark the project as derived (this could be used to distinguish user editable projects<br />
return rodinProject;<br />
} catch (final CoreException e) {<br />
.... exception code ....<br />
}<br />
}<br />
<br />
Once you have created a Rodin Project you may want to call its save method to save it. Since this method makes changes to the workspace, you need to call it from a WorkspaceRunnable.<br />
For Example:-<br />
<br />
RodinCore.run(new IWorkspaceRunnable() {<br />
public void run(final IProgressMonitor monitor) throws CoreException{<br />
monitor.beginTask("",10);<br />
rodinProject=createRodinProject(projectName);<br />
rodinProject.save(null, true);<br />
monitor.done();<br />
}<br />
},null);<br />
<br />
==How to create a Rodin File construct (e.g. Machine, Context)==<br />
Here is a method to create a new Rodin File construct of a given filename in the given Rodin project and with a given comment.<br />
Note that the filename should include the correct extension (e.g. ".bum" for a Machine).<br />
The handle is retrieved from the Rodin project and used to create the new Rodin file.<br />
The corresponding resource is set to derived to indicate that it was generated programmatically.<br />
The comment is added to the Rodin File.<br />
<br />
public static IRodinFile createRodinConstruct(final String filename, final IRodinProject rProject, final String comment) {<br />
if (rProject == null)<br />
return null;<br />
try {<br />
final IRodinFile rodinFile = rProject.getRodinFile(filename);<br />
rodinFile.create(true, null);<br />
rodinFile.getResource().setDerived(true); // mark the file as derived<br />
if (rodinFile instanceof ICommentedElement)<br />
if (comment != null && !comment.trim().equals(""))<br />
((ICommentedElement) rodinFile).setComment(comment, null);<br />
return rodinFile;<br />
} catch (final Exception e) {<br />
.... exception code ....<br />
}<br />
}<br />
<br />
As with the Rodin project above, if you want to save the created construct, you should do this from a WorkspaceRunnable.<br />
<br />
==How to create a Rodin element==<br />
Here is a method to create a new Rodin element of a given type and name in the given Rodin element and Rodin File and with a given comment.<br />
The handle is retrieved from the parent element and used to create the new Rodin element. Depending on the type of the new Rodin element, the name is used as the <br />
label, identifier, or abstract event label. The comment is set if the element type owns a comment.<br />
<br />
public static IInternalElement createRodinElement(<br />
final IInternalElementType type,<br />
final String name,<br />
final IInternalElement parent,<br />
final IRodinFile rodinFile,<br />
final String comment) {<br />
if (parent == null) return null;<br />
try {<br />
final IInternalElement rodinEl = parent.getInternalElement(type, name)<br />
rodinEl.create(null, null);<br />
if (rodinEl instanceof ILabeledElement)<br />
((ILabeledElement) rodinEl).setLabel(name, null);<br />
if (rodinEl instanceof IIdentifierElement)<br />
((IIdentifierElement) rodinEl).setIdentifierString(name, null);<br />
if (rodinEl instanceof ICommentedElement)<br />
if (comment != null)<br />
((ICommentedElement) rodinEl).setComment(comment,null);<br />
if (rodinEl instanceof IRefinesEvent)<br />
((IRefinesEvent) rodinEl).setAbstractEventLabel(name, null);<br />
return rodinEl;<br />
} catch (final Exception e) {<br />
.... exception code ....<br />
}<br />
}<br />
<br />
This method is called passing the appropriate element type which can be obtained from the Rodin element class. For example an Invariant can be created like this:-<br />
<br />
IInvariant invariant = (IInvariant) createRodinElement(IInvariant.ELEMENT_TYPE, invariantName, rodinFile, rodinFile, comment);<br />
<br />
==How to set attributes of a Rodin Element==<br />
<br />
To set attributes of a Rodin Element, use the appropriate methods of the element (depending on the element type).<br />
For example:-<br />
<br />
invariant.setPredicateString(myPredicateString,null);</div>imported>Colin