Rich Client Platform

Video and Eclipse

March 3rd, 2009  |  Published in Rich Client Platform, Tips

For an upcoming project I need to be able to show Flash videos inside of an RCP application. Java has never been known for its multimedia functionality so I didn’t have very high hopes.

Fortunately, with Java Media Components things seem to be moving in the right direction. JMC is an API that allows you to play media files using the video functionality of the underlying operating system (there is work being done to provide cross-platform codecs along with the API, but it’s unclear how extensive this will be). JMC is distributed as part of the JavaFX platform, but it can function independently inside of a regular Swing application.

Using this recent article as a guide, I managed to create an Eclipse plug-in that contributes a very rudimentary video player view to Eclipse or any other RCP application. If you’d like to try it yourself, click here for the source code (exported project). Note that the current code only works on Windows.

Video playing inside the Eclipse IDE

Above you can see a Flash video of Wipeout playing inside of my Eclipse IDE. Wipeout is my 5-year old daughter’s favorite show (if people are falling down, she’s laughing), so after 20 years as a software developer I’ve finally written some code she’d be interested in!

One thing to note is that JMC relies on the codecs installed on your machine. There have been some complaints that JMC is not finding or utilizing the codecs most people have installed, and hopefully this situation will improve. If you find that you’re getting MediaUnsupportedException errors when opening files, you may want to install a codec pack. The CCCP pack seems to work for most people.

Adding the Progress View to your RCP application

February 16th, 2009  |  Published in Rich Client Platform, Tips

Last week Prakash G.R. wrote an excellent post on Using progress bars. This is definitely a post that I’ll be referring my students to in the future. There is still one missing piece to the progress bar puzzle, though, and that is how to add the Progress View itself to your application.

You might think that this view would appear on its own when requested through the UI, and in my opinion this is the way things should be (this has been discussed in past Bugzilla entries). For instance, your users may see a job running in the status bar of your RCP application, like this:

progress11

When the user clicks on the conveyor belt icon, they would expect to see a detailed progress view allowing them to cancel the job, like this:

progress2

So how do you get this working? The answer is not what you might think. Normally, you would add a view by finding the view class and creating a new view extension. But for the Progress View, things are a bit different. The ProgressView class itself is internal and is not intended to be referenced directly. It is exposed, however, through an extension factory. The XML to create the view extension looks like this:

   <extension
         point="org.eclipse.ui.views">
      <view
            name="Progress View"
            icon="icons/pview.gif"
            category="org.eclipse.ui"
            class="org.eclipse.ui.ExtensionFactory:progressView"
            id="org.eclipse.ui.views.ProgressView">
      </view>
   </extension>

The last piece we need to make this work is the view icon, which can be found in the org.eclipse.ui.ide plug-in (not part of the RCP SDK). The actual file in this plug-in is icons/full/eview16/pview.gif. You’ll need to copy this icon into your own plug-in and reference it in the view extension.

So while not extremely straightforward, it’s not that difficult either. Interestingly, there are a variety of other things you can add to your application through the same extension factory mechanism. If you’d like to find out more, check out the constants in the ExtensionFactory class.

Making Music with Eclipse RCP

December 18th, 2008  |  Published in Applications, Rich Client Platform

I’m always on the lookout for Eclipse Rich Client Platform applications that push boundaries. RCP is much too often associated with the Eclipse IDE itself, and this leads us to think that RCP applications need to be IDE-like. But there are many more uses to which RCP can be put, and I think we’re still only beginning to scratch the surface.

For example, check out Neck Diagrams (nice web site, by the way!), an RCP application that allows guitarists to create chord boxes and neck diagrams using a visual editor. I’m not much of a musician myself, but this seems like a great tool. What I really like, though, is how this program stretches the idea of what we think of as an “RCP application”.

neckdiagrams11

This is also a great example of software created by a single developer. I love that RCP makes it possible for a solo developer to realize their vision and bring a product to market quickly.

