<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Eclipse RCP Blog]]></title><description><![CDATA[Yet another blog for Eclipse RCP topics, like good Eclipse RCP architecture, software architecture control, ... ]]></description><link>https://rage5474.github.io</link><generator>RSS for Node</generator><lastBuildDate>Sun, 11 Nov 2018 07:20:20 GMT</lastBuildDate><atom:link href="https://rage5474.github.io/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Eclipse Scripting Basics (EASE)]]></title><description><![CDATA[<div class="sect1">
<h2 id="_motivation">Motivation</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Last time I thought that I would be nice to evaluate automated the output of an application started by Eclipse. E.g. to get an error dialog message when an exception is thrown or at least see an log entry in the Error Log View. Then I thought I would be nice to enable the Eclipse User to write directly a script in Eclipse that evaluates the console output directy. We implemented a similar approach in our Eclipse RCP based application at Elektrobit. After a few minutes searching the internet I found the Eclipse project EASE, that is enabling scripting for Eclipse. But I found not that much tutorials for that and that&#8217;s why I want to blog about it.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_installation">Installation</h2>
<div class="sectionbody">
<div class="paragraph">
<p>I tested the installation with a clean Neon (Version 2) Eclipse. The download links for EASE can be found hier <a href="http://www.eclipse.org/ease/download/" class="bare">http://www.eclipse.org/ease/download/</a> .</p>
</div>
<div class="paragraph">
<p>Installation is as usual:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Start Eclipse</p>
</li>
<li>
<p><strong>Help</strong> &#8594; <strong>Install New Software&#8230;&#8203;</strong></p>
</li>
<li>
<p>Enter following address in the <strong>Work with</strong> field:</p>
<div class="ulist">
<ul>
<li>
<p><a href="http://download.eclipse.org/ease/update/release" class="bare">http://download.eclipse.org/ease/update/release</a> (Current release 0.4.0)</p>
</li>
</ul>
</div>
</li>
<li>
<p>Check all features and click <strong>Next</strong> and</p>
</li>
<li>
<p>again <strong>Next</strong> and</p>
</li>
<li>
<p>accept licenses and click <strong>Finish</strong> and</p>
</li>
<li>
<p>accept warning dialog and</p>
</li>
<li>
<p>restart Eclipse after installation has finished.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_basic_usage">Basic usage</h2>
<div class="sectionbody">
<div class="paragraph">
<p>There is a special perspective for scripting, to activate it simple click <strong>CTRL-3</strong> for <strong>Quick Access</strong> and type scripting
and select select <strong>Scripting</strong> from the <strong>Perspective</strong> section.</p>
</div>
<div class="paragraph">
<p>After the perspective switch your Eclipse should look like this:</p>
</div>
<div class="paragraph">
<p><span class="image"><a class="image" href="/images/ease/01-ease-scripting-view.png"><img src="https://rage5474.github.io/images/ease/01-ease-scripting-view.png" alt="01 ease scripting view.png" width="500"></a></span></p>
</div>
<div class="paragraph">
<p>You can see three important views in this perspective, the Script Explorer, Script Shell, and the Module Explorer.</p>
</div>
<div class="sect2">
<h3 id="_script_shell">Script Shell</h3>
<div class="paragraph">
<p>The easiest way to play around with EASE is to use the Script Shell. This is an interpreter for different scripting languages. Default script engine is Rhino (JavaScript). Following picture explains main features of the script shell.</p>
</div>
<div class="paragraph">
<p><span class="image"><a class="image" href="/images/ease/02-ease-script-shell.png"><img src="https://rage5474.github.io/images/ease/02-ease-script-shell.png" alt="02 ease script shell.png" width="800"></a></span></p>
</div>
<div class="literalblock">
<div class="content">
<pre> (1) Enter your script commands here (Script Input Field, e.g. print("Hello World.")).
 (2) Entered commands and results can be found here (Script Console).
 (3) Start here script recording, toggle button again to save your commands to a script file.
 (4) Load modules by mouse.
 (5) Clear Script Console (is not resetting script engine)
 (6) Hide Variable area.
 (7) Switch script engine(e.g from JavaScript to Python)
 (8) Reset script engine.
 (9) Open an additional script engine.
