Difference between pages "Extending the Rodin Pretty Print Page (How to extend Rodin Tutorial)" and "Extending the Rodin Structured Editor (How to extend Rodin Tutorial)"

From Event-B
(Difference between pages)
Jump to navigationJump to search
imported>Pascal
 
imported>Tommy
m (New page: {{Navigation|Previous= Extend the database | Up= How to extend Rodin Tutorial (Index) | Next= }} === In this ...)
 
Line 1: Line 1:
{{Navigation|Previous= [[Extending_the_Rodin_Event-B_Explorer_(How_to_extend_Rodin_Tutorial)|Adding elements to the Event-B explorer]]| Next=[[Providing_help_for_your_plug-in_(How_to_extend_Rodin_Tutorial)|Providing help]] | Up= [[Plug-in_Tutorial|How to extend Rodin Tutorial (Index)]]}}
+
{{Navigation|Previous= [[Extend_Rodin_database_(How_to_extend_Rodin_Tutorial)|Extend the database]] | Up= [[Plug-in_Tutorial|How to extend Rodin Tutorial (Index)]] | Next= }}
  
 
=== In this part ===
 
=== In this part ===
 +
We will use the extension points provided by the plugin <tt>org.eventb.ui</tt> to add our Probabilistic Attribute on events and the Bound Element to the Structured Editor.
  
As this extension mechanism is detailed on a dedicated page of the wiki, we will here comment the implementation of a pretty printer for the bound elements. Unfortunately, it is not yet possible to act on the pretty print of events, so the probabilistic will not be displayed here.
+
=== Step 1 ===
 +
To structure a bit our development, we will separate the UI from the business layer.<br>
 +
