Eclipse Yoxos Services Downloads Blogs About
Home > Blogs >

Posts Tagged ‘rcp’

on Jul 8th, 2011Single-Sourcing with declarative services

In my last blog post I introduced the idea of using OSGi services for single sourcing a RAP/RCP application. I think this approach is quite elegant, but it has one major drawback. When you use normal OSGi services in your application you will mix your application code with the OSGi Framework code everytime you reference or register a service. Not only does this look ugly, it’s also hard to test.

Luckily there is a lifesaver called Declarative Services. (For those of you who are familiar with declarative services, skip to the next paragraph.) The OSGi declarative services (ds) are specified in the OSGi compendium so they are standardized. It’s just a component framework on top of OSGi services. It gives you the ability to register and consume services in a declarative way using some xml files and simple accessors in your classes.

I’ll take the same example from in my last blog post and use it to look at ds for single sourcing.  In that blog, we single sourced a themed button widget.  We can use the same interfaces and service implementations, and the only differences will be how the services will be registered and referenced.

First, let’s take a look at the service registration. In our example we need to register the services in the rap and rcp bundles. It’s common practice to put all service declarations in a folder called OSGI-INF in the root of your project. Once you’ve created this folder you can create a “component definition” using the wizard. After this you need to fill in three things: first, the filename of your choice, second, the component name which needs to be unique in the framework and third, the component itself.

componentWizard Single Sourcing with declarative services

The component is the fully qualified classname of your implementation. In the case of service registration, it’s your service implementation. To add the service registration, press ‘Finish’ to open the component editor. We only want to register a service, so we jump to the service tab. In the bottom section you can add the service interface.

To understand what happens in the background let’s recap what we have declared. We defined a service interface, a service implementation, a component name and a filename. The component framework takes care of instantiating the service implementation and registering it as a service using the service interface. It registers the component using the component name. The filename will be automatically added to your bundle’s manifest. That’s all, the next time we start this bundle the service will be registered. Your component definition should look something like this:

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="com.eclipsesource.app.rap.service.provider">
   <implementation class="com.eclipsesource.app.rap.RAPSingelSourcingService"/>
   <service>
      <provide interface="com.eclipsesource.app.ISingleSourcingService"/>
   </service>
</scr:component>

Now we get to the service referencing. As you recall, we need to reference the service in our app bundle. Therefore, we need to create a component in this bundle too. In this example I decided to reference the service in the bundle’s activator and provide it with a static accessor. But you can reference it wherever you want. In this case the component is our Activator. The only difference to the service registration is in the service tab of the component editor. Instead of providing a service, we are now referencing one. You can do this by clicking ‘Add’ in the upper section of this tab.

serviceReferencing Single Sourcing with declarative services

After this you need to declare the Interface of the service you want to reference, in our case the ISingleSoucingService. The question is now, “how does this service finds its way to the Activator?” The answer is binding methods. In the reference you can specify a bind and an unbind method e.g. setService and unsetService. You need to add these methods to your activator with the service as a parameter. That’s all – we are referencing the service now. Your component should look something like this:

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" enabled="true" name="com.eclipsesource.app.servic.consumer">
   <implementation class="com.eclipsesource.internal.app.Activator" />
   <reference bind="setSingleSourcingService" cardinality="1..1" interface="com.eclipsesource.app.ISingleSourcingService" name="ISingleSourcingService" policy="dynamic" unbind="unsetSingleSourcingService"/>
</scr:component>

The last thing we need is a little bit of glue to bring these components together. The glue is in the org.eclipse.equinox.ds bundle. This bundle contains the component framework implementation, and to make everything work together you need to add this bundle to your launch configuration. It’s not included in the RAP target components, but you can download it using the Indigo release site or the Equinox SDK.

I added a branch called “ds” to the repository on github from the last blog. This branch represents an example implementation using ds for single sourcing.

Have fun declaring services icon wink Single Sourcing with declarative services

on Jun 20th, 2011Using OSGi services to single-source an RCP and RAP Application

Probably one of RAP’s best known features is its single-sourcing capabilities. Some time ago we created a guide on Single-Sourcing RCP and RAP applications. The guide recommended a technique where a facade and fragments were used to invoke the RCP or RAP implementation during runtime. With this post I want to show you how to achieve the same the OSGi way.

For single-sourcing a RAP or RCP application, its straightforward to use the power of OSGi because it’s included in both platforms out-of-the-box. OSGi has a central concept called services which are simply POJOs and are used to allow communication between modules. And, you can register or resolve services at any time in your code.