(10) Open help.</pre>
</div>
</div>
<div class="paragraph">
<p>Script shell is nice to play, but in the most cases people want to write script to re-use them.</p>
</div>
</div>
<div class="sect2">
<h3 id="_create_a_script">Create a script</h3>
<div class="paragraph">
<p>Let us start with a HelloWorld script. Writting a script is easy. Just create a General Project in your Project Explorer.</p>
</div>
<div class="ulist">
<ul>
<li>
<p><strong>File</strong> &#8594; <strong>New</strong> &#8594; <strong>Project&#8230;&#8203;</strong></p>
</li>
<li>
<p>Select <strong>Project</strong> (Section <strong>General</strong>) and click <strong>Next</strong></p>
</li>
<li>
<p>Enter a name and click <strong>Finish</strong></p>
</li>
<li>
<p>Select the new project in your Project Explorer and open context menu</p>
</li>
<li>
<p><strong>New</strong> &#8594; <strong>File</strong></p>
</li>
<li>
<p>Enter file name with extension, e.g. <strong>js</strong></p>
</li>
<li>
<p>Open script and enter print("Hello World") to the script file and save file.</p>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="_run_a_script_with_run_as">Run a script with Run as</h3>
<div class="ulist">
<ul>
<li>
<p>Select created script and open context-menu</p>
</li>
<li>
<p><strong>Run as&#8230;&#8203;</strong> &#8594; <strong>EASE Script</strong></p>
</li>
<li>
<p>Hello World should be printed at the console.</p>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="_run_a_script_with_script_explorer">Run a script with Script Explorer</h3>
<div class="paragraph">
<p>There is a second possibilty to run scripts. Therefore exists a separate view call <strong>Script Explorer</strong>.
To get a script visible in the script explorer it has to be registered via scripting preferences.</p>
</div>
<div class="paragraph">
<p>To activate our HelloWorld script for the Script Explorer do following:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><strong>Window</strong> &#8594; <strong>Preferences</strong></p>
</li>
<li>
<p><strong>Scripting</strong> &#8594; <strong>Script Locations</strong></p>
</li>
<li>
<p>Click <strong>Add Workspace&#8230;&#8203;</strong> and select your project.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>After that your script should be visible in the Script Explorer. The overall picture show look like this now:
<span class="image"><a class="image" href="/images/ease/03-ease-script-explorer.png"><img src="https://rage5474.github.io/images/ease/03-ease-script-explorer.png" alt="03 ease script explorer.png" width="500"></a></span></p>
</div>
<div class="paragraph">
<p>Script Explorer has four different actions:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Run a script</p>
</li>
<li>
<p>Edit a script</p>
</li>
<li>
<p>Reload repository and (only via button)</p>
</li>
<li>
<p>Rename a script (only via context-menu)</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Run, edit, and rename a script is pretty clear. Reload repository is useful, if a script was added to a registered repository (means here a registered script location) outside of Eclipse. To become all script visible trigger it by this button.</p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_conlusion">Conlusion</h2>
<div class="sectionbody">
<div class="paragraph">
<p>So now all should be able to play around with EASE. Next time I will show how to write more cool scripts.</p>
</div>
</div>
</div>]]></description><link>https://rage5474.github.io/2017/01/08/Eclipse-Scripting-Basics-EASE.html</link><guid isPermaLink="true">https://rage5474.github.io/2017/01/08/Eclipse-Scripting-Basics-EASE.html</guid><category><![CDATA[Eclipse]]></category><category><![CDATA[Raphael Geissler]]></category><category><![CDATA[Scripting]]></category><category><![CDATA[EASE]]></category><pubDate>Sun, 08 Jan 2017 00:00:00 GMT</pubDate></item><item><title><![CDATA[Eclipse RCP 3.x with Compatibility Layer]]></title><description><![CDATA[<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>Today I want to show a step-by-step tutorial how to build a simple Eclipse RCP 3.x application based on Eclipse Mars.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_motivation">Motivation</h2>
<div class="sectionbody">
<div class="ulist">
<ul>
<li>
<p>There exists many Eclipse RCP 3.x applications, which cannot be moved to the latest Eclipse RCP version.</p>
</li>
<li>
<p>There are a few descriptions in the internet what must be done to use the Compatibility Layer, but no step-by-step tutorial</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_background">Background</h2>
<div class="sectionbody">
<div class="ulist">
<ul>
<li>
<p>If you not know what the compatibility layer is than read this <a href="https://www.eclipse.org/community/eclipse_newsletter/2013/february/article3.php" class="bare">https://www.eclipse.org/community/eclipse_newsletter/2013/february/article3.php</a></p>
</li>
<li>
<p>If you want more background information about migrating strategies of Eclipse RCP 3.x than read this <a href="http://eclipsesource.com/blogs/2016/01/08/migrating-from-eclipse-3-x-to-eclipse-4-e4/" class="bare">http://eclipsesource.com/blogs/2016/01/08/migrating-from-eclipse-3-x-to-eclipse-4-e4/</a></p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_prerequisite">Prerequisite</h2>
<div class="sectionbody">
<div class="ulist">
<ul>
<li>
<p>Download Eclipse RCP and RAP for Mars from here <a href="http://www.eclipse.org/downloads/packages/eclipse-rcp-and-rap-developers/mars2" class="bare">http://www.eclipse.org/downloads/packages/eclipse-rcp-and-rap-developers/mars2</a></p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_tutorial">Tutorial</h2>
<div class="sectionbody">
<div class="paragraph">
<p>To create a simple feature-based Eclipse RCP 3.x application we need for plug-ins:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>One plug-in with UI logic (here only an example table): <em>io.rage5474.rcp.example.ui.plugin</em></p>
</li>
<li>
<p>One feature plug-in with represents the feature for the UI plug-in(s): <em>io.rage5474.rcp.example.ui.feature</em></p>
</li>
<li>
<p>One target platform plug-in, which contains only the taegt platform file: <em>io.rage5474.rcp.example.tp</em></p>
</li>
<li>
<p>One product plug-in, which contains the product configuration: <em>io.rage5474.rcp.example.product</em></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>So let us start.</p>
</div>
<div class="sect2">
<h3 id="_create_sample_plug_in">Create sample plug-in</h3>
<div class="paragraph">
<p>First we create the plug-in <em>io.rage5474.rcp.example.ui.plugin</em> with our simple application logic. Therefore we use the integrated plug-in generator. Go to <strong>File &#8594; New &#8594; Other</strong> and select <strong>Plug-in Project</strong> from the folder <strong>Plug-in Development</strong>.</p>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-1.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-1.png" alt="comp layer tut 1.png" width="500"></a>
</div>
</div>
<div class="paragraph">
<p>After clicking <strong>Next</strong> you have to add your plug-in name, here <em>io.rage5474.rcp.example.ui.plugin</em>.</p>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-2.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-2.png" alt="comp layer tut 2.png" width="500"></a>
</div>
</div>
<div class="paragraph">
<p>After clicking <strong>Next</strong> we have to select the option <strong>Would you like to create a rich client application?</strong> to <strong>Yes</strong>.</p>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-3.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-3.png" alt="comp layer tut 3.png" width="500"></a>
</div>
</div>
<div class="paragraph">
<p>Again a click on <strong>Next</strong> leads us to the plug-in generator. Select here <strong>RCP 3.x application with a view</strong></p>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-4.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-4.png" alt="comp layer tut 4.png" width="500"></a>
</div>
</div>
<div class="paragraph">
<p>and <strong>Finish</strong> the dialog. In the end you should have a new plug-in in your workspace, that looks similar to this one:</p>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-5.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-5.png" alt="comp layer tut 5.png" width="1024"></a>
</div>
</div>
<div class="paragraph">
<p>Cool, first step was successful. Let us go on.</p>
</div>
</div>
<div class="sect2">
<h3 id="_create_sample_feature">Create sample feature</h3>
<div class="paragraph">
<p>As I think it is better to work with feature (groups of plug-ins) instead of working only with plug-ins, we have to create a feature plug-in, that contains in the end only one plug-in. We name the feature plug-in <em>io.rage5474.rcp.example.ui.feature</em>.</p>
</div>
<div class="paragraph">
<p>So start again with <strong>File &#8594; New &#8594; Other</strong> and select <strong>Feature Project</strong> from the folder <strong>Plug-in Development</strong>. Enter the feature name <em>io.rage5474.rcp.example.ui.feature</em> and click <strong>Finish</strong>.</p>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-6.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-6.png" alt="comp layer tut 6.png" width="500"></a>
</div>
</div>
<div class="paragraph">
<p>Now you should have a second plug-in in your workspace. Open the file <em>feature.xml</em> (simply be double-click), which is located in <em>io.rage5474.rcp.example.ui.feature</em>. Go to the tab <em>Included Plug-ins</em> on the bottom of the editor and click <strong>Add</strong>. A new window should come up. Select the plug-in with the name <em>io.rage5474.rcp.example.ui.plugin</em> and click <strong>OK</strong>.</p>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-7.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-7.png" alt="comp layer tut 7.png" width="1024"></a>
</div>
</div>
<div class="paragraph">
<p>Save the <em>feature.xml</em> file (<em>CTRL-S</em>).</p>
</div>
<div class="paragraph">
<p>So step 2 was also successful!</p>
</div>
</div>
<div class="sect2">
<h3 id="_create_target_platform_plug_in">Create target platform plug-in</h3>
<div class="paragraph">
<p>Now we must create our target-platform (contains all Eclipse RCP plug-ins we need to get our application running!). I decided to use here Eclipse Mars as target platform. So we put the target platform file in a separate plug-in. We start again with <strong>File &#8594; New &#8594; Other</strong> and select <strong>Project</strong> from the folder <strong>General</strong>. Enter the corresponding plug-in name, here <em>io.rage5474.rcp.example.tp</em> and click <strong>Finish</strong>.</p>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-8.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-8.png" alt="comp layer tut 8.png" width="500"></a>
</div>
</div>
<div class="paragraph">
<p>Now we add a Target Definition file to this project. Go to <strong>File &#8594; New &#8594; Other</strong> and select <strong>Target Definition</strong> from the folder <strong>Plug-in Development</strong> and click <strong>Next</strong>.</p>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-9.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-9.png" alt="comp layer tut 9.png" width="500"></a>
</div>
</div>
<div class="paragraph">
<p>Now select the our target platform plug-in <em>io.rage5474.rcp.example.tp</em>, add <em>mars.target</em> as <strong>File name</strong> and select the option <strong>Nothing</strong> from the section <strong>Initialize the target definition with:</strong> and click <strong>Finish</strong>.</p>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-10.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-10.png" alt="comp layer tut 10.png" width="500"></a>
</div>
</div>
<div class="paragraph">
<p>Now we have our third plug-in. At the moment our Target Definition file is empty. So open it with a double-click on the file <em>mars.target</em> and click the <strong>Add</strong> button to add a Software Site to this Target Definition.</p>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-11.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-11.png" alt="comp layer tut 11.png" width="1024"></a>
</div>
</div>
<div class="paragraph">
<p>Select <strong>Software Site</strong> and click <strong>Next</strong>.</p>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-12.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-12.png" alt="comp layer tut 12.png" width="500"></a>
</div>
</div>
<div class="paragraph">
<p>Enter following URL in the field <strong>Work with</strong> and hit enter: <em><a href="http://download.eclipse.org/releases/mars" class="bare">http://download.eclipse.org/releases/mars</a></em> .
Search and select following three features:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Eclipse RCP</p>
</li>
<li>
<p>Equinox p2, minimal support for RCP applications</p>
</li>
<li>
<p>Eclipse Platform Launcher Executables</p>
</li>
</ul>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-13.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-13.png" alt="comp layer tut 13.png" width="500"></a>
</div>
</div>
<div class="paragraph">
<p>Use the search field to find the right feature fast. Tip: Disable <strong>Group by Category</strong>.</p>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-14.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-14.png" alt="comp layer tut 14.png" width="500"></a>
</div>
</div>
<div class="paragraph">
<p>Click on <strong>Finish</strong> and click <strong>Set as Target Platform</strong>. After a while the target platform should be available.</p>
</div>
</div>
<div class="sect2">
<h3 id="_create_sample_product">Create sample product</h3>
<div class="paragraph">
<p>So we almost finished. We only need the possibility to start our application, therefore we need a product file.
We separate this again in a new plug-in. We start again with <strong>File &#8594; New &#8594; Other</strong> and select <strong>Project</strong> from the folder <strong>General</strong> and enter the plug-ins name <em>io.rage5474.rcp.example.product</em> and click <strong>Finish</strong>.</p>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-15.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-15.png" alt="comp layer tut 15.png" width="500"></a>
</div>
</div>
<div class="paragraph">
<p>Now we have to add a <strong>Product Configuration</strong> file to that plug-in. We create this with <strong>File &#8594; New &#8594; Other</strong> and select <strong>Product Configuration</strong> from the folder <strong>Plug-in Development</strong> and click <strong>Next</strong>.</p>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-16.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-16.png" alt="comp layer tut 16.png" width="500"></a>
</div>
</div>
<div class="paragraph">
<p>Select the right plug-in (<em>io.rage5474.rcp.example.product</em>) and enter a product configuration file name, here <em>example.product</em> and click Finish.</p>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-17.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-17.png" alt="comp layer tut 17.png" width="500"></a>
</div>
</div>
<div class="paragraph">
<p>Now we have to configure our product. Open the product file (<em>example.product</em>) by double clicking. Click on new and select the plug-in <em>io.rage5474.rcp.example.ui.plugin</em> in the field <strong>Defining Plug-in</strong> and enter a <strong>Product ID</strong>, e.g. <em>rcp_product</em>. Before clicking <strong>Finish</strong> switch the toogle button from <strong>plug-ins</strong> to <strong>features</strong>.</p>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-18.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-18.png" alt="comp layer tut 18.png" width="1024"></a>
</div>
</div>
<div class="paragraph">
<p>Now switch to the tab <strong>Contents</strong> and add following feature by clicking on the <strong>Add</strong> button:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>org.eclipse.rcp</p>
</li>
<li>
<p>org.eclipse.emf.common</p>
</li>
<li>
<p>org.eclipse.emf.ecore</p>
</li>
<li>
<p>io.rage5474.rcp.example.ui.feature</p>
</li>
</ul>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-19.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-19.png" alt="comp layer tut 19.png" width="1024"></a>
</div>
</div>
<div class="paragraph">
<p>Now we have to modify the run configuration. Switch to the tab <strong>Configuration</strong> and select <strong>Add Recommended</strong>.</p>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-20.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-20.png" alt="comp layer tut 20.png" width="1024"></a>
</div>
</div>
<div class="paragraph">
<p>Save your product definition file (<em>CTRL-S</em>) and switch back to the tab <strong>Overview</strong> and click the link <em>Synchronize</em> from the section <strong>Test</strong>.</p>
</div>
</div>
<div class="sect2">
<h3 id="_launch_example_application">Launch example application</h3>
<div class="paragraph">
<p>Now we can give it a try. Click the link <em>Launch an Eclipse Application</em> again from the section <strong>Testing</strong>.
The result should look similar to this:</p>
</div>
<div class="imageblock">
<div class="content">
<a class="image" href="/images/complayer/comp-layer-tut-21.png"><img src="https://rage5474.github.io/images/complayer/comp-layer-tut-21.png" alt="comp layer tut 21.png" width="400"></a>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_source_code">Source Code</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The full example source code can also be found here: <a href="https://github.com/rage5474/rcp.3.x.comp.layer.example" class="bare">https://github.com/rage5474/rcp.3.x.comp.layer.example</a> .</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_references">References</h2>
<div class="sectionbody">
<div class="paragraph">
<p><a href="https://www.eclipse.org/community/eclipse_newsletter/2013/february/article3.php" class="bare">https://www.eclipse.org/community/eclipse_newsletter/2013/february/article3.php</a>
<a href="http://eclipsesource.com/blogs/2016/01/08/migrating-from-eclipse-3-x-to-eclipse-4-e4/" class="bare">http://eclipsesource.com/blogs/2016/01/08/migrating-from-eclipse-3-x-to-eclipse-4-e4/</a>
<a href="http://www.vogella.com/tutorials/Eclipse4MigrationGuide/article.html" class="bare">http://www.vogella.com/tutorials/Eclipse4MigrationGuide/article.html</a></p>
</div>
</div>
</div>]]></description><link>https://rage5474.github.io/2016/09/19/Eclipse-RCP-3x-with-Compatibility-Layer.html</link><guid isPermaLink="true">https://rage5474.github.io/2016/09/19/Eclipse-RCP-3x-with-Compatibility-Layer.html</guid><category><![CDATA[Eclipse]]></category><category><![CDATA[RCP]]></category><category><![CDATA[Raphael Geissler]]></category><category><![CDATA[3.x]]></category><category><![CDATA[Compatibility Layer]]></category><pubDate>Mon, 19 Sep 2016 00:00:00 GMT</pubDate></item><item><title><![CDATA[Declarative Annotations in Eclipse Neon]]></title><description><![CDATA[<div class="sect1">
<h2 id="_motivation">Motivation</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Many Eclipse RCP applications are using OSGi Services make their application leightweight and flexible. The most convient method is to use OSGi Services in combination with Declarative Services. This allows to specifiy OSGi Services by XML files. Why this can be quite convient can be found here <a href="http://www.vogella.com/tutorials/OSGiServices/article.html#declarativeservices">DS@Vogella</a>.
Before Eclipse Neon there were two possibilties to create or modify these XML files.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>By Hand - Disadvantage: Error prone.</p>
</li>
<li>
<p>Integration editor - Disadvantages: Error prone on re-factoring, no consistent naming scheme.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>No Eclipse Neon integrated a third solution: Generation of XML files by code annotations. In this blog I want to show more detailled how this can work.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_code_example">Code Example</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Expecting a simple HelloWorld OSGi application, with</p>
</div>
<div class="ulist">
<ul>
<li>
<p>a HelloWorldService and</p>
</li>
<li>
<p>a HelloWorldClient.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The HelloWorldService is exporting following simple interface.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-java" data-lang="java">package my.osgi.ds.example.helloservice.api;

