Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programatically change icon for a eclipse RCP command

I have a menu drop down action in the coolbar. It has 3 sub items that form a radio group. I would like to change the icon shown in the coolbar when the user selects one of these options.

I've googled and seen that I should look at: org.eclipse.ui.commands.ICommandService.refreshElements(String, Map) and org.eclipse.ui.commands.IElementUpdater

Its probably the right thing to look at exception its not enough information. One or two small code snippets will be excellent.

Thanks in advance.

like image 989
Craig Avatar asked May 20 '26 05:05

Craig


2 Answers

Ok basically if you don't want to use a "custom" control the what to do it is to have your handler (handler that is linked to the specific command) implement IElementUpdater. When every the toolbar item gets shown or clicked on (i.e if the user selects on the the radio buttons) the method: updateElement(UIElement element, Map parameters) gets called. The element has a setIcon() method and this is what i used to change the icon of the menu drop down action.

like image 194
Craig Avatar answered May 22 '26 20:05

Craig


Every update to the Coolbar points to the specialization of the WorkbenchWindowControlContribution class.

This bug 186800 has some code example in it which can be of interest.

like image 30
VonC Avatar answered May 22 '26 21:05

VonC