Tuesday, July 24, 2012

Reusing Platform images

The eclipse platform comes with a huge amount of ready to use images. Often when you need a nice icon for a toolbar or menu there is already one available within some other plug-in. Therefore plug-in programmers often copy over these icons to their own plug-in to reuse them. When you can be sure that the base plug-in will be available on your target installation you can use platform scheme URIs (see related post by Marcelo Paternostro) to reference such resources.

Still the hard part is to locate those images in other plug-ins. Therefore I wrote a plug-in, that allows you to search for such images.


This plugin is now part of Eclipse PDE and is maintained by the PDE team.

A screenshot is better than a 1000 words, so see for yourself:

Just select a source to browse, locate your desired image and click on it to update the Image Information.

Install it from the reopsitory: http://codeandme.googlecode.com/svn/trunk/at.pontesegger.updatesite/p2/

The view can be activated with Window -> Show View -> Other... and is located under Plug-in Development.

Be aware that some images you may find might be released under a restrictive license that forbids reuse.

Update 2012-07-29

* Fixed issue with memory errors when parsing too much images
* partially fixed support for e4 -> still you cannot browse the target platform there
* raised Bug 386197 to add this tool to PDE

Monday, July 2, 2012

A convenient toggle handler

Toggle buttons always seemed a bit awkward to me as there seems to be no uniform interface to store the toggle state. In the past I used Ralf Eberts ToggleHandler. But reading/setting and persisting the toggle state programmatically was always painful.

Now I rediscovered a post by Prakash G.R. and built my own ToggleHandler (view online) on top of this.

Using the handler

As stated in the referenced post the command contribution needs a state definition to store the current toggle state to:
<command      ...>       

Then your handler just needs to extend AbstractToggleHandler. The toggle state will automatically be preserved when you close your application.

You can programmatically set the state of any such toggle command by executing
ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
Command command = commandService.getCommand(commandId);
AbstractToggleHandler.setCommandState(command, true);

This will also toggle a visible button using this command.