The basic Idea behind using OSGi services for single-sourcing is as follows. We need to extract all the things that vary into separate, platform specific bundles. To use the different implementations, we have to create an interface in a “common” bundle that contains the methods we want to use. The platform specific bundles have to register an implementation of this interface as a service. In the “common” bundle we can reference the registered services and use them to get the platform specific stuff. More specifically, we register a RAP implementation in a “rap” bundle and an RCP implementation in an “rcp” bundle. The only thing we need to do then is to start the right bundles on the associated platform to get the right service.

With this solution we can extract the platform specific stuff into separate bundles and we don’t have to rely on fragments. So enough talking. Let’s look at some code. I decided to create a very simple single-sourcing interface which can be used to get the WidgetUtil.CUSTOM_VARIANT constant value. This constant exists only in RAP so, it’s a good example for showing how to handle the differences.

public interface ISingleSourcingService {
  String getCustomVariantString();
}

I have created three bundles: one that contains the application which is entitled “com.eclipsesource.app” and one for each platform. These are called “com.eclipsesource.app.rap” and “com.eclipsesource.app.rcp”. Both platform bundles implement the interface.
RAP:

  @Override
  public String getCustomVariantString() {
    return WidgetUtil.CUSTOM_VARIANT;
  }

RCP:

  @Override
  public String getCustomVariantString() {
    // There are no custom variants in RCP
    return "";
  }

And both bundles are registering the service in their Activator during the start method call.

  public void start( BundleContext bundleContext ) throws Exception {
    Activator.context = bundleContext;
    registration = context.registerService( ISingleSourcingService.class.getName(),
                                            new RAPSingelSourcingService(),
                                            null);
  }

When it comes to using the service in the common “app” bundle we can use a ServiceTracker to get the service implementation (you can also use DS).

  private ISingleSourcingService getSingleSourcingService() {
    // We use a tracker to get the service. We also can use DS to get it.
    Bundle bundle = FrameworkUtil.getBundle( getClass() );
    BundleContext context = bundle.getBundleContext();
    ServiceTracker tracker
      = new ServiceTracker( context,
                            ISingleSourcingService.class.getName(),
                            null );
    tracker.open();
    ISingleSourcingService service = tracker.getService();
    tracker.close();
    return service;
  }

The only thing we have to do now is to create two launch configurations which contain the associated platform-specific bundle.

That’s it! You can find the sources in this github repository. Have fun using OSGi services to single-source applications.

 

on Dec 18th, 2010A new Google Maps Widget for SWT and RAP

Your early Christmas present from EclipseSource: a custom-widget that displays, controls and reacts to a Google-Map. While there have been similar widgets before, this one is the first (as far as I know) that runs in RAP and RCP without any changes.

gmapb 300x210 A new Google Maps Widget for SWT and RAP gmapd 300x167 A new Google Maps Widget for SWT and RAP

[ Download ] (You also need RAP 1.4M4.)

Creating custom-widgets for RAP is no easy task. You need to be familiar not only with Java and JavaScript, but with a lot of RAP’s complex internals as well. It’s a lot of work, even if you simply want to integrate an existing javascript-application or library.

That’s now a lot easier, using the much improved browser-widget. We recently added some missing features, tested different scenarios and fixed known bugs. This makes it an ideal platform to insert javascript-based applications with almost no overhead for the programmer. You simply call JavaScript from Java and vice versa! And the bonus: these custom-widgets can (under certain conditions) also run in RCP, as demonstrated here.

The widget is currently hosted at github, so feel free to check it out, use it in your application or fork it to add your improvements. Also check out Holger Staudachers carousel widget for RAP to see another example.

“Traditional” custom widgets for RAP are by no means obsolete with this, as they still have certain advantages (slightly better performance, themeability, can use rap client components). But for the cases mentioned above, the browser widget can make your life much easier!

Happy Holidays!

on Dec 8th, 2010JQuery, Eclipse RAP and a carousel

A few weeks ago, my colleague Ralf Sternberg, announced that RAP supports a JQuery integration. What we still needed to do was to create an example that shows how to integrate some JQuery stuff into RAP. Yesterday I took a little time to work on it. I used the JQueryUI Carousel widget as a base. Two hours later the integration and a book store example were completed. You can see the result in the screencast below.

The special thing about this integration is that it uses the SWT Browser widget with BrowserFunctions. This makes this type of integration very lightweight and simple to develop. As I mentioned before, two hours were enough to create the example. Of course, besides JQuery you can integrate all kinds of Frameworks, Mashups and other things that are running in a browser. Ian Bull highlighted this by developing a GMap example. The cool thing about this technique is that it works with RAP (RWT) and RCP (SWT).