1. Create a new plugin (here <tt>fr.systerel.rodinextension.sample.ui</tt>, and this time, select "This plug-in will make contributions to the UI" as it will be indeed the case here.<br>
 +
2. Add our business plugin (<tt>fr.systerel.rodinextension.sample</tt>) to the dependencies as well as <tt>org.eventb.ui</tt> that provides the extensions points we want to use.
  
See here for the detailed documentation : [[Extending_the_Pretty_Print_Page| Extending the Pretty print Page]]
+
=== Step 2 ===
 +
1. Add the extension point <tt>org.eventb.ui.editorItems</tt>
 +
At this point, we will start to add our extensions to the structured editor.<br>
  
=== Step1 ===
+
=== Step 3 ===
Go back to the element extension for the bound element <tt>fr.systerel.rodinextension.sample.bound</tt> that we previously created from the <tt>org.eventb.ui.editorItems</tt> extension point.
+
First, let's add the probabilistic attribute to Event-B events.<br>
Create a new class that will implement the pretty printer for the bound element, using the eclipse new class wizard as in the picture below.
+
The probabilistic attribute can have two values : 'standard' (by default) and 'probabilistic'. Thus we need to create a 'choiceAttribute' extension.
 +
Create a new 'choice attibute' extension :<br>
 +
1. give a unique ID to identify this attribute in the UI plugin (such as <tt>fr.systerel.rodinextension.sample.ui.probabilistic</tt>),<br>
 +
2. in typeID, give the ID reference of the probabilistic attribute in our business plugin (here <tt>fr.systerel.rodinextension.sample.probabilistic</tt>), <br>
 +
3. create a class (using Eclipse assist, see [[Extend_Rodin_database_(How_to_extend_Rodin_Tutorial)|Step4]]) to manipulate this attribute, this class should implements the interface <tt>org.eventb.ui.IAttributeManipulation</tt>.
 +
:This class should be implemented the following :
 +
:Before doing any manipulation on
 +
:1. getPossibleValues() should return an array of two constant values : 'standard' and 'probabilistic',
 +
:2. // FIXME Continue here.
  
[[Image:Extend_Rodin_Tuto_1_11_Add_PrettyPrinter.png]]
 
  
=== Step2 ===
 
  
Edit this class as following :
 
  
public class BoundPrettyPrinter extends DefaultPrettyPrinter {
 
 
private static final String BOUND_EXPRESSION = "variantExpression";
 
private static final String BOUND_EXPRESSION_SEPARATOR_BEGIN = null;
 
private static final String BOUND_EXPRESSION_SEPARATOR_END = null;
 
 
@Override
 
public void prettyPrint(IInternalElement elt, IInternalElement parent, IPrettyPrintStream ps) {
 
if (elt instanceof IBound) {
 
IBound bound = (IBound) elt;
 
try {
 
appendBoundExpression(ps,wrapString(bound.getExpressionString()));
 
} catch (RodinDBException e) {
 
System.err.println("Cannot get the expression string for the bound element."+ e.getMessage());
 
}
 
}
 
}
 
 
private static void appendBoundExpression(IPrettyPrintStream ps, String expression) {
 
    ps.appendString(expression, //
 
      getHTMLBeginForCSSClass(BOUND_EXPRESSION, //
 
                              HorizontalAlignment.LEFT, //
 
                              VerticalAlignement.MIDDLE),//
 
      getHTMLEndForCSSClass(BOUND_EXPRESSION, //
 
                              HorizontalAlignment.LEFT, //
 
                              VerticalAlignement.MIDDLE),//
 
                              BOUND_EXPRESSION_SEPARATOR_BEGIN, //
 
                              BOUND_EXPRESSION_SEPARATOR_END);
 
}
 
 
}
 
  
As we want only to display the expression hold by the Bound element, we extend here <tt>org.eventb.ui.prettyprint.DefaultPrettyPrinter</tt> to avoid implementing unused methods from the <tt>IElementPrettyPrinter</tt> interface. In fact, what we need here is only to implement the method <tt>prettyPrint(IInternalElement elt, IInternalElement parent, IPrettyPrintStream ps)</tt>.
+
{{Navigation|Previous= [[Extend_Rodin_database_(How_to_extend_Rodin_Tutorial)|Extend the database]] | Up= [[Plug-in_Tutorial|How to extend Rodin Tutorial (Index)]] | Next= }}
 
 
This method has to check that the handled element is a bound (e.g. instanceof <tt>IBound</tt>) and then display the embedded expression string. We created a dedicated method to append the expression in the pretty print stream, and used the pretty print helpers methods that are provided by <tt>org.eventb.ui.prettyprint.PrettyPrintUtils</tt> using the following static imports :<br>
 
:<tt>import static org.eventb.ui.prettyprint.PrettyPrintUtils.getHTMLBeginForCSSClass;</tt>
 
:<tt>import static org.eventb.ui.prettyprint.PrettyPrintUtils.getHTMLEndForCSSClass;</tt>
 
:<tt>import static org.eventb.ui.prettyprint.PrettyPrintUtils.wrapString;</tt>
 
 
 
The only trick here, was to use the same display as the one used by variants using <tt>private static final String BOUND_EXPRESSION = "variantExpression";</tt>. Doing so, we reuse the CSS class that is defined for variant expressions. There are many pre-defined CSS classes for the Event-B language elements. To review them, go to the file <tt>html/style.css</tt> in the plugin <tt>org.eventb.ui</tt>.
 
 
 
Here is the result you should get :
 
 
 
[[Image:Extend_Rodin_Tuto_1_12_PrettyPrint_for_BoundElement.png|400px]]
 
 
 
{{Navigation|Previous= [[Extending_the_Rodin_Event-B_Explorer_(How_to_extend_Rodin_Tutorial)|Adding elements to the Event-B explorer]]| Next=[[Providing_help_for_your_plug-in_(How_to_extend_Rodin_Tutorial)|Providing help]] | 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]]

Revision as of 17:29, 19 August 2010

In this part

We will use the extension points provided by the plugin org.eventb.ui to add our Probabilistic Attribute on events and the Bound Element to the Structured Editor.

Step 1

To structure a bit our development, we will separate the UI from the business layer.
1. Create a new plugin (here fr.systerel.rodinextension.sample.ui, and this time, select "This plug-in will make contributions to the UI" as it will be indeed the case here.
2. Add our business plugin (fr.systerel.rodinextension.sample) to the dependencies as well as org.eventb.ui that provides the extensions points we want to use.

Step 2

1. Add the extension point org.eventb.ui.editorItems At this point, we will start to add our extensions to the structured editor.

Step 3

First, let's add the probabilistic attribute to Event-B events.
The probabilistic attribute can have two values : 'standard' (by default) and 'probabilistic'. Thus we need to create a 'choiceAttribute' extension. Create a new 'choice attibute' extension :
1. give a unique ID to identify this attribute in the UI plugin (such as fr.systerel.rodinextension.sample.ui.probabilistic),
2. in typeID, give the ID reference of the probabilistic attribute in our business plugin (here fr.systerel.rodinextension.sample.probabilistic),
3. create a class (using Eclipse assist, see Step4) to manipulate this attribute, this class should implements the interface org.eventb.ui.IAttributeManipulation.

This class should be implemented the following :
Before doing any manipulation on
1. getPossibleValues() should return an array of two constant values : 'standard' and 'probabilistic',
2. // FIXME Continue here.