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 coolb开发者_如何学编程ar 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.
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.
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.
精彩评论