I made the source code publicly available via github. You can find the repository here. It would be great to see some other examples. So, please feel free to post your examples in a comment.

on Oct 21st, 2010Eclipse and RCP Apps on Apple’s Mac App Store

Yesterday Apple announced the App Store for the Mac OS X Lion operating system, which will be released mid-2011. You probably know the App Store from the iPhone, iPod or the iPad. It’s a really cool way to install Apps. From a developer point of view it’s also interesting because a huge amount of the marketing for an App is done by the App Store for you.

appstore hero20101020 Eclipse and RCP Apps on Apples Mac App Store

For me as an Eclipse developer the first thing that came to my mind while watching yesterday’s Apple keynote was, “It would be so cool if I could install Eclipse or RCP-based Apps directly on my Mac with the App Store.”  We know that in the past Apple hasn’t been very open to Java-based applications. But, since then, they have given up their strange licensing policy and allow Apps to be written in other technologies.

As a result of this, it should be possible to ship Java-based applications with the App Store. Of course, this is just my opinion and we have to make sure that Apple will allow it.  But, if it’s allowed, this should be the last big hurdle before we can investigate the App Store for Eclipse and RCP-based Apps. Imagine:  installing, auto updating, user reviews, marketing and ratings all under one hood. If we do this right, it could create a synergistic relationship between the App Store and the Eclipse Marketplace.   For example, promote once and your application could show up on the Marketplace and the App Store.

So, it can’t be too early to start looking at the possibilities. I opened an Eclipse Bug to support the Mac App Store. Maybe you’re interested in this topic and want to help make it real. The bug id is 328317.

on Jul 16th, 2010Helios DemoCamp Darmstadt review

Two days ago was the Helios DemoCamp in Darmstadt at Deutsche Telekom.  I think it was a very successful evening with a whole bunch of good talks. Two of them are very noteworthy.

The first one was presented by Marcel Bruch. He talked about the Eclipse Code Recommenders project which he’s working on at TU Darmstadt. The basic idea behind this project is to provide a way to recommend code. He used the analogy of the Amazon online store. When you buy a book you always get a recommendation along the lines of, “People who bought this book also found this one interesting…”. The Code Recommenders does exactly the same just with code.  Watch the great screencast the Code Recommenders Team provides if you don’t want to take my word for it.

marcel 2 150x150 Helios DemoCamp Darmstadt review marcel 1 150x150 Helios DemoCamp Darmstadt review

Another especially noteworthy demo for me was presented by Stefan Lay. He demo’d the Eclipse Git Team provider called EGit.  In addition to the tooling he presented Gerrit. Gerrit is an automated review tool for Git. The scenario he presented was to push some changes to a remote repository. The changes were caught by gerrit to be reviewed.   With those changes however, an automated build failed and gerrit sent an automated message that the changes couldn’t be applied because they broke the build. I think this will make the workflow much easier for code review and keeping the repository stable. The EGit project already uses Gerrit for their productive work.

Lay 1 150x150 Helios DemoCamp Darmstadt review Lay 2 150x150 Helios DemoCamp Darmstadt review

To put it all in a nutshell it was a very cool DemoCamp with 120 attendees and nice buffet afterwards. At this point I want to thank Ralph Müller and the Foundation who organized a spontanous Eclipse Stammtisch after the DemoCamp. It was great to talk to all the guys individually. The bad thing about this is that the evening went by too fast. But there also a good thing. Most of those people will also attend the Eclipse Summit Europe in November and we can meet again.

stammtisch 2 150x150 Helios DemoCamp Darmstadt review stammtisch 1 150x150 Helios DemoCamp Darmstadt review

on May 13th, 2010Using Equinox Security in RCP and RAP

I finally had the time to care about one of my outstanding tasks – provide a tutorial and example how to use Equinox Security. While the tutorial was initially targeted for RAP users, I also added a launch config and a target definition for RCP as the code is the same for both runtimes. The tutorial will provide some hints and pointers how to setup your login procedure, like shown below:

rapsec login Using Equinox Security in RCP and RAP

After logging in (hint, hint), you’re able to inspect the currently active Subject. I made up this example to be as simple as possible to demonstrate the key concepts of Equinox Security, and not the ones from RAP/RCP.

rapsec subject Using Equinox Security in RCP and RAP

As I said, you can either choose between RAP as runtime (above) or RCP (below).

rcpsec subject Using Equinox Security in RCP and RAP

