Programatically change icon for a eclipse RCP command

我怕爱的太早我们不能终老 提交于 2019-12-06 07:59:07

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/2506062/programatically-change-icon-for-a-eclipse-rcp-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!