public interface HelloWorldService {
    // Prints 'Hello + name' to the console
    public void sayHello(String name);
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Whenever <code>sayHello</code> is called 'Hello + name' is printed on the console.</p>
</div>
<div class="paragraph">
<p>Here is the corresponding implementation of this OSGi Service. So the implementation is quite straight forward.
Now let us come to the interesting part of this class - the <code>@Component</code> DS Annotations.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-java" data-lang="java">package my.osgi.ds.example.helloservice.impl;

import org.osgi.service.component.annotations.Component;
import my.osgi.ds.example.helloservice.api.HelloWorldService;

@Component
public class HelloWorldServiceImpl implements HelloWorldService {

	@Override
	public void sayHello(String name) {
		System.out.println(("Hello " + name + "!"));
	}

}</code></pre>
</div>
</div>
<div class="paragraph">
<p>To register a class as OSGi-Service (Component is used here as synonym) just use <code>@Component</code> as class annotation. That&#8217;s the minimum to register a class as OSGi service. Whenever you save this class, automatically a new XML file <code>my.osgi.ds.example.helloservice.impl.HelloWorldServiceImpl.xml</code> will be generated <code>OSGI-INF</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="my.osgi.ds.example.helloservice.impl.HelloWorldServiceImpl"&gt;
   &lt;service&gt;
      &lt;provide interface="my.osgi.ds.example.helloservice.api.HelloWorldService"/&gt;
   &lt;/service&gt;
   &lt;implementation class="my.osgi.ds.example.helloservice.impl.HelloWorldServiceImpl"/&gt;
&lt;/scr:component&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>So in the most cases this should be enough. Look&#8217;s quite easy.</p>
</div>
<div class="paragraph">
<p>Let us have a look on the <code>HelloWorldClientImpl</code>. It&#8217;s the service that is using our <code>HelloWorldService</code>.
At first it has to become also a OSGi service. So <code>@Component`annotation is needed. Then we need the reference to the `HelloWorldService</code>. This is done by a method, which is annotated by <code>@Reference</code>. But here its also a special parameter <code>unbind</code> needed, which also points to the unbind method. So the <code>@Reference</code> method is used inject the <code>HelloWorldService</code> to the <code>HelloWorldClientImpl</code>. In case you have multiple <code>@Reference</code> methods, you should use the <code>@Activate</code> method to start your component. Otherwise it&#8217;s not guaranteed, that all service references were already injected.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-java" data-lang="java">package my.osgi.ds.example.helloclient.impl;

import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;

import my.osgi.ds.example.helloservice.api.HelloWorldService;

@Component
public class HelloWorldClientImpl {
	private HelloWorldService helloWorldService;