In addition to the authentication mechanism, I wrote a pretty simple LoginModule to show how to connect your authentication process to an alternative backend (eg. LDAP, Kerberos, …).

As I put the tutorial into the Eclipse wiki, I encourage everyone to extend the tutorial with hints, tricks or ideas what you can do with Equinox Security. Hope the tutorial helps to get up to speed how to use secure your RCP/RAP applications.

on Apr 13th, 2010Eclipse RCP 2nd Edition going to press!

EclipseRCP cover medium Eclipse RCP 2nd Edition going to press!

We are very pleased to report that the long awaited 2nd edition of the Eclipse RCP book (http://eclipsercp.org) is going to the presses on Thursday, April 15th. That means it should be in the stores by the end of the month. Of course, you don’t have to wait, you can pre-order from Amazon or read it online at Safari. Check out the book website for more info.

In addition to the snazzy new cover, this book is an update of the original content to include new technologies, updated workflows and more detail. Here is the marketing blurb from the back cover…

In Eclipse Rich Client Platform, Second Edition, three Eclipse Rich Client Platform (RCP) project leaders show how to use Eclipse 3.5 (“Galileo”) to rapidly deliver cross-platform applications with rich, native-feel GUIs.

The authors fully reveal the power of Eclipse as a desktop application development platform; introduce important new improvements in Eclipse 3.5; and walk through developing a full-featured, branded RCP application for Windows, Linux, Mac, and other platforms—including handheld devices and kiosks.

Drawing on their extensive experience, the authors cover building, refining, and refactoring prototypes; customizing user interfaces; adding help and software management features; and building, branding, testing, and shipping finished software. They demonstrate current best practices for developing modular and dynamically extensible systems, using third-party code libraries, packaging applications for diverse environments, and much more.

For Java programmers at all levels of experience, this book

  • Introduces important new RCP features such as p2, Commands, and Databinding
  • Thoroughly covers key RCP-related technologies such as Equinox, SWT, JFace, and OSGi
  • Shows how to effectively brand and customize RCP application look-and-feel
  • Walks through user interface testing for RCP applications with SWTBot
  • Illuminates key similarities and differences between RCP and conventional plug-in development

Hands-on, pragmatic, and comprehensive, this book offers all the real-world, nontrivial code example working developers need—as well as “deep dives” into key technical areas that are essential to your success.

on Mar 19th, 2010Helios M6 RCP package

The new EPP packages for Helios M6 are uploaded to the download area and just need some more hours to be distributed to the Eclipse download mirrors until we can make them available for the public from eclipse.org/downloads. The mirroring is important, because otherwise the eclipse.org uplink would be entirely saturated and no one could get the Helios M6 bits in time before EclipseCon.

In the meantime, I’d like to highlight some additions that I recently did as a package maintainer of the RCP package. (If you don’t know what a package maintainer is you should consider joining my talk on Monday about ‘Building EPP packages‘.)

  • git is becoming more and more popular at Eclipse and EGit is always one of the first plug-ins that I am installing whenever I unpack a new Eclipse milestone on my computer. The logical step: Include EGit in my RCP package because I think that I am not the only one who needs this tool.
  • Another addition that I recently made is the RAP tooling. My daily work has changed and in the last months I am doing more RAP development than RCP development. I am not entirely sure if one needs both in one package, maybe RAP needs to go into its own package, but so far I think both technologies  complement each other. I am happy to get feedback – see bug 230357.
  • Last but not least: The Marketplace Client (MPC) is included to allow early feedback – the developers of this nice tool need your feedback to bring it into the best possible shape for Helios!

Now let’s wait until the packages are available… and I need to go back preparing my EclipseCon slides.

on Feb 10th, 2010redView at EclipseSource

We recently had a workshop on redView with the developers of the project, probably many of you know ekke. We wanted to evaluate it and gain a better understanding if we could use it in the context of a project in the insurance space.

redView looks pretty promising, and although personally I am not a big fan of modeling and code generation there might be a sweet spot for redView for people who have tons of forms to fill in data.

One really nice thing about redView is that they created a detailled install instruction (a yoxos profile could probably help here), and a bunch of demos to get started.

http://redview.wordpress.com/howto/examples
http://redview.wordpress.com/howto/installation/
http://sourceforge.net/projects/redview/files/

P.S: The obligatory question about single sourcing redView has been discussed, and as redView is EMF + Riena it looks feasible to get redViews working in RAP. Even the visual form designer imposes no hurdles that could not be overcome (plain SWT, no GEF).

© EclipseSource 2008 - 2011