Thursday, May 31, 2007

Adding a cheat sheet menu action

Creating a cheat sheet using the org.eclipse.ui.cheatsheets.cheatSheetContent extension is well documented. What is not documented is how to add the cheat sheet action to your application help menu. You need to make your application plugin depend upon the org.eclipse.ui.cheatsheets plugin. Then add the following extension:
<extension point="org.eclipse.ui.actionSets">
  <actionSet
      label="Cheat Sheets"
      visible="true"
      id="org.eclipse.ui.cheatsheets.actionSet">
     <action
        label="Cheat Sheets"
        class="org.eclipse.ui.cheatsheets.
               CheatSheetExtensionFactory:helpMenuAction"
        menubarPath="help/group.tutorials"
        id="org.eclipse.ui.cheatsheets.
            actions.CheatSheetHelpMenuAction">
     </action>
  </actionSet>
</extension>

Thursday, May 10, 2007

Plugin your images

Let AbstractUIPlugin handle sharing images with your plugins. It has its own ImageRegistry that handles storing, disposing, and retrieving of images.

A simple override of initializeImageRegistry(ImageRegistry) and you are on your way to Image sharing bliss.

public class Activator extends AbstractUIPlugin {
    public static final String ID = "rcp.eclipse";
    public static final String MY_IMAGE_ID = 
                                  "image.myimage";

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

        ImageDescriptor myImage = ImageDescriptor.createFromURL(
              FileLocator.find(bundle,
                               new Path("icons/myImage..gif"),
                                        null));
        registry.put(MY_IMAGE_ID, myImage);
    }
}

Put your image into workspace/rcp.eclipse/icons/myImage.gif and then access it in your code.

AbstractUIPlugin plugin = Activator.getDefault();
ImageRegistry imageRegistry = plugin.getImageRegistry();
Image myImage = imageRegistry.get(Activator.MY_IMAGE_ID);