Premium Content

New Signal Chain Resources from Texas Instruments:

Write Less Code And Deliver Java Apps Faster With Eclipse 3.0

Base your next application on the Eclipse RCP and you can start thinking about reusing code—and get better cross-platform user interfaces.

Date Posted: September 20, 2004 12:00 AM

Next, we needed to work on making sure the navigator view is initialized properly. Because this was previously done by the workbench's application advisor (which we replaced), we needed to make sure that our advisor does the same initialization. We located the code in:

com.eclipse.ui.internal.ide.IDEWorkbenchAdvisor

and copied the methods,

declareWorkbenchImages(), declareWorkbenchImage(Bundle, String, String, boolean), and initialize(IWorkbenchConfigurer),

into our workbench advisor class. With another quick launch to test our changes, we saw that the navigator had been repaired (Fig. 5).

Our final task was to create menu bars containing only the actions necessary for our application. Again we turned to the

IDEWorkbenchAdvisor
class, because we knew that it sets up the menu bar for the workbench application. We copied the
fillActionBars(IWorkbenchWindow, IActionBarConfigurer, int)

method into our

ImageViewerWorkbenchAdvisor

class and declared the same ACTION_BUILDER constant. At this point, we had exactly the same menu configuration as the workbench. But, because we need to customize both the menu bar and the actions, we simply copied

org.eclipse.ui.internal.ide.WorkbenchActionBuilder

to

com.genuitec.eclipse.imageviewer.rcp.ImageViewerActionBuilder.

Now we can simply remove the code that builds the menus or actions that we don't want in our final application. By comparing the final menu layout in Figure 6 to Figure 1, you can easily see that we removed everything that wasn't germane to viewing images.

Step 3. Packaging the Image Viewer for Distribution:
The Eclipse distribution and update model is based on the concept of a feature, which is a grouping of plug-ins that provides some function. So next, we quickly created a feature for the image-viewer application.

We used the feature project wizard and specified that our project would be called com.genuitec.eclipse.imageviewer-feature. Once the project creation was completed, we navigated to the Content tab of the feature manifest editor. Then we added our two plug-ins, and selected the Compute button in the Required Features/Plug-ins section so that Eclipse would determine the top-level plug-ins necessary for our feature to execute properly. This prevented our feature from installing any distribution without all of the prerequisites. At this point, our completed development projects looked like Figure 7.

Next, we had to determine the minimal set of plug-ins necessary to ship as part of the product distribution. So it was time to download the RCP binary distribution to use as our application's distribution foundation. The plug-ins within the RCP distribution form the minimum platform for any RCP-based application and include:

  • org.eclipse.core.expressions_3.0.0
  • org.eclipse.core.runtime_3.0.0
  • org.eclipse.help_3.0.0
  • org.eclipse.jface_3.0.0
  • org.eclipse.osgi.services_3.0.0
  • org.eclipse.osgi_3.0.0
  • org.eclipse.swt.win32_3.0.0
  • org.eclipse.swt_3.0.0
  • org.eclipse.ui.workbench_3.0.0
  • org.eclipse.ui_3.0.0

After unzipping the RCP, we renamed the top-level directory to ImageViewer so that we could begin adding our unique functionality into it.

Because we reused some functionality from the SDK, most notably the navigator view, we needed to do a bit of research to determine the full closure of the set of plug-ins required by the image viewer plug-ins—until we reach the RCP layer. Fortunately, we could use standard plug-in development techniques to find that list by focusing the Eclipse plug-in dependencies view on each of our plug-ins. Upon inspection, our plug-in dependency trees illustrated that the following plug-ins from the Eclipse SDK needed to be redistributed as part of our application:

  • org.apache.lucene_1.3.0
  • org.eclipse.core.resources_3.0.0
  • org.eclipse.core.resources.win32_3.0.0
  • org.eclipse.core.runtime.compatibility_3.0.0
  • org.eclipse.help.appserver_3.0.0
  • org.eclipse.ui.forms_3.0.0
  • org.eclipse.help.base_3.0.0
  • org.eclipse.ui.ide_3.0.0
  • org.eclipse.ui.win32_3.0.0
  • org.eclipse.ui.views_3.0.0
  • org.eclipse.update.configurator_3.0.0
  • org.eclipse.update.core_3.0.0
  • org.eclipse.update.core.win32_3.0.0
  • org.eclipse.update.ui_3.0.0

To complete the packaging of our application, we copied these additional plug-ins from our Eclipse SDK installation into our unzipped RCP binary distribution's plug-ins directory. We then exported our image-viewer feature from the workbench as a directory structure, which we pointed to the top-level ImageViewer directory. Finally, we created a new directory, called bin, and moved eclipse.exe into it. At the top level, we created a new shortcut named ImageViewer.exe and added the command-line argument

-application=com.genuitec.eclipse.imageviewer.rcp.application

to start our application. The completed application directory structure is shown in Figure 8. An application distribution could then be built by creating a zip file of the ImageViewer directory. As long as a Java VM of version 1.4.1 or later is installed, any recipient of the distribution can simply unzip it and double-click the ImageViewer.exe executable to launch the application on Windows.

For non-Windows platforms, a compatible distribution can be created by removing the four Windows-specific plug-ins (org.eclipse.core.resources.win32_3.0.0, org.eclipse.swt.win32_3.0.0, org.eclipse.ui.win32_3.0.0, org.eclipse.update.core.win32_3.0.0) and replacing them with the appropriate platform-specific version that's available from Eclipse.

How effective was this application development on the Eclipse RCP? The Image Viewer was completely built and ready for distribution in only a few hours. In our opinion, rapid delivery of end-user functionality is the definition of effective development. Of course, many will note that the primary reason for this rapid implementation was that we actually wrote very little new code. And, they'd be correct.

But the bigger question is "How did we manage to get away with writing so little code?" It's because we based our application on Eclipse technology. Between the Eclipse Foundation's projects and the hundreds of other open source Eclipse plug-in projects scattered throughout the Internet, there are literally millions of lines of code that are ready for use, reuse, integration, or modification.

Now you can base your next application on the Eclipse RCP and start thinking about reusing code rather than writing it. You'll likely deliver your next application much more effectively, just like we did.

* Li, Chendong, "A Basic Image Viewer," University of Kentucky, March, 15, 2004, http://www.eclipse.org/articles/Article-Image-Viewer/Image_viewer.html

Part Inventory
Go
powered by:
 

 
You must log on before posting a comment.

Are you a new visitor? Register Here
    There are no comments to display. Be the first one!