Thursday, October 28, 2010

Eclipse RCP: Images and Icons, Using ImageRegistry

Code examples are full of automagical ways of putting an image on a button or label. For example, your TreeViewer may set an ILabelProvider, which may have the following getImage method:

public Image getImage(Object obj) {
String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
}


But how do we add our own image to our plugin, and use it in a simple way?

Here's How:

In this example I've prepared two images and placed them in the project's icons directory:

In your plugin's Activator class override the initializeImageRegistry method.  For example:

@Override
protected void initializeImageRegistry(ImageRegistry registry) {
super.initializeImageRegistry(registry);
Bundle bundle = Platform.getBundle(PLUGIN_ID);

//
// Setup our own images to be used as icons, etc
//
ImageDescriptor image = ImageDescriptor.createFromURL(
FileLocator.find(bundle, new Path("icons/chart.gif"), null));

registry.put(ACTIVE_CHART, i);

image = ImageDescriptor.createFromURL(
FileLocator.find(bundle, new Path("icons/module.gif"), null));

registry.put(MODULE, i);

}


In the example code above, we prepare two images: module.gif and chart.gif .  Now we're ready to use them in a viewer's label. You should already know how to use a LabelProvider for your viewer. A LabelProvider is a class that implements ILabelProvider. In my case I had a TreeViewer that needed special icons on tree nodes.

My LabelProvider's getImage method:

@Override
public Image getImage(Object obj) {

// we'll just get the MODULE image
Image image = imageRegistry.get(gov.faa.ata.sdat.Activator.MODULE);

return image;

}



So there you have it.

Sunday, July 18, 2010

Eclipse RCP Browser Example


This workflow is based on Eclipse Helios (3.6) for RCP Developers.

This workflow assumes a familiarity with Eclipse and RCP Java development.  Lars Vogel has published an excellent tutorial on basic RCP development.  I recommend an understanding of the concepts covered on Lars Vogel's excellent RCP tutorial.

This workflow covers the very basic concept of retrieving an Eclipse project from the Eclipse CVS repository.

Select File/Import, then select CVS/Projects From CVS from the “select an import source” list.
Click Next.

Provide the host and path.
Click Next.



Select the browser example from the list of existing modules.
Click Next.



Accept the default entries.  
Click Finish.
















ArcGIS Engine and Eclipse Rich Client Platform

This is a recent GIS project. The customer required a simple 2D map as a canvas for drawing custom polygons. This is a fully functioning GIS desktop application using ESRI ArcGIS Engine and Eclipse Rich Client Platform.