neckdiagrams2

If you’re interested in seeing this software in action, check out the screencast.

Perspective Layouts – Programmatic vs Declarative

December 11th, 2008  |  Published in Rich Client Platform, Tips

One issue that developers new to RCP face is whether to add UI elements programmatically or declaratively. In my experience, most initially choose the programmatic approach because it seems more familiar. You know, why mess with extension points when you can just code it up and be done with it.

But it’s almost always better to do things declaratively through extension points, the main reason being that doing so allows you leverage the power of RCP as a modular user interface framework. To illustrate this, let’s look at our options for laying out perspectives.

Programmatic Layout = Centralized / Hard Coded

Here is the simplest code needed to add a view to a perspective programmatically. To do so, we implement the IPerspectiveFactory interface and add a view using its string id.

public class MyPerspectiveFactory implements IPerspectiveFactory {

	public void createInitialLayout(IPageLayout layout) {
		layout.addView(MyView.ID, IPageLayout.BOTTOM, 0.5f, layout.getEditorArea());
	}

}

The problem here is that we’ve coupled our perspective to the view being added. This view may exist in the same plug-in as the perspective, but often it does not. If the view is in a different plug-in, we have to declare a dependency on that plug-in just to add the view. It’s possible to reduce the coupling somewhat by replacing MyView.ID with the actual string id itself, but hidden dependencies based on string equivalency are arguably even more smelly.

In the end, a programmatic perspective layout results in a hard-coded and centralized architecture looking like this.

perspective-layouts-central

Declarative Layout = Decentralized / Modular

The declarative approach based on extension points resolves these issues. To layout a perspective declaratively we extend the org.eclipse.ui.perspectiveExtensions extension point.

   <extension
         point="org.eclipse.ui.perspectiveExtensions">
      <perspectiveExtension
            targetID="com.mycompany.myperspective">
         <view
               id="com.mycompany.myview"
               minimized="false"
               ratio="0.5"
               relationship="left"
               relative="org.eclipse.ui.editorss">
         </view>
      </perspectiveExtension>
   </extension>

Using this approach, each plug-in adds the views that it knows about, resulting in a decentralized architecture where the plug-ins containing the views are now in control.

perspective-layouts-decentr

Note that we have not eliminated all coupling, as the perspective extensions still need to refer to the perspective by its string id, but this is not as bad as it sounds. Perspectives are much more static than views – you typically define them and make few changes afterwards. Views, on the other hand are often moved from one plug-in to another or have their purpose (and potentially their id) redefined. Decentralizing control allows you to make these kinds of changes without breaking the perspective layout.

Conclusion

Adding UI elements declaratively is definitely the way to go. It gives you much more flexibility (e.g. you can add views to perspectives you didn’t create) and also allows you to leverage the modular nature of the framework.

Sure, there will always be cases where a declarative approach cannot be taken, particularly when some part of an API is not yet surfaced in the related extension point. But in the absence of such a need, I urge RCP developers to always turn first to the extension point mechanisms and fall back to programmatic approaches as a last resort. As your application evolves over time, you’ll really come to enjoy the flexibility and increased reusability that a declarative approach makes possible.

Eclipse RCP Trends

August 7th, 2008  |  Published in Rich Client Platform

I’ve been having some fun today with Google Insights for Search, and of course my first thought was to examine trends relating to the Eclipse Rich Client Platform. And what did I find? Here is a chart showing historical data beginning in 2004 for the search “eclipse rcp”.

First, this is just awesome data! You can drill down to individual countries, states/provinces or even cities. I could play with this all day, but I really should get back to work!


Unfortunately the news isn’t good for Eclipse RCP. It’s interesting that while Eclipse RCP job postings are trending up, the search statistics are telling a different story. The stats for RCP look even worse when you compare them to Adobe Flex, which many (mistakenly, I believe) think of as a substitute for RCP.

