我得有自己的图标工具栏项,像plugin.xml文件中定义?我的意思是,从代码更改Eclipse工具栏图标动态
3
A
回答
5
使用org.eclipse.ui.menus
扩展点,而不是改变它,并添加menuContribution与动态。 类的动态应子类ControlContribution
并实施createControl
方法来创建按钮。
3
您应该implements
IElementUpdater
在您的Handler
类。
请参考:https://stackoverflow.com/a/23742598/2893073
Handler类
import java.util.Map; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.commands.IElementUpdater; import org.eclipse.ui.menus.UIElement; import com.packpub.e4.menu.Activator; public class SampleHandler2 extends AbstractHandler implements IElementUpdater{ private static ImageDescriptor image_enable = Activator.getImageDescriptor("icons/btn_adapt_enable.png"); private static ImageDescriptor image_disable = Activator.getImageDescriptor("icons/btn_adapt_disable.png"); /** * The constructor. */ public SampleHandler2() { } /** * the command has been executed, so extract extract the needed information * from the application context. */ public Object execute(ExecutionEvent event) throws ExecutionException { //... return null; } @Override public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map map) { boolean condition = false; //... if(condition) { element.setIcon(image_disable); }else{ element.setIcon(image_enable); } } }
调用这个处理程序使用
ICommandService
:IWorkbenchWindow window = part.getSite().getWorkbenchWindow(); ICommandService commandService = (ICommandService) window.getService(ICommandService.class); if (commandService != null) { commandService.refreshElements("com.packpub.e4.menu.commands.sampleCommand", null); }
感谢。
相关问题
- 1. 如何动态更改jqgrid中的navGrid工具栏图标?
- 2. 动态更改CKEditor工具栏
- 3. 从AppCompat继承工具栏更改工具栏图标边距
- 4. 将图标更改为工具栏Android
- 5. 更改Eclipse工具栏 - 删除启动栏
- 6. 如何动态更改VIM工具栏中的菜单标题?
- 7. 将Eclipse工具栏图标左对齐
- 8. 通过ABAP动态更改应用程序工具栏项目图标
- 9. Eclipse工具栏
- 10. 更改UIImagePicker中的工具栏标题
- 11. 动态改变工具栏布局
- 12. 动态更改标签栏标题
- 13. 更改工具栏菜单项行动动态
- 14. 静态工具栏图标ontop
- 15. 与工具栏项更改活动
- 16. 更改工具栏按钮的图像
- 17. 如何更改Android工具栏视图?
- 18. 更改工具栏背景
- 19. Sencha 2.0动态更改标题栏
- 20. 动态更改过滤器工具栏选项
- 21. 安卓工具栏菜单 - 动态更改
- 22. 动态更改工具栏的文本颜色MenuItem文本
- 23. 如何在Zimbra中动态更改工具栏
- 24. 如何动态更改工具栏中的命令的UIID?
- 25. 更改状态栏图标颜色
- 26. 更改状态栏图标色调
- 27. 动态更改IntelliJ IDEA插件中的状态栏图标
- 28. 动态ckeditor工具栏
- 29. 更改图标动态
- 30. 更改工具栏和CollapsingToolbarLayout以编程方式滚动标志