<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TechJava &#187; TechJava &#8211; Articles tagged by rcp</title>
	<atom:link href="http://www.techjava.de/topics/tag/rcp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.techjava.de</link>
	<description>Journal on Java Technology</description>
	<lastBuildDate>Wed, 11 May 2011 21:15:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Launching Eclipse RCP via Java Web Start</title>
		<link>http://www.techjava.de/topics/2010/02/launching-rcp-via-jws/</link>
		<comments>http://www.techjava.de/topics/2010/02/launching-rcp-via-jws/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 16:32:15 +0000</pubDate>
		<dc:creator>Simon Zambrovski</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Enterprise Systems]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Application id not found]]></category>
		<category><![CDATA[bundle]]></category>
		<category><![CDATA[delivery]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[Java Web Start]]></category>
		<category><![CDATA[JNLP]]></category>
		<category><![CDATA[JWS]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[packaging]]></category>
		<category><![CDATA[rcp]]></category>

		<guid isPermaLink="false">http://www.techjava.de/?p=582</guid>
		<description><![CDATA[The Eclipse RCP became a prominent platform for building client software. One of the delivery mechanisms supported by Eclipse RCP is Sun&#8217;s Java Web Start (JWS). Since Galileo Edition some changes has been introduced in the platform. This article provides some hints for creation of the RCP delivered by Java Web Start. Packaging In order [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.techjava.de/wp-content/uploads/eclipse-rcp.png" alt="" title="eclipse-rcp" width="237" height="237" style="float:right; margin:5px" />The Eclipse RCP became a prominent platform for building client software. One of the delivery mechanisms supported by Eclipse RCP is Sun&#8217;s Java Web Start (JWS). Since Galileo Edition some changes has been introduced in the platform. This article provides some hints for creation of the RCP delivered by Java Web Start.</p>
<h2>Packaging</h2>
<p>In order to package the RCP I suggest to use feature-based products as described in 
<a  href="http://www.techjava.de/topics/2009/07/packaging-eclipse-based-rcp-for-the-use-in-enterprise-context/">a previous article</a>. Following it, you should have a top-level plug-in (also refered as product-defining plug-in) and top-level feature, which is called &#8220;wrap&#8221;-feature in the context of the Java Web Start. </p>
<h3>Exporting the product</h3>
<p>Before you start with Java Web Start (JWS), export the product and make sure it starts as a standalone application. In doing so, you have to ensure that your references to the plug-ins are correct. One of the way of doing it is to hit the Validate button in the top left of the product editor. <img src="http://www.techjava.de/wp-content/uploads/validate-product.png" alt="" title="validate-product" width="196" height="79" style="float:right; margin:5px;" /> If the validation is successful, try to export the product. The PDE builder will run and create a distribution. The errors of the compiler/builder/assembler, if any, are reported to files zipped to the <code>logs.zip</code> file in the distribution directory. <span id="more-582"></span> A prominent error is</p>
<pre class="brush: plain; light: true; title: ;">
Compliance level '1.3' is incompatible with source level '1.6'. A compliance level '1.6' or better is required.
</pre>
<p>Which actually means that the plug-in classes has not been compiled at all. In order to avoid this error make sure to set the following properties in the <code>build.properties</code> file of the corresponding plug-in:</p>
<pre class="brush: plain; light: true; title: ;">
javacSource=1.3
javacTarget=1.3
</pre>
<h3>Exporting the wrap-feature</h3>
<p>After a successful export of the product, just export the top-level feature (the wrap-feature). Make sure to provide the signing information, since JWS requires all resources to be signed. If you are aiming to deliver for different platforms, make sure to define a target platform (<strong>Window > Preferences > Plug-in Development > Target Platform</strong>) which contains a Delta Pack. A Delta Pack is a set of plug-ins which can be downloaded separately on the 
<a  href="http://ww.eclipse.org/downloads/" onclick="javascript:pageTracker._trackPageview('/external/ww.eclipse.org/downloads/');" >Eclipse Homepage</a>. Also, don&#8217;t forget to switch over to the Java Web Start tab of the Feature Export Wizard, activate the checkbox &#8220;Create JNLP manifest for the JAR archives&#8221; and specify the site URL where the resulting JNLP will be located. Make sure all your features has the provider attribute set, since it is used as the &#8220;vendor&#8221; inside of the JNLP file, which is a mandatory attribute.</p>
<h3>Creating the main JNLP</h3>
<p>The PDE build will run and create a distribution in the specified directory. Along with the exported JARs in features and plug-ins, the packaging script will generate the JNLP descriptors for every feature. Still, the main JNLP file required for launching the application is missing and has to be provided separately. Here is, how it looks like:</p>
<pre class="brush: xml; title: ;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;jnlp spec=&quot;1.0+&quot; codebase=&quot;http://localhost/app/&quot; href=&quot;app.jnlp&quot;&gt;
    &lt;information&gt;
        &lt;title&gt;application titel&lt;/title&gt;
        &lt;vendor&gt;provider&lt;/vendor&gt;
        &lt;offline-allowed/&gt;
    &lt;/information&gt;

    &lt;security&gt;
        &lt;all-permissions/&gt;
    &lt;/security&gt;

    &lt;application-desc main-class=&quot;org.eclipse.equinox.launcher.WebStartMain&quot;&gt;
	&lt;argument&gt;-product&lt;/argument&gt;
	&lt;argument&gt;de.techjava.app.webstart.productid&lt;/argument&gt;
	&lt;argument&gt;-application&lt;/argument&gt;
	&lt;argument&gt;de.techjava.app.webstart.appid&lt;/argument&gt;
    &lt;/application-desc&gt;

    &lt;resources&gt;
        &lt;j2se version=&quot;1.4+&quot; ax-heap-size=&quot;128m&quot; /&gt;
	&lt;jar href=&quot;plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar&quot;/&gt;
	&lt;extension name=&quot;wrap feature&quot; href=&quot;features/wrap_feature_1.0.0.jnlp&quot; /&gt;
	&lt;!-- OSGI setup --&gt;
        &lt;property name=&quot;osgi.instance.area&quot; value=&quot;@user.home/app&quot;/&gt;
        &lt;property name=&quot;osgi.configuration.area&quot; value=&quot;@user.home/app&quot;/&gt;
    &lt;/resources&gt;
&lt;/jnlp&gt;
</pre>
<p>Important is to specify both, the <strong>product id</strong> and the <strong>applciation id</strong>, otherwise you will see the &#8220;Application id not found&#8221; exception. Of course you can specify 
<a  href="http://help.eclipse.org/galileo/topic/org.eclipse.platform.doc.isv/reference/misc/runtime-options.html" onclick="javascript:pageTracker._trackPageview('/external/help.eclipse.org/galileo/topic/org.eclipse.platform.doc.isv/reference/misc/runtime-options.html');" >additional options</a> as command-line arguments of the launcher itself. I found it useful to be able to let the OSGi running and then connect to it and query for loaded bundles. You can do it by adding the following arguments:</p>
<pre class="brush: xml; title: ;">
	&lt;argument&gt;-console&lt;/argument&gt;
	&lt;argument&gt;1234&lt;/argument&gt;
	&lt;argument&gt;-noExit&lt;/argument&gt;
</pre>
<p>This will allow to connect via telnet with running OSGi, even after the application finishes.<br />
This is basically it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techjava.de/topics/2010/02/launching-rcp-via-jws/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Eclipse CNF: Navigator Content Extensions</title>
		<link>http://www.techjava.de/topics/2009/08/eclipse-common-navigator-framework-2/</link>
		<comments>http://www.techjava.de/topics/2009/08/eclipse-common-navigator-framework-2/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 20:55:11 +0000</pubDate>
		<dc:creator>Simon Zambrovski</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[cnf]]></category>
		<category><![CDATA[common navigator framework]]></category>
		<category><![CDATA[navigator content extension]]></category>
		<category><![CDATA[NCE]]></category>
		<category><![CDATA[plug-in]]></category>
		<category><![CDATA[rcp]]></category>

		<guid isPermaLink="false">http://www.techjava.de/?p=471</guid>
		<description><![CDATA[Abstract After providing the basic example of how the Eclipse Common Navigator Framework (CNF) can be used to display custom content, this article focuses on the main feature of the CNF &#8211; the contribution of content to the same navigator by several independent plug-ins. First of all, I will explain some minor changes introduced to [...]]]></description>
			<content:encoded><![CDATA[<h2>Abstract</h2>
<p><img class="alignnone size-thumbnail wp-image-501" style="float:right; margin:10px;" title="compass" src="http://www.techjava.de/wp-content/uploads/compass2-150x150.jpg" alt="compass" width="150" height="150" /> After 
<a  href="http://www.techjava.de/topics/2009/04/eclipse-common-navigator-framework/">providing the basic example</a> of how the Eclipse Common Navigator Framework (CNF) can be used to display custom content, this article focuses on the main feature of the CNF &#8211; the contribution of content to the same navigator by several independent plug-ins. First of all, I will explain some minor changes introduced to the CNF in the Gallileo Edition, then I will focus on the content itself and finally provide an overview of how the action contributions can be provided. In the end of the post, some ideas on control of dynamic content are explained.</p>
<h2>Gallileo Changes</h2>
<p>There are two noticeable changes in the CNF that have been added with 
<a  href="http://www.techjava.de/topics/2009/06/galileo-has-arrived/">Eclipse Galileo</a>. The return type of the method <span id="more-471"></span><code>CommonNavigator#getInitialInput()</code> has been changed to <code>Object</code> (which is important for the RCP usage of the CNF) and the call of the method <code>org.eclipse.ui.internal.ide.model.WorkbenchAdapterBuilder#registerAdapters()</code> has been replaced by the <code>org.eclipse.ui.ide.IDE.registerAdapters();</code> which should be executed in the <code>initialize</code> method of the <code>ApplicationWorkbenchAdvisor</code> of your RCP if you are using resources with the CNF.</p>
<pre class="brush: java; title: ;">
public class CommonNavigator ...
{
  /**
   * Used to provide the initial input for the {@link CommonViewer}.
   * By default getSite().getPage().getInput() is used.
   * Subclass this to return your desired input.
   * @return The initial input for the viewer.
   * Defaults to getSite().getPage().getInput()
   * @since 3.4
   */
  protected Object getInitialInput() {...}
}
</pre>
<h2>Content contribution</h2>
<p>The main advantage of the use of the CNF over a simple tree view is the ability to contribute content to the view from several plug-ins. Thus, the plug-in that contains the view does not depend on the contributing plug-ins. If you are not familiar with the CNF, please review the 
<a  href="http://www.techjava.de/topics/2009/04/eclipse-common-navigator-framework/">previous post</a>, since the example provided there will be extended. The data model used previously will be extended by an additional layer: along with parents and children, the pets are introduced. Let&#8217;s assume that pets are owned by children.</p>
<pre class="brush: java; title: ;">
/**
 * Represents a pet
 * @author Simon Zambrovski
 */
public class Pet
{
    private String name;
    private Child owner;

    public Pet(String name, Child owner)
    {
        super();
        this.name = name;
        this.owner = owner;
    }
    ...
    // getter and setter
}
</pre>
<p>First of all create a new plug-in project called <code>de.techjava.rcp.cnf.subcontent</code>, add a plug-in dependency to the <code>de.techjava.rcp.cnf</code> and to the <code>org.eclipse.ui.navigator</code>. Then add two extensions <code>org.eclipse.ui.navigator.navigatorContent</code> and <code>org.eclipse.ui.navigator.viewer</code>. The first extension defines the new Navigator Content Extension (NCE) and the second one is used to bind it to the existing viewer.</p>
<pre class="brush: xml; title: ;">
   &lt;extension
         point=&quot;org.eclipse.ui.navigator.navigatorContent&quot;&gt;
      &lt;navigatorContent
            activeByDefault=&quot;true&quot;
            contentProvider=&quot;de.techjava.rcp.cnf.subcontent.provider.CNFSubContentProvider&quot;
            id=&quot;de.techjava.rcp.cnf.subcontent.navigatorContent&quot;
            labelProvider=&quot;de.techjava.rcp.cnf.subcontent.provider.CNFSubLabelProvider&quot;
            name=&quot;Sub Content&quot;
            priority=&quot;normal&quot;
            providesSaveables=&quot;false&quot;&gt;
         &lt;enablement&gt;
            &lt;instanceof value=&quot;de.techjava.rcp.cnf.data.Child&quot; /&gt;
         &lt;/enablement&gt;
      &lt;/navigatorContent&gt;
   &lt;/extension&gt;
   &lt;extension
         point=&quot;org.eclipse.ui.handlers&quot;&gt;
      &lt;handler
            class=&quot;de.techjava.rcp.cnf.subcontent.handler.RenameHandler&quot;
            commandId=&quot;org.eclipse.ui.edit.rename&quot;&gt;
         &lt;activeWhen&gt;
            &lt;reference definitionId=&quot;de.techjava.rcp.cnf.subcontent.petSelected&quot; /&gt;
         &lt;/activeWhen&gt;
         &lt;enabledWhen&gt;
            &lt;reference definitionId=&quot;de.techjava.rcp.cnf.subcontent.petSelected&quot;/&gt;
         &lt;/enabledWhen&gt;
      &lt;/handler&gt;
   &lt;/extension&gt;
</pre>
<p>The Sub Content is defined following the same scheme as the content in the previous article of this series.  Its <code>contentProvider</code> and <code>labelProvider</code> attributes point to the corresponding classes. The label provider implementation is straight forward. The content provider has to be able to return a list of children, if the instance of the <code>Child</code>-class is selected in the Navigator. The <code>enablement</code> is defined in this way respectively. An important thing to understand at this point is that the CNF will <strong>join</strong> contributions of all NCEs triggered on the element selection. This means, that even if the NCE of the first plug-in does not provide any children for the <code>Child</code> element, there will be children contributed by the second plug-in&#8217;s content provider. Here is the example content provider, which returns the number of pets depending on the last digit in a child&#8217;s name:</p>
<pre class="brush: java; title: ;">
public class CNFSubContentProvider implements ITreeContentProvider
{
    ...
    public Object[] getChildren(Object parentElement)
    {
        if (parentElement instanceof Child
                &amp;&amp; !(parentElement instanceof Parent))
        {
            Child child = ((Child) parentElement);
            char lastDigit = child.getName().charAt(child.getName().length() - 1);
            if (Character.isDigit(lastDigit))
            {
                int petCount = Integer.parseInt(String.valueOf(lastDigit));
                Pet[] pets = new Pet[petCount];
                for (int i = 0; i &gt; petCount; i++)
                {
                    pets[i] = new Pet(child.getName() + &quot;'s pet &quot; + (i + 1), child);
                }
                return pets;
            }
            return EMPTY_ARRAY;
        } else
        {
            return EMPTY_ARRAY;
        }
    }
    ...
}
</pre>
<p>After this trivial configuration and the inclusion of the new plug-in into the example product, the resulting Navigator should show pets as sub-elements of the child-elements.<br />
<img class="alignnone size-full wp-image-484" title="CNF2" src="http://www.techjava.de/wp-content/uploads/CNF2.png" alt="CNF2" width="400" height="300" /></p>
<h2>Shared commands</h2>
<p>If the Navigator displays content from several plug-ins, the contributed commands should be handled carefully. The commands (contributed to the pop-up menu shown upon right-click on the corresponding item) should appear only on items they belong to. In order to achieve this, let us first look at the standard way of the command contribution. The CNF developer is strongly recommend to use the declarative contribution techniques instead of the Action Contribution Provider. For this purpose, the extension point <code>org.eclipse.ui.navigator.viewer</code> allows to contribute a <code>popupMenu</code> element as a child element of the <code>viewer</code>. The pop-up menu element defines the structure (in terms of separators) of the pop-up menu. There is a standard pop-up menu structure defined, which is default if a user-specific definition is ommited. In the example, the user-specific pop-up menu is defined:</p>
<pre class="brush: xml; title: ;">
   &lt;extension
         point=&quot;org.eclipse.ui.navigator.viewer&quot;&gt;
      &lt;viewer
            viewerId=&quot;de.techjava.rcp.cnf.view&quot;&gt;
         &lt;popupMenu
               allowsPlatformContributions=&quot;true&quot;
               id=&quot;de.techjava.rcp.cnf.view.popup&quot;&gt;
            &lt;insertionPoint
                  name=&quot;group.new&quot;
                  separator=&quot;false&quot;&gt;
            &lt;/insertionPoint&gt;
            &lt;insertionPoint
                  name=&quot;group.open&quot;
                  separator=&quot;false&quot;&gt;
            &lt;/insertionPoint&gt;
            &lt;insertionPoint
                  name=&quot;group.edit&quot;
                  separator=&quot;true&quot;&gt;
            &lt;/insertionPoint&gt;
            ...
         &lt;/popupMenu&gt;
      &lt;/viewer&gt;
      ...
    &lt;/extension&gt;
</pre>
<p>Using the 
<a  href="http://wiki.eclipse.org/index.php/Platform_Command_Framework" onclick="javascript:pageTracker._trackPageview('/external/wiki.eclipse.org/index.php/Platform_Command_Framework');" >Eclipse Command Framework</a>, the commands can be contributed to the defined pop-up menu in the following way. Using the <code>org.eclipse.ui.menus</code> extension point one or several <code>menuContribution</code> elements can be defined. Each menu contribution defines a set of commands, controls, menus, tool bars or dynamic contributions (or any combination) which are added to a specific separator addressed in a special way (see Command Framework Documentation). In this example the set of commands is contributed:</p>
<pre class="brush: xml; title: ;">
   &lt;extension
         point=&quot;org.eclipse.ui.menus&quot;&gt;
      &lt;menuContribution
            locationURI=&quot;popup:de.techjava.rcp.cnf.view.popup?after=group.edit&quot;&gt;
         &lt;command
               commandId=&quot;org.eclipse.ui.edit.delete&quot;
               id=&quot;cnf.popupmenu.delete&quot;
               label=&quot;Delete&quot;
               mnemonic=&quot;D&quot;
               style=&quot;push&quot;&gt;
         &lt;/command&gt;
         &lt;command
               commandId=&quot;org.eclipse.ui.edit.rename&quot;
               id=&quot;cnf.popupmenu.rename&quot;
               label=&quot;Rename&quot;
               mnemonic=&quot;R&quot;
               style=&quot;push&quot;&gt;
         &lt;/command&gt;
      &lt;/menuContribution&gt;
      ....
    &lt;/extension&gt;
</pre>
<p>Please note that the <code>commandId</code> must point to an existing command, which is either user-defined, or defined by the Eclipse platform. A <code>command</code> is an abstraction of a user command which is referenced from the User Interface on one hand and has assigned handlers (which execute the command) on the other hand. The representation of the command is shown in the UI only if a handler is assigned to it. The idea of using shared commands is to have multiple handlers for the same command, which are activated depending on the selected element.</p>
<p>In order to enable and disable handlers in a declarative way, the 
<a  href="http://wiki.eclipse.org/Command_Core_Expressions" onclick="javascript:pageTracker._trackPageview('/external/wiki.eclipse.org/Command_Core_Expressions');" >Eclipse Core Expressions</a> are used. Core expressions can be written in the <code>enabledWhen</code> and <code>activeWhen</code> child elements of the handler definition. The core expressions can also be defined and referenced externally using the <code>org.eclipse.core.expressions.definitions</code> extension point. Here is an example definition of the handler assigned to the Rename command:</p>
<pre class="brush: xml; title: ;">
   &lt;extension
         point=&quot;org.eclipse.ui.handlers&quot;&gt;
      &lt;handler
            class=&quot;de.techjava.rcp.cnf.handler.RenameHandler&quot;
            commandId=&quot;org.eclipse.ui.edit.rename&quot;&gt;
         &lt;activeWhen&gt;
            &lt;reference definitionId=&quot;de.techjava.rcp.cnf.elementSelected&quot; /&gt;
         &lt;/activeWhen&gt;
         &lt;enabledWhen&gt;
            &lt;reference definitionId=&quot;de.techjava.rcp.cnf.elementSelected&quot; /&gt;
         &lt;/enabledWhen&gt;
      &lt;/handler&gt;
   &lt;/extension&gt;
</pre>
<p>The handler is enabled and active if the expression <code>de.techjava.rcp.cnf.elementSelected</code> is triggered. The definition of the expression is as follows. It defines the <code>with</code>-scope on the current selection, <code>iterates</code> over the elements and applies the <code>instance of</code> operator on the elements using the OR-conjunction. In doing so, the expression will trigger if among the currently selected elements is at least one <code>Child</code> element.</p>
<pre class="brush: xml; title: ;">
   &lt;extension
         point=&quot;org.eclipse.core.expressions.definitions&quot;&gt;
      &lt;definition id=&quot;de.techjava.rcp.cnf.elementSelected&quot;&gt;
         &lt;with variable=&quot;selection&quot;&gt;
            &lt;iterate ifEmpty=&quot;false&quot; operator=&quot;or&quot;&gt;
               &lt;instanceof value=&quot;de.techjava.rcp.cnf.data.Child&quot; /&gt;
            &lt;/iterate&gt;
         &lt;/with&gt;
      &lt;/definition&gt;
   &lt;/extension&gt;
</pre>
<p><img class="alignnone size-full wp-image-486" title="CNF2-rename-child" src="http://www.techjava.de/wp-content/uploads/CNF2-rename-child.png" alt="CNF2-rename-child" width="384" height="239" /><br />
In order to use the same action (the Rename item of the pop-up menu) in the Pet plug-in, the handler enabled on the Pet element has to be provided. The code is analogous to the code before:</p>
<pre class="brush: xml; title: ;">
   &lt;extension
         point=&quot;org.eclipse.ui.handlers&quot;&gt;
      &lt;handler
            class=&quot;de.techjava.rcp.cnf.subcontent.handler.RenameHandler&quot;
            commandId=&quot;org.eclipse.ui.edit.rename&quot;&gt;
         &lt;activeWhen&gt;
            &lt;reference
                  definitionId=&quot;de.techjava.rcp.cnf.subcontent.petSelected&quot;&gt;
            &lt;/reference&gt;
         &lt;/activeWhen&gt;
         &lt;enabledWhen&gt;
            &lt;reference definitionId=&quot;de.techjava.rcp.cnf.subcontent.petSelected&quot; /&gt;
         &lt;/enabledWhen&gt;
      &lt;/handler&gt;
   &lt;/extension&gt;
   &lt;extension
         point=&quot;org.eclipse.core.expressions.definitions&quot;&gt;
      &lt;definition
            id=&quot;de.techjava.rcp.cnf.subcontent.petSelected&quot;&gt;
         &lt;with variable=&quot;selection&quot;&gt;
            &lt;iterate ifEmpty=&quot;false&quot; operator=&quot;or&quot;&gt;
               &lt;instanceof value=&quot;de.techjava.rcp.cnf.subcontent.data.Pet&quot; /&gt;
            &lt;/iterate&gt;
         &lt;/with&gt;
      &lt;/definition&gt;
   &lt;/extension&gt;
</pre>
<p>This should enable the Rename action on the Pet elements, too.<br />
<img class="alignnone size-full wp-image-487" title="CNF2-rename-pet" src="http://www.techjava.de/wp-content/uploads/CNF2-rename-pet.png" alt="CNF2-rename-pet" width="384" height="239" /></p>
<h2>Dynamic content change</h2>
<p>Finally, the last topic, which is covered in this article is the control of which content is shown in the Common Navigator. The developer can define the initial behaviour by setting the <code>activeByDefault</code> attribute of the <code>NavigatorContent</code> element. The user can customize the visible NCEs in the special dialog:<br />
<img class="alignnone size-full wp-image-489" title="CNF2-available-customizations" src="http://www.techjava.de/wp-content/uploads/CNF2-available-customizations.png" alt="CNF2-available-customizations" width="407" height="339" /><br />
Of course there is a way to change the content shown in the Common Navigator at run-time. The following section describes how this can be done.</p>
<p>Responsible for loading the NCEs is the NavigatorContentService, which can be retrieved from the running Navigator instance. Using it is straight forward.</p>
<pre class="brush: java; title: ;">
    /**
     * Sets the status of a NCE of the current viewer if any
     */
    public static void setToolboxNCEActive(final String extensionId, final boolean active)
    {
        CommonNavigator instance = findCommonNavigator(CNFNavigator.VIEW_ID);
        if (instance != null)
        {
            INavigatorContentService contentService = instance.getNavigatorContentService();
            boolean isActive = contentService.getActivationService().isNavigatorExtensionActive(extensionId);
            if (active &amp;&amp; !isActive)
            {
                contentService.getActivationService().activateExtensions(new String[] { extensionId }, false);
            } else if (!active &amp;&amp; isActive)
            {
                contentService.getActivationService().deactivateExtensions(new String[] { extensionId }, false);
            } else
            {
                // do nothing, just quit
                return;
            }
            contentService.getActivationService().persistExtensionActivations();
            contentService.update();
        }
    }
</pre>
<p>The method <code>findCommonNavigator(String viewId)</code> is responsible for delivering the instance of the CNF. For example it could query the view for visible viewers and compare them with the requested Id:</p>
<pre class="brush: java; title: ;">
    public static CommonNavigator findCommonNavigator(String navigatorViewId)
    {
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        if (page != null)
        {
            IViewPart view = page.findView(navigatorViewId);
            if (view != null &amp;&amp; view instanceof CommonNavigator)
                return ((CommonNavigator) view);
        }
        return null;
    }
</pre>
<p>After the NCE status is changed the viewer has to be updated. Please note, that retrieving the instance of the <code>INavigatorContentService</code> via the Factory (<code>NavigatorContentServiceFactory</code>) will not work for this scenario (see 
<a  href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=284650" onclick="javascript:pageTracker._trackPageview('/external/bugs.eclipse.org/bugs/show_bug.cgi');" >Bug 284650</a>).</p>
<p>Making a step back and thinking about the usage of the method above, I realized that it can be reduced to the usage of core expressions instead of the simple boolean <code>activeByDefault</code> attribute. Maybe this enhancement could be contributed to the CNF at some point&#8230;</p>
<p>The source code to this post is available for 
<a  href="http://www.techjava.de/wp-content/uploads/rcp-cnf2.zip" onclick="javascript:pageTracker._trackPageview('/downloads/wp-content/uploads/rcp-cnf2.zip');" >download</a>. It includes two plug-in projects (the CNF and the child content) which are packaged into a small RCP application. Just launch the product included in the CNF plug-in.</p>
<h3>References</h3>
<ul>
<li>
<a  href="http://wiki.eclipse.org/index.php/Common_Navigator_Framework" onclick="javascript:pageTracker._trackPageview('/external/wiki.eclipse.org/index.php/Common_Navigator_Framework');" >http://wiki.eclipse.org/index.php/Common_Navigator_Framework</a></li>
<li>
<a  href="http://wiki.eclipse.org/Command_Core_Expressions" onclick="javascript:pageTracker._trackPageview('/external/wiki.eclipse.org/Command_Core_Expressions');" >http://wiki.eclipse.org/Command_Core_Expressions</a></li>
<li>
<a  href="http://wiki.eclipse.org/index.php/Platform_Command_Framework" onclick="javascript:pageTracker._trackPageview('/external/wiki.eclipse.org/index.php/Platform_Command_Framework');" >http://wiki.eclipse.org/index.php/Platform_Command_Framework</a></li>
</ul>
<p>The compass image used in the post is taken from the 
<a  href="http://www.flickr.com/photos/bio_inc/484534267/" onclick="javascript:pageTracker._trackPageview('/external/www.flickr.com/photos/bio_inc/484534267/');" >FlickR gallery</a> of Jean Franco Castro.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techjava.de/topics/2009/08/eclipse-common-navigator-framework-2/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Passing Data between Plug-ins</title>
		<link>http://www.techjava.de/topics/2009/07/passing-data-between-plug-ins/</link>
		<comments>http://www.techjava.de/topics/2009/07/passing-data-between-plug-ins/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 20:57:12 +0000</pubDate>
		<dc:creator>Simon Zambrovski</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[extension point]]></category>
		<category><![CDATA[pde]]></category>
		<category><![CDATA[plug-in]]></category>
		<category><![CDATA[rcp]]></category>
		<category><![CDATA[schema]]></category>

		<guid isPermaLink="false">http://www.techjava.de/?p=436</guid>
		<description><![CDATA[Abstract The Eclipse Platform provides a very rich API for the development and configuration of plug-ins and RCPs. It does this in two ways: by providing the corresponding classes and interfaces or by using the extension point mechanism. During the development the question arises, how to develop own extension points and how those plug-in interfaces [...]]]></description>
			<content:encoded><![CDATA[<h2>Abstract</h2>
<p><img src="http://www.techjava.de/wp-content/uploads/imp_extplug_wiz.png" alt="Passing Data between Plug-ins" title="Passing Data between Plug-ins" width="75" height="66" style="margin:10px;float:right;" /><br />
The Eclipse Platform provides a very rich API for the development and configuration of plug-ins and RCPs. It does this in two ways: by providing the corresponding classes and interfaces or by using the extension point mechanism. During the development the question arises, how to develop own extension points and how those plug-in interfaces look like. This article summarizes some of my experiences with developing plug-ins extension points.</p>
<h2>Introduction</h2>
<p>The extensive use of extension points is the standard approach during the development of own plug-ins and Eclipse-based applications. Especially, in the 3.x branch, the Eclipse Developers introduced tons of new extension points, primarily for the user interface, moving towards the declarative definition of the UI. Even if the the topic of the definition of extension points is covered in several 
<a  href="http://www.amazon.de/Contributing-Eclipse-Principles-Patterns-Plug-Ins/dp/0321205758" onclick="javascript:pageTracker._trackPageview('/external/www.amazon.de/Contributing-Eclipse-Principles-Patterns-Plug-Ins/dp/0321205758');" >books</a> and 
<a  href="http://www.eclipse.org/articles/Article-Plug-in-architecture/plugin_architecture.html" onclick="javascript:pageTracker._trackPageview('/external/www.eclipse.org/articles/Article-Plug-in-architecture/plugin_architecture.html');" >articles</a>, it is a bit challenging to come up with a clean extension point design for a particular scenarios, especially for beginners. This has to do with the specific way, how the Eclipse platform handles extensions.</p>
<p>In order to have a concrete scenario, lets assume that a small RCP application consisting of two plug-ins is being developed. The application prints out the time every ten seconds. One plug-in is responsible for the functionality of the time generation (lets call it the Core plug-in) and another, for the presentation of the results of the first one (lets call it UI plug-in). The separation of code in UI and non-UI plug-ins is a common practice and the standard question is, how to to pass data between the two. In general we assume, that the UI plug-in depends on the Core plug-in.<br />
<span id="more-436"></span><br />
In the following the different alternatives are discussed.</p>
<h2>Call me synchronously</h2>
<p>One of the most simple and common cases is the situation, in which the UI plug-in has the control and needs to call a method on some instance of the Core plug-in. This happens particularly in cases, in which a command handler or an action implemented in the UI plug-in is invoked on behalf of user interaction and the functionality of the Core plug-in is called. The only thing to do is to add the classes to the exported by the Core plug-in. Since the UI plug-in depends on Core, the classes will become visible (in terms of OSGi) and can be imported and used directly. If the method is synchronous, the result can be received upon the completion of the method and displayed by the UI plug-in. In this case the plug-in boundary disappears.</p>
<h2>Call me asynchronously</h2>
<p>The things get more complicated, if the call is not synchronous, but is invoked inside of a <code>IWorkspaceRunnable</code> or a <code>Job</code>. This situation is common in enterprise scenarios, when the invoked functionality is a long running operation, like loading data from a database or accessing a resource over the network. The signatures of the methods for those operations do not provide a possibility to get the invocation result.</p>
<pre class="brush: java; title: ;">
public interface IWorkspaceRunnable {
    public void run(IProgressMonitor monitor) throws CoreException;
}
</pre>
<pre class="brush: java; title: ;">
public abstract class Job extends InternalJob implements IAdaptable {
    protected abstract IStatus run(IProgressMonitor monitor);
}
</pre>
<p>In fact the method invocation of asynchronous calls can be performed from any plug-in (so not only UI) and it does not play any role for the result. Thus, this case can be discussed together with the case, in which the Core plug-in broadcasts the data change.</p>
<h2>Don&#8217;t call us, we will call you</h2>
<p>Another case, which can be seen as a general extension of the asynchronous case is if the state changes, and consequently the UI change originates from the Core plug-in. This use case is possible if there are several UI plug-ins working with one Core plug-in, and the changes inside of the Core plug-in have to be propagated to the views, following the well-known Model-View-Controller Design Pattern. Then, a common approach is the implementation of the Listener-Broadcaster Design Pattern. The UI plug-ins (Views) should register themselves as listeners by the Core plug-ins and will be notified on changes of its (Model) state. In this case the extension point mechanism of Eclipse can be used as discussed in the following. It is also a good idea, to hide the code dealing with Eclipse Extension Registry and extensions, so a simple implementation of the broadcaster is provided, too.</p>
<h3>Definition of the extension point (Core plug-in side)</h3>
<p>The definition of extension point for the listener/broadcaster case involves four steps:</p>
<ul>
<li>Creation of the listener interface</li>
<li>Registration of the extension point</li>
<li>Creation of the extension point schema</li>
<li>Implementation of the broadcaster</li>
</ul>
<p>The so defined extension point can be used by plug-ins, which then provide implementations of the listener interface. The broadcaster, located in the Core plug-in is responsible for sending the data to them. Note, that providing the implementation of the listener via extension point <strong>is logically equivalent to the creation of a factory</strong> which is responsible for the production of listeners. The Core plug-in has the control of how this factory is used, how many listeners (from each extension) are created, and when these are notified.</p>
<h4>Creation of the listener interface</h4>
<p>The interface for the listener is usually very simple. It provides a method, which is called by the broadcaster, e.G:</p>
<pre class="brush: java; title: ;">
public interface ISimpleListener
{
    public void eventOccured();
}
</pre>
<p>Sometimes the method takes parameters, like <code>public void eventOccured(String message)</code> or <code>public void eventOccured(ISimpleEvent event)</code> and sometimes it returns a value. In general, the signature of the notification method is application-specific and will not be discussed further. Since the implementers of the listener does not have control over the way, how and when this method is used, it is advised to add two life-cycle methods to the interface <code>initialize()</code> and <code>terminate()</code>:</p>
<pre class="brush: java; title: ;">
package de.techjava.rcp.plugins.core.listener;

/**
 * A simple listener
 * @author Simon Zambrovski, TechJava Group
 */
public interface ISimpleListener
{
    /**
     * Initialization life-cycle method
     */
    public void initialize(Object source);

    /**
     * Signals the event occurrence
     * @param event
     */
    public void eventOccured(SimpleEvent event);

    /**
     * Termination life-cycle method
     */
    public void terminate();
}
</pre>
<p>The life-cycle of the listener is then defined as follows: first, its parameter-less constructor is called, then the <code>initialize</code> method is invoked, providing the ability to hook into some infrastructure inside of the implementing plug-in. After the initialization, the <code>eventOccured</code> method is called multiple times. Finally, the listener is informed about the fact that the source will not send any information by the invocation of the <code>terminate</code> method. The <code>source</code> parameter of the <code>ISimpleListener#initialize(Object)</code> method again is application specific and should be chosen that way, that the listener is able to determine the source of events. Alternatively, the method <code>ISimpleListener#eventOccured(SimpleEvent)</code> can carry this information on every invocation, either in the <code>SimpleEvent</code> object or as additional parameter.</p>
<h4>Registration of the extension point</h4>
<p>After the Java interface of the listener has been created, the extension point can be defined. The easiest way to this, is to use the Plug-In Manifest Editor &gt; Extension Points, but you can edit the <code>plugin.xml</code> directly. Basically, three values are required: <code>id</code>, <code>name</code> and <code>schema location</code>.<br />
<img class="alignnone" style="margin: 5px;" title="extension-point-wizard" src="http://www.techjava.de/wp-content/uploads/extension-point-wizard.png" alt="extension-point-wizard" width="435" height="311" /></p>
<p>The corresponding <code>plugin.xml</code> code looks like this:</p>
<pre class="brush: xml; title: ;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;?eclipse version=&quot;3.5&quot;?&gt;
&lt;plugin&gt;
   &lt;extension-point
      id=&quot;de.techjava.rcp.plugins.core.listener&quot;
   	  name=&quot;Simple Core Listener&quot;
   	  schema=&quot;schema/org.techjava.rcp.plugins.core.listener.exsd&quot;/&gt;
&lt;/plugin&gt;
</pre>
<p>Since the dependent plug-ins should implement the <code>ISimpleListener</code> interface, the containing package  has to be exposed. This can be done either by adding the package to the list of exported packages using the Plug-In Manifest Editor &gt; Runtime &gt; Exported Packages or by simple editing of the <code>MANIFEST.MF</code> file and adding the following line to it:</p>
<pre class="brush: xml; title: ;">
Export-Package: de.techjava.rcp.plugins.core.listener
</pre>
<h4>Creation of the extension point schema</h4>
<p>The definition of the extension point is performed by creation of the XML-Schema document, describing the structure and the data of the extension point. The Eclipse IDE provides a convenient Extension Point Schema Editor for this task, implemented as multi-page editor with master-detail page for schema definition. The creation wizard already creates the extension element. What has to be done is this:</p>
<ul>
<li>Create <code>New Element</code></li>
<li>Provide an adequate <code>Name</code> for it (<code>listener</code> in our case)</li>
<li>Add an <code>Attribute</code> to this element</li>
<li>Provide an adequate <code>Name</code> for it (<code>class</code> in our case)</li>
<li>Change the <code>Use</code> to required</li>
<li>Change the <code>Type</code> to <code>java</code></li>
<li>Fill the <code>Implements</code> with the full-qualified name of the listener interface (<code>de.techjava.rcp.plugins.core.listener.ISimpleListener</code>)</li>
<li>Optionally, fill the description</li>
<li>Add a <code>Sequence</code> to the <code>extension</code></li>
<li>Add a reference to the <code>listener</code> to the <code>Sequence</code></li>
<li>Optionally, adjust the multiplicity of the <code>listener</code> element, to allow multiple listeners to be registered using one extension point</li>
</ul>
<p>In the Extension Point Schema Editor the corresponding changes should look like this: <img class="alignnone" style="margin: 5px;" title="extension-point-editor" src="http://www.techjava.de/wp-content/uploads/extension-point-editor1.png" alt="extension-point-editor" width="549" height="419" /></p>
<h4>Implementation of the broadcaster</h4>
<p>After the interface is created and the corresponding extension point is defined, a broadcaster can be implemented. Its purpose is to hide the code related to the use of the Extension Point Registry. For convenience, the broadcaster can implement the same interface as the listeners do (<code>ISimpleListener</code>).</p>
<pre class="brush: java; title: ;">
/**
 * Simple broadcaster implementing the listener interface
 * @author Simon Zambrovski, TechJava Group
 */
public class SimpleBroadcaster implements ISimpleListener
{

    private static final String POINT_ID = &quot;de.techjava.rcp.plugins.core.listener&quot;;
    private static final String CLASS_ATTRIBUTE = &quot;class&quot;;

    private List&lt;ISimpleListener&gt; listeners = null;

    /**
     * Construct the broadcaster and initializes the listeners registered
     * using {@link de.techjava.rcp.plugins.core.listener} extension
     * point
     */
    public SimpleBroadcaster(Object source)
    {
        // initialize on creation
        initialize(source);
    }

    public void eventOccured(SimpleEvent event)
    {
        // broadcast the events
        for (ISimpleListener listener : this.listeners)
        {
            if (listener != null)
            {
                listener.eventOccured(event);
            }
        }
    }

    public void initialize(Object source)
    {
        // retrieve the registered listeners
        this.listeners = getRegisteredListeners();

        // initialize
        for (ISimpleListener listener : this.listeners)
        {
            if (listener != null)
            {
                listener.initialize(source);
            }
        }
    }

    public void terminate()
    {
        // terminate
        for (ISimpleListener listener : this.listeners)
        {
            if (listener != null)
            {
                listener.terminate();
            }
        }
        this.listeners = null;
    }
...
}
</pre>
<p>The broadcaster holds the list of registered <code>ISimpleListener</code> instances. Its own implementation of the <code>ISimpleListener</code> is trivial and just delegates the calls to the elements of this list. The static method <code>SimpleBroadcaster#getRegisteredListeners()</code> is responsible for querying the registry for the registered extension and looks as follows:</p>
<pre class="brush: java; title: ;">
    /**
     * Retrieves all registered listeners
     */
    public static List&lt;ISimpleListener&gt; getRegisteredListeners()
    {
        IConfigurationElement[] decls = Platform.getExtensionRegistry().getConfigurationElementsFor(POINT_ID);

        Vector&lt;ISimpleListener&gt; validExtensions = new Vector&lt;ISimpleListener&gt;();
        for (int i = 0; i &lt; decls.length; i++)
        {
            try
            {
                ISimpleListener extension = (ISimpleListener) decls[i].createExecutableExtension(CLASS_ATTRIBUTE);
                validExtensions.add(extension);
            } catch (CoreException e)
            {
                Activator.logError(&quot;Error instatiating the &quot; + POINT_ID + &quot; extension&quot;, e);
            }
        }
        return validExtensions;
    }
</pre>
<h4>Use of the broadcaster</h4>
<p>The use of the broadcaster from the Core plug-in is straight-forward. Here is an example of a job, which periodically sends message containing the time to the  listeners.</p>
<pre class="brush: java; title: ;">
/**
 * Broadcasts the current time
 * @author Simon Zambrovski
 * @version $Id$
 */
public class SimpleTimeBroadcastJob extends Job
{
    private SimpleDateFormat sdf = new SimpleDateFormat(&quot;yyyy-MM-dd hh:mm:ss&quot;);
    private SimpleBroadcaster broadcaster = null;

    public SimpleTimeBroadcastJob()
    {
        super(&quot;Time Broadcast Job&quot;);
    }

    protected IStatus run(IProgressMonitor monitor)
    {
        try
        {
            broadcaster = new SimpleBroadcaster(this);
            broadcaster.eventOccured(new SimpleEvent(&quot;Curent time in Core is &quot; + sdf.format(new Date())));
            broadcaster.terminate();
            return Status.OK_STATUS;
        } finally
        {
            // restart again in a 10 seconds
            schedule(10 * 1000);
        }
    }
}
</pre>
<p>Now, after the Core part is implemented, we focus on the implementation of the UI part, which receives the events.</p>
<h3>Use of extension point (UI plug-in side)</h3>
<p>The usage of the extension point is simpler than its definition and basically consists of the implementation of the listener interface and its registration. Here is a sample implementation writing to System.out:</p>
<pre class="brush: java; title: ;">
public class SimpleListener implements ISimpleListener
{
    private Object source;

    public SimpleListener()
    {
    }

    public void eventOccured(SimpleEvent event)
    {
        String message = &quot;Event from &quot; + source.toString() + &quot;: &quot; + event.getMessage();
        System.out.println(message);
    }

    public void initialize(Object source)
    {
        this.source = source;
        System.out.println(&quot;New &quot; + SimpleListener.class.getName() + &quot; listens to &quot; + source.toString());
    }

    public void terminate()
    {
        this.source = null;
        this.consoleStream = null;
        System.out.println(&quot;Listners destroyed&quot;);
    }
}
</pre>
<p>In order to tell the Eclipse Platform about the existence of this implementation, the extension point defined in the Core plug-in and has to be used in the UI plug-in.  For this purpose, the UI plug-in must list the Core plug-in in its <code>Dependencies</code> and define the use of the extension point in the <code>plugin.xml</code>:</p>
<pre class="brush: xml; title: ;">
   &lt;extension
         point=&quot;de.techjava.rcp.plugins.core.listener&quot;&gt;
      &lt;listener
            class=&quot;de.techjava.rcp.plugins.ui.SimpleListener&quot;&gt;
      &lt;/listener&gt;
   &lt;/extension&gt;
</pre>
<p>That&#8217;s it.</p>
<h2>Example</h2>
<p>The example source for this article is available 
<a  href="http://www.techjava.de/download/examples/rcp-plugins.zip" onclick="javascript:pageTracker._trackPageview('/downloads/download/examples/rcp-plugins.zip');" >here</a>. It is a little bit more elaborate and provides a simple application, which prints the time into the Eclipse Console. I used Eclipse Galileo (3.5.0) &#8211; just copy the two projects into your workspace and run the product.<br />
<img src="http://www.techjava.de/wp-content/uploads/time-rcp1.png" alt="time-rcp" title="time-rcp" width="585" height="265" class="alignnone size-full wp-image-449" style="margin:10px;"/></p>
<h2>References</h2>
<ul>
<li>
<a  href="http://www.eclipse.org/articles/Article-Plug-in-architecture/plugin_architecture.html" onclick="javascript:pageTracker._trackPageview('/external/www.eclipse.org/articles/Article-Plug-in-architecture/plugin_architecture.html');" >Notes on the Eclipse Plug-in Architecture</a></li>
<li>
<a  href="http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612/ref=sr_1_2?ie=UTF8&amp;s=books&amp;qid=1248225439&amp;sr=8-2" onclick="javascript:pageTracker._trackPageview('/external/www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612/ref=sr_1_2');" >Design Patterns: Elements of Reusable Object-Oriented Software</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.techjava.de/topics/2009/07/passing-data-between-plug-ins/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Packaging Eclipse-based RCP for the use in enterprise context</title>
		<link>http://www.techjava.de/topics/2009/07/packaging-eclipse-based-rcp-for-the-use-in-enterprise-context/</link>
		<comments>http://www.techjava.de/topics/2009/07/packaging-eclipse-based-rcp-for-the-use-in-enterprise-context/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 20:00:33 +0000</pubDate>
		<dc:creator>Simon Zambrovski</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Enterprise Systems]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[enterprise systems]]></category>
		<category><![CDATA[feature]]></category>
		<category><![CDATA[packaging]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[product]]></category>
		<category><![CDATA[rcp]]></category>

		<guid isPermaLink="false">http://www.techjava.de/?p=394</guid>
		<description><![CDATA[Abstract Using Eclipse-based rich-clients as stand-alone applications is discussed in many books and articles. In the context of enterprise systems, the software development adopted several paradigms to improve the quality of the overall architecture. This short article describes some issues in packaging the application for using it in the context of enterprise systems. Architectural Assumptions [...]]]></description>
			<content:encoded><![CDATA[<p><img style="margin: 5px; float: right" title="Packaging" src="http://www.techjava.de/wp-content/uploads/packaging.jpg" alt="Packaging" width="120" height="120" /></p>
<h2>Abstract</h2>
<p>Using Eclipse-based rich-clients as stand-alone applications is discussed in many 
<a  href="http://www.amazon.com/Eclipse-Rich-Client-Platform-Applications/dp/0321334612" onclick="javascript:pageTracker._trackPageview('/external/www.amazon.com/Eclipse-Rich-Client-Platform-Applications/dp/0321334612');" >books</a> and 
<a  href="http://www.eclipse.org/articles/Article-RCP-1/tutorial1.html" onclick="javascript:pageTracker._trackPageview('/external/www.eclipse.org/articles/Article-RCP-1/tutorial1.html');" >articles</a>. In the context of enterprise systems, the software development adopted several paradigms to improve the quality of the overall architecture. This short article describes some issues in packaging the application for using it in the context of enterprise systems.</p>
<h2>Architectural Assumptions</h2>
<p>Designing enterprise architectures is a standard discipline for IT-consulting companies or freelancers involved in software development. Maybe one of the main characteristics of enterprise architectures is the framework-driven approach of software creation. Thus, the software has to comply certain rules and standards adopted inside the enterprise. In order to simplify such constrained development process, it is common to use an in-house software framework, which enforces the  compliance of the enterprise-internal standards and acts as glue between different technologies adopted as parts of the enterprise architecture.</p>
<p>Using such frameworks has major implications for the software development in general, and especially for the rich client development. The design issues are summarized in the next section.</p>
<h2>Usaging an Enterprise Framework</h2>
<p>The major goal of the enterprise in-house framework is to simplify the process of software systems development and to enforce standardization among the software systems. This usually includes the following aspects:</p>
<ul>
<li>Domain-specific component framework</li>
<li>Methods for master data management</li>
<li>Infrastructure services: authentication, authorization, communication, security, printing, reporting</li>
<li>Application skeletons and launchers</li>
</ul>
<p>The more unification and standardization is included inside the framework, the easier it is for a software developer to concentrate on the particular business task and the easier is the maintenance of the software system.</p>
<p>From the previous list, the most interesting part related to RCP packaging and deployment is the existence of the application skeletons and launchers. So, when launching an application, the framework libraries are loaded and executed first and pass the control to the application-specific modules. The advantage of this approach is that infrastructure services can be loaded first, which can be developed and shared among different applications.<br />
<span id="more-394"></span></p>
<h2>The required plug-ins</h2>
<p>Following the general idea of RCP packaging (see rules provided in the 
<a  href="http://www.amazon.com/Eclipse-Rich-Client-Platform-Applications/dp/0321334612" onclick="javascript:pageTracker._trackPageview('/external/www.amazon.com/Eclipse-Rich-Client-Platform-Applications/dp/0321334612');" >RCP Book</a>) and assuming one target platform (in terms of one RCP product), <strong>one top-level plug-in and should be defined</strong>. In addition, we assume at least one <strong>in-house framework plug-in</strong> and at least <strong>one application-specific plug-in</strong>. Usually there will be more of each type, but it will not change the picture much. Important at this point is the fact, that the application-specific code depends on the in-house framework code. In order to simplify the identification of the plug-ins, an example project is introduced. Let’s assume the project is called <strong>FooBar</strong>. Then, the plug-ins are called:</p>
<ul>
<li><code>de.techjava.foobar</code>: This is the functional plug-in, which contains the application-specific code.</li>
<li><code>de.techjava.framework</code>: This is the framework plug-in, which contains framework component code.</li>
<li><code>de.techjava.foobar.product.standalone</code>: This is an application and product definition plug-in which contains the definition of the product and application-agnostic code for launching the application.</li>
</ul>
<h2>Managing plug-in dependencies</h2>
<p>A difficult issue for the RCP beginners is the management of dependencies between plug-ins. Especially, the transition from the development of a single plug-in to the configuration of features and products seem to be non-trivial. In order to solve this problem, there are simple rules to follow. You can violate these rules in sophisticated scenarios, but for the beginners it is a good idea to follow them.</p>
<ol>
<li><em>Create dependencies only if you need them</em>. Each plug-in should only list plug-ins (or even better packages) it really depends on. Make sure to check it with the “<strong>Find unused dependencies</strong>” action available on the right-click in the Dependencies Tab of the Plug-in Manifest Editor.</li>
<li><em>Use versioning information. </em>Plug-ins (or better bundles, or as 
<a  href="http://www.aniszczyk.org/" onclick="javascript:pageTracker._trackPageview('/external/www.aniszczyk.org/');" >Chris</a> call them Plundles) provide version information. And it is highly advisable to include them in the import statements of the plug-ins, which simplifies the migration later on…</li>
<li><em>Don’t forget anything</em>. Every Plug-in should appear in at least in one Plug-In section of the Feature definition. Every feature should be included by another feature, higher in the hierarchy.</li>
<li><em>Keep the hierarchy flat</em>. For simple scenarios, it is sufficient to have two levels of features (top-level feature, one per-product and the underlying features include their plug-ins).</li>
<li><em>Don’t re-export dependencies</em>. Every Feature for a group of plug-ins should also include plug-ins required by the members of the group. It does not hurt if a plug-in is included several times, but it does if it is not included at all. You can optimize here if you check which plug-ins are imported by the Eclipse RCP feature (which can be considered as stable), but it does not make assumptions about features developed by third parties.</li>
</ol>
<p>Following these rules it is simple to create features for the corresponding plug-ins. Several plug-ins which belong together and are handled as a fixed piece can be grouped into Features. Usaging Features is highly advisable, and sometimes simply required (e.G. by RCP in a Java Web Start target deployment strategy). So in addition to the previously mentioned plug-in projects, at least three feature projects are required:</p>
<ul>
<li><code>de.techjava.foobar.feature</code>: This is a functional feature, which includes the <code>de.techjava.foobar</code> plug-in and all plug-ins required by it, which do not appear in the Eclipse RCP feature</li>
<li><code>de.techjava.framework.feature</code>: This is a framework feature, which includes the <code>de.techjava.framework</code> plug-in and all plug-ins required by it, which do not appear in the Eclipse RCP feature</li>
<li><code>de.techjava.foobar.feature.standalone</code> This is the top level feature, which is used for the product configuration. <strong>It includes the two features above and the Eclipse RCP feature </strong>(and optional other features used, like e.G. org.eclipse.help). <strong>It also includes exactly one plug-in</strong>, which is not included anywhere else: <code>de.techjava.foobar.standalone.product</code></li>
</ul>
<h2>The product definition plug-in</h2>
<p>The definition of the product is spread among several files. First of all the plug-in.xml of the <code>de.techjava.foobar.standalone.product</code> plug-in makes uses of two extensions:</p>
<ul>
<li><code>org.eclipse.core.runtime.applications</code></li>
<li><code>org.eclipse.core.runtime.products</code></li>
</ul>
<p>The application extension point is used to point to the Java class implementing the interface <code>org.eclipse.equinox.app.IApplication</code>. Along with this implementation, other classes needed to start up the RCP (like Advisors, etc…) are placed into the source directory of the plug-in. The product extension point is used for the association of the application with a product id. The previously-defined top-level feature includes all required features and the product definition plug-in. Finally, the <code>.product</code> file is the place, where all things are bound together: product id, application id, launcher parameters, and the one top level feature: <code>de.techjava.foobar.feature.standalone</code>. Other customization of the RCP is possible from the <code>plugin-customization.ini</code>, which is placed together with the <code>.product</code> file into the plug-in root directory.</p>
<p><img class="alignnone size-full" style="margin:10px;" title="Product configuration" src="http://www.techjava.de/wp-content/uploads/product_feature_plugin1.png" alt="Product configuration" width="385" height="499" /><br />
As a result the following configuration should be achieved after the packaging is finished. The product references the product-id and the application, defined in the plugin.xml of the plug-in project it is contained in. The product configuration is feature-based and includes one top-level feature. The top-level feature includes all other features (functional, framework, Eclipse RCP, other optional) and the one plugin, in which the product file resides.</p>
<p>The simple example provided in this articles is available as sourcecode for download (
<a  href="http://www.techjava.de/download/examples/rcp-packaging.zip" onclick="javascript:pageTracker._trackPageview('/downloads/download/examples/rcp-packaging.zip');" >rcp-packaging.zip</a>).</p>
<h2>The framework hooks</h2>
<p>In the introduced scenario, the packaging is not specific to the in-house framework. It just includes the feature containing the framework plug-in. This approach works fine, if the framework is used in a white-box manner, which means that the framework provides ready-to-use components to be plugged-in to the application (like e.G. a component for the master data management). The other type of frameworks is the so-called black-box framework, which provides components that have to be configured and integrated into the application components. In this case, the framework components can not be plugged-in using some declarative extension points, but need to be called from the application code. In the latter case, the dependencies appear between the plug-in launching the application (<code>de.techjava.foobar.standalone.product</code>) and the framework plug-ins. This requires a modification in the previous setup and the violation of one of the rules posted above. The plug-in has to define the dependency to the framework plug-in, but the top-level feature does not include the required plug-in directly, but imports the whole framework feature.</p>
<p></p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">Technorati-Tags: 
<a rel="tag"  href="http://technorati.com/tags/eclipse" onclick="javascript:pageTracker._trackPageview('/external/technorati.com/tags/eclipse');" >eclipse</a>,
<a rel="tag"  href="http://technorati.com/tags/java" onclick="javascript:pageTracker._trackPageview('/external/technorati.com/tags/java');" >java</a>,
<a rel="tag"  href="http://technorati.com/tags/rcp" onclick="javascript:pageTracker._trackPageview('/external/technorati.com/tags/rcp');" >rcp</a>,
<a rel="tag"  href="http://technorati.com/tags/packaging" onclick="javascript:pageTracker._trackPageview('/external/technorati.com/tags/packaging');" >packaging</a>,
<a rel="tag"  href="http://technorati.com/tags/plugin" onclick="javascript:pageTracker._trackPageview('/external/technorati.com/tags/plugin');" >plugin</a>,
<a rel="tag"  href="http://technorati.com/tags/feature" onclick="javascript:pageTracker._trackPageview('/external/technorati.com/tags/feature');" >feature</a>,
<a rel="tag"  href="http://technorati.com/tags/product" onclick="javascript:pageTracker._trackPageview('/external/technorati.com/tags/product');" >product</a>,
<a rel="tag"  href="http://technorati.com/tags/enterprise+systems" onclick="javascript:pageTracker._trackPageview('/external/technorati.com/tags/enterprise+systems');" >enterprise systems</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.techjava.de/topics/2009/07/packaging-eclipse-based-rcp-for-the-use-in-enterprise-context/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Eclipse Common Navigator Framework</title>
		<link>http://www.techjava.de/topics/2009/04/eclipse-common-navigator-framework/</link>
		<comments>http://www.techjava.de/topics/2009/04/eclipse-common-navigator-framework/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 01:13:02 +0000</pubDate>
		<dc:creator>Simon Zambrovski</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[cnf]]></category>
		<category><![CDATA[common navigator]]></category>
		<category><![CDATA[common navigator framework]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[rcp]]></category>
		<category><![CDATA[resource]]></category>

		<guid isPermaLink="false">http://www.techjava.de/?p=302</guid>
		<description><![CDATA[Abstract This article describes some efforts to use the Common Navigator Framework (CNF). In doing so it incorporates the information already covered in different articles, but also focuses on the specific use case of providing a view of something completely unrelated to the platform resources. So the aim is not to add some content to [...]]]></description>
			<content:encoded><![CDATA[<p><img style="margin: 10px; float:right;" title="compas" src="http://www.techjava.de/wp-content/uploads/compas.jpg" alt="compas" width="240" height="160" /></p>
<h2>Abstract</h2>
<p>This article describes some efforts to use the Common Navigator Framework (CNF). In doing so it incorporates the information already covered in different articles, but also focuses on the specific use case of providing a view of something completely unrelated to the platform resources. So the aim is not to add some content to the &#8220;Project Explorer&#8221; which is an example of resource-oriented CNF usage, but to provide a view on a completely own data model.</p>
<h2>Introduction</h2>
<p><img style="margin: 10px; float:left;" title="Project Explorer" src="http://www.techjava.de/wp-content/uploads/pe_01.png" alt="Project Explorer" width="272" height="179" /><br />
A very common UI element to represent data is a tree view. In SWT this UI element is implemented using the <code>Tree</code> widget. Following the MVC design pattern in the <code>TreeViewer</code>, JFace simplifies the usage of the Tree widget by delegating the task of content adoption to the ContentProvider and the label production to the LabelProvider (and using Sorters and Filters for sorting and filtering). Still for a single representation one has to construct a viewer and configure it with a corresponding Label- and ContentProvider. Further code reduction can be achieved by the use of <code>WorkbenchContentProvider</code> and <code>WorkbenchLabelProvider</code> if the elements can be made adaptable (implement <code>IAdaptable</code> interface and making them first-class workbench citizens). This approach is helpful, if the elements has to be displayed in several different viewers (e.G. Table). Finally, <strong>the Common Navigator Framework (CNF)</strong> is a facility provided by the Eclipse Platform which allows the usage of multiple Label- and ContentProvider on the same view. The providers are activated and used dynamically and can be configured declarative or programmatically. The advantage of CNF approach is the ability to combine elements in one view which have different origins(e.G. contributed by different plugins). CNF is used in Eclipse IDE: e.G. &#8220;ProjectExplorer&#8221; and &#8220;CVS Synchrnoize&#8221; are both instances of the CNF.</p>
<p>The usage of the CNF in your own application for purposes of representation of resource-based (and usually file-based) content is discussed in 
<a  href="http://scribbledideas.blogspot.com/2006/07/pdf-versions-now-available.html" onclick="javascript:pageTracker._trackPageview('/external/scribbledideas.blogspot.com/2006/07/pdf-versions-now-available.html');" >articles of Micael Elder</a> in detail. The main idea is to instantiate the view, declare the default content and UI interface and make some additions where needed. This post has a different aim: we start from scratch and represent completely resource unrelated content. Before diving in the implementation details, some overview is provided.</p>
<h2>UI Overview</h2>
<p><img style="margin: 10px; float:right;" title="Project Explorer with default options" src="http://www.techjava.de/wp-content/uploads/pe_02.png" alt="Project Explorer with default options" width="380" height="215" /> There are many things which can be configured by the usage of CNF and it is beyond the scope of this post to cover all of them. Still there are several things to understand before the actual code can be written. The user interacts with a View which shows the data elements. Which elements are shown is configured using the navigation content extensions. Shown elements can be filtered with Filters and sorted using Sorters on behalf of the user. There are some predefined actions and their positions in the UI and corresponding extension points to contribute to. <img style="margin: 10px; float:right;" title="Project Explorer Pop-up" src="http://www.techjava.de/wp-content/uploads/pe_031.png" alt="Project Explorer Pop-up" width="293" height="174" />. The actions for <strong>Working sets</strong>, <strong>Customize View</strong>, <strong>Link with editor</strong> belong to this category. The user can also right-click on particular element in the tree and sees a popup-menu. This menu is configured based on the content element and can be (is) contributed by several plugins. The action contribution is also covered in the article series from 
<a  href="http://scribbledideas.blogspot.com/2006/07/pdf-versions-now-available.html" onclick="javascript:pageTracker._trackPageview('/external/scribbledideas.blogspot.com/2006/07/pdf-versions-now-available.html');" >Michael Elder</a>.<br />
<br />
<span id="more-302"></span></p>
<h2>Minimal non-resource based CNF viewer</h2>
<p>The following example provide a set of minimal steps required to create a non-resource based CNF viewer. Your plug-in requires at least a dependency to <code>org.eclipse.ui.navigator</code>, <code>org.eclipse.ui</code>. </p>
<h3>Data model</h3>
<p>Let us assume a simple data model that should be represented in the view. There are two kinds of elements: parents and children (see Composite design pattern). Both Child and Parent are POJOs:</p>
<pre class="brush: java; title: ;">
public class Child
{
    private String name;
    private Parent parent;

    public Child(String name)
    {
        super();
        this.name = name;
    }

    // getters and setter
...
}
</pre>
<p>Every child stores information about its parent, and every parent knows its children. In order to maintain the model in-sync the <code>setChildren()</code> method of the <code>Parent</code> class takes care of unsetting on all previous children and setting the parent on new children. This is just a sample code and there are different ways to implement this more elegantly (like e.G. holding the parent-child relation externally).</p>
<pre class="brush: java; title: ;">
public class Parent extends Child
{
    private Child[] children = new Child[0];
    private Object rootElement;

    public Parent(String name)
    {
        super(name);
    }

    public void setChildren(Child[] children)
    {
        if (children != null)
        {
            setChildrensParent(null, this.children);
        }
        this.children = children;
        setChildrensParent(this, this.children);
    }

    /**
     * Sets children's parent
     * @param parent parent to be set
     * @param children children to set the parent
     */
    private static void setChildrensParent(Parent parent, Child[] children)
    {
        for (int i = 0; i &lt; children.length; i++)
        {
            children[i].setParent(parent);
        }
    }

    // getter and setter
...
}
</pre>
<p>Please note, that nothing more is assumed about the parent and the child. It is a good idea to make such elements implement <code>IAdaptable</code>, which simplifies a lot of issues later, but this is another topic. You may have noticed the <code>rootElement</code> member of the Parent. Again, this is only used in order to keep the object tree structure as simple as possible and provide a hook to the root of the tree. The final tree structure contains one root object, several parent objects containing several child objects each.</p>
<pre class="brush: java; title: ;">
public class Root extends PlatformObject
{
}
</pre>
<h3>Declaring the viewer</h3>
<p>In order to contribute a view to RCP/IDE the <code>org.eclipse.ui.views</code> extension point is used:</p>
<pre class="brush: xml; title: ;">
   &lt;extension
         point=&quot;org.eclipse.ui.views&quot;&gt;
      &lt;view
            class=&quot;de.techjava.rcp.cnf.provider.CNFNavigator&quot;
            id=&quot;de.techjava.rcp.cnf.view&quot;
            name=&quot;Virtual CNF&quot;
            restorable=&quot;true&quot;&gt;
      &lt;/view&gt;
   &lt;/extension&gt;
</pre>
<p>The two important things here are the <code>class</code> attribute pointing to the class of the CNF Navigator and the <code>id</code> attribute that will be used later in order to identify the view. Instead of pointing to the <code>org.eclipse.ui.navigator.CommonNavigator</code><br />
the reference to <code>ParentChildNavigator</code> is provided which is a subclass of the <code>CommonNavigator</code>. The reason for that is, that CommonNavigator gets its initial input (during initialization) from the Workbench by calling <code>getSite().getPage().getInput()</code>. In the IDE scenario, the default page input is <code>IWorkspaceRoot</code>, in the RCP scenario it is <code>null</code> and can be configured in the <code>WorkbenchAdvisor</code>. Instead, another implementation of <code>getInitialInput()</code> can be provided, passing the dummy Root object, which indicates the root of the tree. </p>
<pre class="brush: java; title: ;">
public class CNFNavigator extends CommonNavigator
{
    protected IAdaptable getInitialInput()
    {
        return new Root();
    }
}
</pre>
<h3>Defining viewer content</h3>
<p>In order to see something in the freshly-defined viewer, the information about the content has to be provided. The extension point <code>org.eclipse.ui.navigator.navigatorContent</code> is defined for this purpose. The main element responsible for the content is called <code>navigatorContent</code> and contains the following information:</p>
<ul>
<li><code>id</code> &#8211; the id of the content, to be referenced in the viewer</li>
<li><code>name</code> &#8211; the name of the content, which is seen in the <strong>Customize View</strong> dialog using the content tab, which can be activated or deactivated there by the user.</li>
<li><code>contentProvider</code> &#8211; the contentProvider class responsible for providing content elements</li>
<li><code>labelProvider</code> &#8211; the labelProvider class responsible for rendering a content element in the view</li>
</ul>
<pre class="brush: xml; title: ;">
   &lt;extension
         point=&quot;org.eclipse.ui.navigator.navigatorContent&quot;&gt;
      &lt;navigatorContent
            activeByDefault=&quot;true&quot;
            contentProvider=&quot;de.techjava.rcp.cnf.provider.CNFContentProvider&quot;
            id=&quot;de.techjava.rcp.cnf.content.VirtualContent&quot;
            labelProvider=&quot;de.techjava.rcp.cnf.provider.CNFLabelProvider&quot;
            name=&quot;Virtual content&quot;
            priority=&quot;normal&quot;&gt;
         &lt;triggerPoints&gt;...&lt;/triggerPoints&gt;
         &lt;possibleChildren&gt;...&lt;/possibleChildren&gt;
      ...
      &lt;/navigatorContent&gt;
   &lt;/extension&gt;
</pre>
<p>In addition, nested elements <code>triggerPoints</code> and <code>possibleChildren</code> describe when the current content is activated. This means that a CNF Viewer can compose the content coming from multiple providers and needs to know what content to display. These will be covered in the following sections. </p>
<h3>How the platform uses the viewer</h3>
<p>Before diving into the code section, it is worth spending a small section on the topic, how the platform uses the CNF viewer. In general, if an element is selected in the viewer, the CNF consults <code>triggerPoints</code> of all <b>Navigation Content Extensions (NCEs)</b> provided and tries to match the element to the trigger point expression. If the expression matches, the NCE is activated by the platform and the corresponding <code>contentProvider</code> is responsible for delivering content. If the element is activated by other means than in the viewer (e.G. in the Editor), the platform consults <code>possibleChildren</code> list and tries to match the corresponding expression. For resource-based approaches, the NCE with id <code>org.eclipse.ui.navigator.resourceContent</code> is usually provided. This NCE is enabled / triggered on any element that is instance of <code>IResource</code>. By this means e.G. the Project Explorer in the IDE passes the workspace root to the <code>ResourceExtensionContentProvider</code> which is responsible for delivering the children of the workspace root &#8211; the projects. In a non-resource based approach, the NCE must be triggered by the initial input of the viewer, in this example by the <code>Root</code> object. If the selected element is a <code>Parent</code> node, the NCE should also be triggered. The following definition of the trigger point accomplishes this task:</p>
<pre class="brush: xml; title: ;">
         &lt;triggerPoints&gt;
            &lt;or&gt;
               &lt;instanceof value=&quot;de.techjava.rcp.cnf.data.Root&quot; /&gt;
               &lt;instanceof value=&quot;de.techjava.rcp.cnf.data.Parent&quot; /&gt;
            &lt;/or&gt;
         &lt;/triggerPoints&gt;
</pre>
<p>Since the children delivered by the content provider on <code>Root</code> as parent element are instances of <code>Parent</code> and on <code>Parent</code> as parent element are instances of <code>Child</code>, the <code>possibleChildren</code> code looks as follows:</p>
<pre class="brush: xml; title: ;">
         &lt;possibleChildren&gt;
            &lt;or&gt;
               &lt;instanceof value=&quot;de.techjava.rcp.cnf.data.Parent&quot; /&gt;
               &lt;instanceof value=&quot;de.techjava.rcp.cnf.data.Child&quot; /&gt;
            &lt;/or&gt;
         &lt;/possibleChildren&gt;
</pre>
<h3>Label and Content providers</h3>
<p>After the way how the navigation content is being activated is discussed, the Content and Label providers can be addressed. The label provider implementation is straight-forward. Its task is to produce a textual and graphical representation of every element. In addition, it implements the <code>IDescriptionProvider</code> interface to provide description in the status bar when an element is selected. Please note, that this section is not CNF-specific but is related to JFace ContentProvider and JFace LabelProvider, as usual for any Viewer. It is provided here only for completion and if the user is not familiar with it in detail.</p>
<pre class="brush: java; title: ;">
public class CNFLabelProvider extends LabelProvider implements ILabelProvider, IDescriptionProvider
{
    public String getText(Object element)
    {
        if (element instanceof Parent)
        {
            return ((Child)element).getName() + &quot; [ &quot; +((Parent)element).getChildren().length + &quot; ]&quot;;
        } else if (element instanceof Child)
        {
            return ((Child)element).getName();
        }
        return null;
    }

    public String getDescription(Object element)
    {
        String text = getText(element);
        return &quot;This is a description of &quot; + text;
    }

    public Image getImage(Object element)
    {
        if (element instanceof Parent)
        {
            return PlatformUI.getWorkbench().getSharedImages()
              .getImage(ISharedImages.IMG_OBJ_FOLDER);
        } else if (element instanceof Child)
        {
            return PlatformUI.getWorkbench().getSharedImages()
              .getImage(ISharedImages.IMG_OBJ_FILE);
        }
        return null;
    }
}
</pre>
<p>The methods above are self-describing. For any element the text and image is selected based on element type. For children, the name is shown, for parents the number of children is displayed, additionally. The platform built-in icons of folder and file are used for convenience. The methods for the Label/Content provider usually follow this pattern of a <code>instanceof</code> cascade. </p>
<p>The content provider is responsible for the following tasks:</p>
<ul>
<li>At requested of <code>Root</code> it should deliver the list of <code>Parent</code> elements</li>
<li>At requested of <code>Parent</code> it should deliver the list of its children (<code>Child</code> elements)</li>
<li>At requested of <code>Child</code> it should deliver an empty list</li>
</ul>
<p>Since no real data model is available, its creation is hooked to the first access (that is, of course, for demonstration purposes only)</p>
<pre class="brush: java; title: ;">
public class CNFContentProvider implements ITreeContentProvider
{

    private static final Object[] EMPTY_ARRAY = new Object[0];
    private Parent[] parents;

    public Object[] getChildren(Object parentElement)
    {
        if (parentElement instanceof Root)
        {
            if (parents == null)
            {
                initializeParents(parentElement);
            }
            return parents;
        } else if (parentElement instanceof Parent)
        {
            return ((Parent) parentElement).getChildren();
        } else if (parentElement instanceof Child)
        {
            return EMPTY_ARRAY;
        } else
        {
            return EMPTY_ARRAY;
        }
    }

    public Object getParent(Object element)
    {
        if (element instanceof Child)
        {
            return ((Child) element).getParent();
        } else if (element instanceof Parent)
        {
            return ((Parent) element).getRoot();
        }
        return null;
    }

    public boolean hasChildren(Object element)
    {
        return (element instanceof Root || element instanceof Parent);
    }

    public Object[] getElements(Object inputElement)
    {
        return getChildren(inputElement);
    }

    public void dispose()
    {
        this.parents = null;
    }

    public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
    { /* ... */
    }
    ...
}
</pre>
<p>The class has three important methods: <code>getChildren(Object)</code>, <code>getParent(Object)</code> and <code>hasChildren(Object)</code>. The <code>getChildren(Object)</code> is responsible for delivering children elements to a given parent element. The <code>getParent()</code> delivers a parent for a given child element (e.G. when the child is selected using the editor and the viewer is requested to show the element in it). The <code>hasChildren(Object)</code> is a way of providing a more efficient implementation than <code>(getChildren(element).length == 0)</code>. The <code>getElements(Object)</code> method is usually delegated to <code>getChildren(Object)</code>. The difference between these methods is that <code>getElements(Object)</code> is called to obtain the tree viewer&#8217;s root elements, whereas <code>getChildren(Object)</code> is used to obtain the children of a given parent element in the tree (including a root). Since there is only one root (the not shown <code>IWorkspaceRoot</code>), it is OK to delegate. Finally, the <code>parents</code> member variable needs to be initialized on the first access, which can be done using the following code:</p>
<pre class="brush: java; title: ;">
    /**
     * Init code for empty model
     */
    private void initializeParents(Object parentElement)
    {
        this.parents = new Parent[3];
        for (int i = 0; i &lt; this.parents.length; i++)
        {
            this.parents[i] = new Parent(&quot;Parent &quot; + i);
            this.parents[i].setRoot(parentElement);
            Child[] children = new Child[3];
            for (int j = 0; j &lt; children.length; j++)
            {
                children[j] = new Child(&quot;Child &quot; + i + j);
            }
            this.parents[i].setChildren(children);
        }
    }
</pre>
<h3>Binding the content to the viewer</h3>
<p>The last remaining piece in the puzzle is to bind the content defined in the navigation content extension to the view defined in the view extension. The extension point <code>org.eclipse.ui.navigator.viewer</code> is responsible for that. It consists of several parts: the <code>viewer</code> element, that references the <code>id</code> of the view and the <code>viewerContentBinding</code> element that one one hand specifies the view to bind the content to and on the other hand provides a reference to the content definition id.</p>
<pre class="brush: xml; title: ;">
   &lt;extension
         point=&quot;org.eclipse.ui.navigator.viewer&quot;&gt;
      &lt;viewer
            viewerId=&quot;de.techjava.rcp.cnf.view&quot;&gt;
      &lt;/viewer&gt;
      &lt;viewerContentBinding
            viewerId=&quot;de.techjava.rcp.cnf.view&quot;&gt;
         &lt;includes&gt;
            &lt;contentExtension
                  isRoot=&quot;false&quot;
                  pattern=&quot;de.techjava.rcp.cnf.content.VirtualContent&quot;&gt;
            &lt;/contentExtension&gt;
         &lt;/includes&gt;
      &lt;/viewerContentBinding&gt;
   &lt;/extension&gt;
</pre>
<p>Please note, that the content id is provided in the <code>pattern</code> attribute. Instead of pointing to particular content id, the regex can be used (e.G. <code>de.techjava.rcp.cnf.content.*</code>). That&#8217;s it, look at the result.<br />
<img style="margin: 10px;" title="RCP virtual CNF" src="http://www.techjava.de/wp-content/uploads/rcp_cnf.png" alt="RCP virtual CNF" width="402" height="302" /><br />
Under <strong>&#8220;Custimize View&#8221;</strong> the content tab allows to show the defined &#8220;virtual content&#8221;. Since no filters are defined, the filter section is empty.<br />
<img style="margin: 10px;" title="RCP virtual CNF content selection" src="http://www.techjava.de/wp-content/uploads/rcp_cnf_content.png" alt="RCP virtual CNF content selection" width="406" height="416" /> </p>
<h2>Conclusion</h2>
<p>To my opinion, for almost every application using a tree/list view to represent entities the CNF should serve as a basis for the implementation. Thus, CNF documentation should be improved and get to the level &#8220;for beginners&#8221; rather than &#8220;for experts&#8221;. In this post, I have tried to provide an introduction for non-expert RCP/PDE developers. I&#8217;m interested in your comments.</p>
<h2>Further directions</h2>
<p>Currently, neither filters, sorters nor actions or pop-up menu are defined for the viewer. This can be a subject of the follow-up post, if requested, but is partly covered in the 
<a  href="http://scribbledideas.blogspot.com/2006/07/pdf-versions-now-available.html" onclick="javascript:pageTracker._trackPageview('/external/scribbledideas.blogspot.com/2006/07/pdf-versions-now-available.html');" >articles of Michael Edler.</a> Especially, the application of the new command framework has to be described.</p>
<h2>Resources</h2>
<h3>Eclipse</h3>
<ul>
<li>
<a  href="http://wiki.eclipse.org/index.php/Common_Navigator_Framework" onclick="javascript:pageTracker._trackPageview('/external/wiki.eclipse.org/index.php/Common_Navigator_Framework');" >CNF EclipseWiki page</a></li>
<li>
<a  href="http://dev.eclipse.org/blogs/francis/" onclick="javascript:pageTracker._trackPageview('/external/dev.eclipse.org/blogs/francis/');" >Common Navigator and Other Things by Francis Upton</a></li>
</ul>
<h3>Digital Paper Napkin by Michael D. Elder</h3>
<p>A basic set of introduction articles written in 2006. The articles introduce contribution to the resource-based CNF viewer displaying the content of the property files. A good overview to get into the subject. The blog seems to be dead, according to many spam comments.</p>
<ul>
<li>
<a  href="http://scribbledideas.blogspot.com/2006/05/building-common-navigator-based-viewer.html" onclick="javascript:pageTracker._trackPageview('/external/scribbledideas.blogspot.com/2006/05/building-common-navigator-based-viewer.html');" >Part 1 &#8211; Defining the Viewer</a></li>
<li>
<a  href="http://scribbledideas.blogspot.com/2006/05/building-common-navigator-based-viewer_22.html" onclick="javascript:pageTracker._trackPageview('/external/scribbledideas.blogspot.com/2006/05/building-common-navigator-based-viewer_22.html');" >Part 2 &#8211; Adding Content</a></li>
<li>
<a  href="http://scribbledideas.blogspot.com/2006/06/building-common-navigator-based-viewer.html" onclick="javascript:pageTracker._trackPageview('/external/scribbledideas.blogspot.com/2006/06/building-common-navigator-based-viewer.html');" >Part 3 &#8211; Configuring Menus</a></li>
<li>
<a  href="http://scribbledideas.blogspot.com/2006/06/building-common-navigator-based-viewer_18.html" onclick="javascript:pageTracker._trackPageview('/external/scribbledideas.blogspot.com/2006/06/building-common-navigator-based-viewer_18.html');" >Part 4 &#8211; Object Contribution</a></li>
<li>
<a  href="http://scribbledideas.blogspot.com/2006/06/building-common-navigator-_115067357450703178.html" onclick="javascript:pageTracker._trackPageview('/external/scribbledideas.blogspot.com/2006/06/building-common-navigator-_115067357450703178.html');" >Part 5 &#8211; Action Providers</a></li>
<li>
<a  href="http://scribbledideas.blogspot.com/2006/06/what-does-common-navigator-framework.html" onclick="javascript:pageTracker._trackPageview('/external/scribbledideas.blogspot.com/2006/06/what-does-common-navigator-framework.html');" >High Level Requirement on CNF</a></li>
<li>
<a  href="http://scribbledideas.blogspot.com/2006/05/where-do-we-go-from-here.html" onclick="javascript:pageTracker._trackPageview('/external/scribbledideas.blogspot.com/2006/05/where-do-we-go-from-here.html');" >Further directions</a></li>
<li>
<a  href="http://scribbledideas.blogspot.com/2006/07/pdf-versions-now-available.html" onclick="javascript:pageTracker._trackPageview('/external/scribbledideas.blogspot.com/2006/07/pdf-versions-now-available.html');" >PDF Versions</a></li>
<li>
<a  href="http://scribbledideas.blogspot.com/2006/07/label-decorators-in-common-navigator.html" onclick="javascript:pageTracker._trackPageview('/external/scribbledideas.blogspot.com/2006/07/label-decorators-in-common-navigator.html');" >Label decorators</a></li>
</ul>
<h3>Eclipse from the bottom up by Michael Valenta</h3>
<p>A good hint is to look on the implementation of the 
<a  href="http://eclipselowdown.blogspot.com/2006/05/common-navigator-and-synchronize-view.html" onclick="javascript:pageTracker._trackPageview('/external/eclipselowdown.blogspot.com/2006/05/common-navigator-and-synchronize-view.html');" >CVS Synchronize View</a>. Pretty old content, but still valid.</p>
<h3>vAAni by Aashish Patil</h3>
<p>Weakly formatted article, providing some hints on how to implement a not &#8220;resource only&#8221;-based CNF viewer. Still, the information from here helped me to create a complete 
<a  href="http://aashishpatil.blogspot.com/2006/07/displaying-non-resource-content-using.html" onclick="javascript:pageTracker._trackPageview('/external/aashishpatil.blogspot.com/2006/07/displaying-non-resource-content-using.html');" >non-resource based CNF viewer described here.</a></p>
<h3>Other</h3>
<p>Thanks to 
<a  href="http://dev.eclipse.org/blogs/francis/" onclick="javascript:pageTracker._trackPageview('/external/dev.eclipse.org/blogs/francis/');" >Francis Upton</a>, who reviewed the post and corrected some mistakes and misconceptions.</p>
<p>Special thanks to 
<a  href="http://bairdphotos.com/" onclick="javascript:pageTracker._trackPageview('/external/bairdphotos.com/');" >Michael &#8220;Mike&#8221; L. Baird</a> for the beautiful 
<a  href="http://www.flickr.com/photos/mikebaird/3009401040/" onclick="javascript:pageTracker._trackPageview('/external/www.flickr.com/photos/mikebaird/3009401040/');" >picture of the compass</a>. I found the picture on Google Image Search and became a big fan of his pictures (some of you know about 
<a  href="http://www.flickr.com/photos/sza/" onclick="javascript:pageTracker._trackPageview('/external/www.flickr.com/photos/sza/');" >my photo passion</a>). It is funny that from all places in the world, the picture is shot in Morro Bay, about 200 Miles away from where I&#8217;m located now. It is also funny that Mike is a computer science guy, even if retired&#8230;<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.techjava.de/topics/2009/04/eclipse-common-navigator-framework/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>RCP Help System</title>
		<link>http://www.techjava.de/topics/2009/04/rcp-help-system/</link>
		<comments>http://www.techjava.de/topics/2009/04/rcp-help-system/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 22:04:23 +0000</pubDate>
		<dc:creator>Simon Zambrovski</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Enterprise Systems]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[rcp]]></category>

		<guid isPermaLink="false">http://www.techjava.de/?p=241</guid>
		<description><![CDATA[Eclipse Platform provides a help system that can be used during creation of the help content for your application. It is very convenient while used inside of the IDE, but needs a special approach if used in the RCP. This article tries to gather the information which may be useful. Adding Help Support Basic preparations [...]]]></description>
			<content:encoded><![CDATA[<p><img style="margin: 10px; float:right" title="Eclipse help" src="http://www.techjava.de/wp-content/uploads/help-150x150.jpg" alt="help" width="150" height="150" />Eclipse Platform provides a help system that can be used during creation of the help content for your application. It is very convenient while used inside of the IDE, but needs a special approach if used in the RCP. This article tries to gather the information which may be useful.</p>
<h2>Adding Help Support</h2>
<h3>Basic preparations</h3>
<p>As discussed in Eclipse RCP Book and RCP Articles, the help system is not a part of the RCP-Runtime and should be added separately. The question arises where to add at to? If you follow the best practices for packaging of RCP applications, you should have at least one product and the top level feature defined (See Rule 1 of Chapter 23 of Eclipse Rich Client Platform). The top level feature includes the branding plug-in (containing the product definition) and refer to other features (like <code>org.eclipse.rcp</code>, and your functional features). In order to add the help system, you need to add the <code>org.eclipse.help</code> feature in this list.</p>
<h3>Platform help buttons</h3>
<p>There are several predefined buttons (actions) you can use for calling the help system. These are:</p>
<ul>
<li>Help Contents</li>
<li>Help Search</li>
<li>Dynamic Help</li>
</ul>
<p>In order to activate them from your <code>ApplicationActionBarAdvisor</code> just call:</p>
<pre class="brush: java; title: ;">
private IWorkbenchAction helpContentsAction;
private IWorkbenchAction helpSearchAction;
private IWorkbenchAction dynamicHelpAction;

protected void makeActions(IWorkbenchWindow window)
{
helpContentsAction = ActionFactory.HELP_CONTENTS.create(window);
dynamicHelpAction = ActionFactory.DYNAMIC_HELP.create(window);
helpSearchAction = ActionFactory.HELP_SEARCH.create(window);
register(helpContentsAction);
register(helpSearchAction);
register(dynamicHelpAction);
}
</pre>
<p>If you want to do the same declarative, you have to create commands that use the following <code>actionDefinitionId</code>s:</p>
<ul>
<li>org.eclipse.ui.help.helpContents</li>
<li>org.eclipse.ui.help.helpSearch</li>
<li>org.eclipse.ui.help.dynamicHelp</li>
</ul>
<p>The same ids are required for registration of key bindings (e.G. Ctrl + F1, Shift + F1, F1 on Win32). Apparently, since these actions adjust their status depending on the state of the system and the plug-ins installed, I could not figure out how to force them to be enabled, when installed in a declarative way. Since they are still provided as <code>ActionFactory</code> (which is legacy due to the changes introduced by new Command Framework), they should be further activated from the <code>ApplicationActionBarAdvisor</code>.</p>
<h2>Context-Sensitive Help UI Integration</h2>
<p>The Eclipse platform provides not only the help system, but also support the so-called Context-Sensitive Help (a very confusing name, because the context is only the widget, and not the data). In the following, it is shown, how the connection between the widgets and the help system can be established.</p>
<h3>The big picture</h3>
<p>The content already defined in the help system can be pointed at from various places in the your application using the so-called help contexts, which on one hand point to the places in the documentation and on the other hand can be assigned to widgets in the application UI.</p>
<h3>Establishing contexts</h3>
<p>In order to assign the help context to a widget the invocation of the method <code>PlatformUI.getWorkbench().getHelpSystem().setHelp(Control control, String contextId);</code> is used. The contextId is a <strong>full-qualified string constructed from the pluginId and the local context name</strong>. The context name should be unique for this plug-in (usage of non-unique ids leads to a merge of different subjects, which is a nice feature, but may be not desired). I prefer to create the convenience method for this invocation:</p>
<pre class="brush: java; title: ;">
public class HelpUtil
{
public static void setHelp(Control control, String localContextId)
{
if (localContext == null || control == null) return;
PlatformUI.getWorkbench().getHelpSystem().setHelp(control,
Activator.PLUGIN_ID + &quot;.&quot; + localContextId);
}
}
</pre>
<p>There are also methods for registration of other SWT widgets (Control, IAction, Menu, or MenuItem) in the help system, which can be handled by the overloaded version of the method. The invocation of the convenenience method usually looks like: <code>HelpUtil.setHelp(composite, "newWizardPage")</code> and should be invoked from the createControls() of the correponding element. Please note, that the &#8220;newWizardPage&#8221; is a local name, and the pluginId is added to it inside of the conveninece method. Widgets that do not get focus should not be assigned context ids, since they will never trigger a context-sensitive help</p>
<h3>The declarative part</h3>
<p>As usual in Eclipse, there is a declarative part, that connects the context ids, set up in the code with the help pages. The connection is established by a special XML file. In order for the platform to know, where to find the file, there is an extension point (<strong>org.eclipse.help.contexts</strong>), that you need to contribute to:</p>
<pre class="brush: xml; title: ;">
&lt;extension point=&quot;org.eclipse.help.contexts&quot;&gt;
&lt;contexts file=&quot;contexts.xml&quot; plugin=&quot;de.techjava.rcp.ui&quot; /&gt;
&lt;/extension&gt;
</pre>
<p>The <strong>file</strong> attribute specifies the full path to the XML file containing the context definition. The <strong>plugin</strong> attribute is optional and declares for which plugin the context definition applies. Please note, that if the plugin attribute is ommited, the context names used in the context definition file will be seen as local to the plugin they are declared in. For example, if you want to support the context-sensitive help in plug-in <code>de.techjava.rcp.xyz</code> then your in-code definition of the context should define full qualified context names like <code>de.techjava.rcp.xyz.context1</code>. Either you use the extension point (org.eclipse.help.contexts) in the plugin.xml of the de.techjava.rcp.xyz plugin.xml, or if you put the usage of the extension point into some other plugin (e.G. central for all help), you must provide the plugin attribute with value &#8220;de.techjava.rcp.xyz&#8221;.  This issue is badly discussed in the help guide and is a little confusing. In the context definition file the contexts are defined as follows:</p>
<pre class="brush: xml; title: ;">
&lt;contexts&gt;
&lt;context id=&quot;context1&quot; title=&quot;My first context&quot;&gt;
&lt;description&gt;This is a test context&lt;/description&gt;
&lt;topic href=&quot;path/context1.htm&quot; label=&quot;Context1&quot;/&gt;
&lt;/context&gt;
...
&lt;/contexts&gt;
</pre>
<h3>Wizards and Dialogs</h3>
<p>Wizards are used with or without dialog.</p>
<p>The call of the <code>Wizard#setHelpAvailable(true)</code> shows the Help button.<br />
The call of the <code>WizardDialog.setHelpAvailable(true);</code> shows the small sexy round Question button.</p>
<h2>References</h2>
<ul>
<li>
<a  href="http://www.amazon.com/Eclipse-Rich-Client-Platform-Applications/dp/0321334612/ref=sr_1_2?ie=UTF8&amp;qid=1235103097&amp;sr=8-2" onclick="javascript:pageTracker._trackPageview('/external/www.amazon.com/Eclipse-Rich-Client-Platform-Applications/dp/0321334612/ref=sr_1_2');" >Eclipse Rich Client Platform: Designing, Coding, and Packaging Java(TM) Applications (Eclipse Series)</a></li>
<li>
<a  href="http://www.eclipse.org/articles/article.php?file=Article-DynamicCSH/index.html" onclick="javascript:pageTracker._trackPageview('/external/www.eclipse.org/articles/article.php');" >Dynamic User Assistance in Eclipse-Based Applications (Eclipse Article)</a></li>
<li>
<a  href="http://www.eclipse.org/articles/article.php?file=Article-AddingHelpToRCP/index.html" onclick="javascript:pageTracker._trackPageview('/external/www.eclipse.org/articles/article.php');" >Adding Help Support to a Rich Client Platform (RCP) Application (Eclipse Article)</a></li>
<li>
<a  href="http://www.eclipse.org/articles/Article-Online%20Help%20for%202_0/help1.htm" onclick="javascript:pageTracker._trackPageview('/external/www.eclipse.org/articles/Article-Online%20Help%20for%202_0/help1.htm');" >Contributing a little help (Eclipse Article)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.techjava.de/topics/2009/04/rcp-help-system/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>RCP with multiple application windows</title>
		<link>http://www.techjava.de/topics/2009/01/rcp-with-multiple-application-windows/</link>
		<comments>http://www.techjava.de/topics/2009/01/rcp-with-multiple-application-windows/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 21:25:37 +0000</pubDate>
		<dc:creator>Simon Zambrovski</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[rcp]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://www.techjava.de/?p=228</guid>
		<description><![CDATA[Eclipse RCP by default promotes the usage of a single application window with multiple views and editors inside. This default can be changed to multi-windowed application. The platform API offers several methods to operate with multiple application windows: package org.eclipse.ui; ... public interface IWorkbench ... { /** * Retrieves the number of opened windows */ [...]]]></description>
			<content:encoded><![CDATA[<p>
<a  href="http://www.flickr.com/photos/33910833@N03/3195292012/" target="_blank" onclick="javascript:pageTracker._trackPageview('/external/www.flickr.com/photos/33910833@N03/3195292012/');" ><img style="margin: 10px; border: 0px; float: right;" src="http://farm4.static.flickr.com/3267/3195292012_4b4405c777_m.jpg" border="0" alt="" width="240" height="150" /></a><br />
Eclipse RCP by default promotes the usage of a single application window with multiple views and editors inside. This default can be changed to multi-windowed application. The platform API offers several methods to operate with multiple application windows:</p>
<pre class="brush: java; title: ;">
package org.eclipse.ui;
...
public interface IWorkbench ...
{
/**
* Retrieves the number of opened windows
*/
public int getWorkbenchWindowCount();
/**
* Retrieves the array of opened windows
*/
public IWorkbenchWindow[] getWorkbenchWindows();
/**
* Openes a new window with given perspective
*/
public IWorkbenchWindow openWorkbenchWindow(String perspectiveId,
IAdaptable input) throws WorkbenchException;
/**
* Performs a perspective switch in a given window
*/
public IWorkbenchPage showPerspective(String perspectiveId,
IWorkbenchWindow window, IAdaptable input)
throws WorkbenchException;
...

}</pre>
<p>Using this API, opening of new windows seems simple. For example one could define a perspective, that is always opens in a new window.</p>
<p>Closing windows is generally performed by calling <code>close</code> method on the <code>IWorkbenchWindow</code> instance.</p>
<pre class="brush: java; title: ;">
package org.eclipse.ui;
...
public interface IWorkbenchWindow ...
{
  /**
   * Closes the window
   */
  public boolean close();
}
</pre>
<p>Unfortunaly, there is no elegant way to find out which window are you in. A workaround which uses Eclipse internal API works fine for <code>WorkbenchWindow</code>, which is a standard platform implementation of the <code>IWorkbenchWindow</code> interface.</p>
<pre class="brush: java; title: ;">
/**
 * Determines if the window is a root window
 * @param window a window to be checked
 * @return true, if the window is considered to be a root window
 */
public static int getWindowId(IWorkbenchWindow window)
{
// HACK: note this could change in future
  if (window != null &amp;&amp; window instanceof WorkbenchWindow))
  {
    return ((WorkbenchWindow)window).getNumber();
  }
  return -1;
}
</pre>
<p>The initial application window gets the id 1. The lookup in the implementation reveals that the internal method finds the smalles unused positive number and assigns it to the newly opened window. If you do not want to rely on this algorithm, just hash the newly created windows by they ids.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techjava.de/topics/2009/01/rcp-with-multiple-application-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