We obviously need to do a much better job promoting Eclipse RCP. There are so many things involved with this, including making the platform easier to use (hopefully the e4 project will help) and also communicating clearly what Eclipse RCP is and why it’s useful. I’ll have something to say about this later point in upcoming posts, but I’d be curious to hear what others have to say. What do you think can be done to better promote Eclipse RCP?

Updated PDE Build and Test Example

August 4th, 2008  |  Published in Builds, Rich Client Platform, Testing, Tips

I’ve just spent some time updating my example showing how to set up PDE Build and the Eclipse Testing Framework. I’ve generally cleaned things up and I’m now creating the test environment in the correct way.

As a special bonus, I’ve also thrown in coverage analysis using EMMA. And before people ask, yes I have tried to use Clover with PDE Build, but have had little luck due to Clover’s dependence on a specialized Java complier. If anyone has gotten this to work, I’d love to hear about it.

And finally, I had to change this example to use a test plug-in instead of a test fragment. For some reason when running Eclipse 3.4 (maybe related to p2?), the ETF is not finding tests in fragments. If anyone has any ideas here as well, please let me know.

You can download the new example here.

NOTE: I’ve discovered that the EMMA instrumentation task fails if you’re running the script inside of Eclipse and you have spaces in your workspace path. Avoid spaces in your path and you should be good to go.

Update – October 6, 2009: The sample projects have now been updated to work with Eclipse 3.5.1

Running Unit Tests for RCP and OSGi Applications

June 12th, 2008  |  Published in Builds, Rich Client Platform, Testing, Tips

Eclipse provides great tools for testing RCP and OSGi applications using JUnit, but there a few areas that are problematic.

  • It’s not easy to run all the tests in a set of plug-ins. The test launcher allows you to run all the tests in a single project, but RCP and OSGi developers are usually working with a large set of test plug-ins. Sure it’s possible to create test suites, but keeping suites up-to-date is a real pain.
  • It’s not easy to use test fragments. To find out why you’d want to use test fragments instead of test plug-ins, check out my previous post on Testing Plug-ins with Fragments. The problem is that even the standard suite-based solution does not work with fragments. There are workarounds, but they’re not very pretty.
  • It’s not easy to run all of your tests during an automated build using the Eclipse Testing Framework. This is related to the first point above, and again you can use suites to handle this. 
So to sum things up, I want to run sets of tests across multiple plug-ins or fragments and I don’t want to use suites. My solutions has been to create a simple bundle test collection plug-in that harvests unit tests based on a set of filters. To use the plug-in, you need to do the following:
  1. Download the bundle test collector which is licensed under the standard EPL. The archive contains the test collector plug-in and also an example plug-in showing proper usage.
  2. Add the com.rcpquickstart.bundletestcollector plug-in to your workspace.
  3. Create a plug-in that will contain a suite or set of suites that will load tests based on filters. The tests making up the suites will be generated dynamically, so you won’t need to maintain them. This plug-in will need to depend on the com.rcpquickstart.bundletestcollector and junit plug-ins, but that’s it.
  4. In your suite, add the following method:
    	public static Test suite() {
    		BundleTestCollector testCollector = new BundleTestCollector();
    
    		TestSuite suite = new TestSuite("All Tests");
    
    		/*
    		 * assemble as many collections as you like based on bundle, package and
    		 * classname filters
    		 */
    		testCollector.collectTests(suite, "com.mycompany.", "com.mycompany.mypackage.",
    				"*Test");
    
    		return suite;
    
    	}

 

You can then run the test suite both inside of the Eclipse IDE and using the Eclipse Testing Framework. I should note that this works only for JUnit 3.x tests. JUnit 4 describes suites using annotations which makes it (as far as I can tell) impossible to dynamically generate a suite at runtime. If anyone has a solution to this, I’d love to hear it. 

As always, comments and fixes are much appreciated.

RCP Target Platform Tips

April 29th, 2008  |  Published in Rich Client Platform, Tips