	@Reference(unbind = "unbind")
	public void bind(HelloWorldService helloWorldService) {
		this.helloWorldService = helloWorldService;
	}

	@Activate
	public void start() {
		helloWorldService.sayHello("Mr. X");
	}

	public void unbind(HelloWorldService helloWorldService) {
		this.helloWorldService = null;
	}

	@Deactivate
	public void stop() {
		this.helloWorldService = null;
	}
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Again a XML file <code>my.osgi.ds.example.helloclient.impl.HelloWorldClientImpl.xml</code> is generated in the folder <code>OSGI-INF</code>.</p>
</div>
<div class="paragraph">
<p>Content looks like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
	activate="start"
	deactivate="stop"
	name="my.osgi.ds.example.helloclient.impl.HelloWorldClientImpl"&gt;
    &lt;reference
   	bind="bind"
        cardinality="1..1"
        interface="my.osgi.ds.example.helloservice.api.HelloWorldService"
        policy="static"
        unbind="unbind"/&gt;
   &lt;implementation class="my.osgi.ds.example.helloclient.impl.HelloWorldClientImpl"/&gt;
&lt;/scr:component&gt;</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_advantages">Advantages</h2>
<div class="sectionbody">
<div class="ulist">
<ul>
<li>
<p>Naming scheme of XML files are always the same.</p>
</li>
<li>
<p>Usability is trivial.</p>
</li>
<li>
<p>Annoations can be easily used for byte code generated traces (I will write another post for this topic!).</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_try_it_out">Try it out</h2>
<div class="sectionbody">
<div class="paragraph">
<p>A full example can be found here: <a href="https://github.com/rage5474/rcp.examples/tree/master/ds.annotation.example/my.osgi.ds.example">ds.annotation.example@github</a>.</p>
</div>
</div>
</div>]]></description><link>https://rage5474.github.io/2016/08/29/Declarative-Annotations-in-Eclipse-Neon.html</link><guid isPermaLink="true">https://rage5474.github.io/2016/08/29/Declarative-Annotations-in-Eclipse-Neon.html</guid><category><![CDATA[Eclipse]]></category><category><![CDATA[RCP]]></category><category><![CDATA[Raphael Geissler]]></category><category><![CDATA[OSGi]]></category><category><![CDATA[Declarative Annotations]]></category><category><![CDATA[Eclipse Neon]]></category><pubDate>Mon, 29 Aug 2016 00:00:00 GMT</pubDate></item></channel></rss>