Setting up a target platform for an Eclipse Rich Client Platform application is fairly simple. You simply download the RCP SDK, extract it to a directory, and then use the Target platform preferences page to point to the new directory. But managing target platforms over time can be more complicated, and I’d like to pass along a few tips I’ve learned the hard way.

Maintain a separate target platform for each application.

The plug-ins that make up a target platform are as much a part of your application as the code you write, and this set of plug-ins will vary from one application to the next. One application might require the forms API. Another might use cheat sheets. Creating individual target platforms for each applications allows you to more easily manage these dependencies.

Make it easy for developers to create or link to target platforms.

Developers come and go on most projects and the first thing a new developer will need to do is set up a target platform. One way of making this easier is to create a wiki page listing the plug-ins that make up a target platform. Even better, just keep your target platform on a shared drive so everyone on the team can access it.

Version your target platforms.

Wiki pages and shared folders are great, but if you want to go all the way, consider versioning your target platforms along with your application source code. This makes it even easier to support new developers, and also makes it much easier to rebuild previous versions of your application.

Adding a new plug-in to your target platform is a big deal.

Adding a plug-in should be an explicit decision driven by your application’s requirements. When using the default target platform (Eclipse itself), it’s much too easy for developers to simply add dependencies on whatever plug-ins they like. Adding a new plug-in will generally require changes to your feature definitions, launch configurations, production configurations and automated build processes. Make sure the decision to add a plug-in to your application gets the deliberation it deserves.

A little work up front goes a long way.

Having said all that, I don’t want to make dealing with target platforms sound like rocket science. It’s usually a fairly simple aspect of RCP application development, as long as you treat it with the respect it deserves. The teams I see suffering from complications are those that never specifically address the issues posed by target platforms. With a little effort up front you can save yourself from some serious headaches.

Why create a custom target platform?

April 21st, 2008  |  Published in Rich Client Platform, Tips

One of the most important tips I have for beginning RCP developers is to please, please, please set up a custom target platform for your applications. As a trainer, it’s one of the first things I have students do. This is because target platforms are central to many other things we do as RCP developers, including the management of launch and product configurations. 

A target platform is simply the set of base plug-ins on which your application depends. By default, this target is set to be the entire collection of plug-ins shipped with Eclipse itself. So the first reason to set up a custom target platform is that the default is just messy. Why have hundreds of plug-ins in your target platform when you only need 20 or 30?

So setting up a target platform satisfies my sometimes excessive need for cleanliness, but there are other reasons as well. The best reason is that it decouples your application from the Eclipse development environment. Consider the following scenarios:

  • You’d like to upgrade your Eclipse development environment to a milestone release, but you don’t want your RCP application to depend on beta plug-ins.
  • You want to add GEF, EMF, BIRT or whatever to your application, but you don’t want to add it to your development environment.

In both cases, you’re out of luck if you’ve left your target platform defaulted to your Eclipse install. So save yourself some future headaches and set up a custom target platform.

 

Using FormEditor with a single page

January 4th, 2008  |  Published in Rich Client Platform, Tips

I tried to think of a snazzier title for this post, but I’m in a literal mood I guess. So have you ever faced this problem? You want to use the FormEditor class (or it’s new subclass SharedHeaderFormEditor), but you only have a single page.

Sure, you can use FormEditor with a single page, but you’ll wind up with a single tab at the bottom of the editor. It looks a bit goofy:

View of editor showing tab on single page

Well the solution is surprisingly simple. In your subclass of FormEditor, just override the createPages method like this:

protected void createPages() {
	super.createPages();
        if (getPageCount() == 1 &&
		getContainer() instanceof CTabFolder) {
            ((CTabFolder) getContainer()).setTabHeight(0);
        }
}

This code hides the tabs when there is only one page, and you wind up with this:

View of editor with no tabs for single page

Note that you need to call the super method before resizing the tab height, or this won’t work.