eclipse default handler IHandler interface “the chosen operation is not enabled”

简介:

NOTE: These two methods:

Tip: Subclass AbstractHandler rather than implementing IHandler. but you can use it to the below section you need to set:

 

IHandler the chosen operation is not enabled

NOT USE popupMenus instead of Menus

isEnabled: should be set to true

isHandled:should be set to true

 

复制代码
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.commands.IHandlerListener;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;


public class MyHandler implements IHandler {

    private FontChanger font=FontChanger.getInstance();
    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        // TODO Auto-generated method stub
        
        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
        MessageDialog.openInformation(
                window.getShell(),
                "Demo",
                "Hello, Eclipse world");
        font.decreaseSize();
        return null;
    }
    @Override
    public void addHandlerListener(IHandlerListener handlerListener) {
        // TODO Auto-generated method stub
        
    }
    @Override
    public void dispose() {
        // TODO Auto-generated method stub
        
    }
    @Override
    public boolean isEnabled() {
        // TODO Auto-generated method stub
        return true;
    }
    @Override
    public boolean isHandled() {
        // TODO Auto-generated method stub
        return true;
    }
    @Override
    public void removeHandlerListener(IHandlerListener handlerListener) {
        // TODO Auto-generated method stub
        
    }

    
}
复制代码

 

 

menu :

 

http://stackoverflow.com/questions/1342532/how-to-add-items-in-popup-menu

add it as a menu or menu item

 

Eclipse base location uri for menus

Since they are impossible to find on the net here is the list of all base location uri's in eclipse that are used in the org.eclipse.ui.menus extension point:
menu:org.eclipse.ui.main.menu // the top-level menu
popup:org.eclipse.ui.popup.any // all pop-up menus
toolbar:org.eclipse.ui.main.toolbar // the top-level tool bar
toolbar:org.eclipse.ui.trim.command1 // the top left trim (main toolbar area)
toolbar:org.eclipse.ui.trim.command2 // the top right trim (perspective switcher area)
toolbar:org.eclipse.ui.trim.vertical1 // the left vertical trim
toolbar:org.eclipse.ui.trim.vertical2 // the right vertical trim
toolbar:org.eclipse.ui.trim.status // the status line trim
to access the menu/toolbar/popup of a part (view or editor):
menu:partid //the part's chevron menu
toolbar:partid //the part's toolbar (cannot contain other toolbars)
popup:partid //the part's popup menu (register the context menu in createPartControl first)

 

 

eclipse plugin menu gray out

check the handler class is correct set ,or not implement



本文转自hcy's workbench博客园博客,原文链接:http://www.cnblogs.com/alterhu/p/3996200.html,如需转载请自行联系原作者。


目录
相关文章
|
5月前
|
Android开发
Eclipse提示“The default workspace “xxxx” is in use or cannot be created Please choose a different on
Eclipse提示“The default workspace “xxxx” is in use or cannot be created Please choose a different on
|
Java Maven Android开发
eclipse maven 报错Could not get the value for parameter encoding for plugin execution default
问题描述:更改默认的maven仓库路径完成后、即存maven项目或者新建maven项目的时候出现如下错误   Could not get the value for parameter encoding for plugin execution default   原因分析:当问题解决后、回...
1843 1
|
5月前
|
Java Maven Android开发
在Eclipse里配置Maven插件
Maven是一款比较常用的Java开发拓展包,它相当于一个全自动jar包管理器,会导入用户开发时需要使用的相应jar包。使用Maven开发Java程序,可以极大提升开发者的开发效率。下面我就跟大家介绍一下如何在Eclipse里安装和配置Maven插件。
131 0
|
5月前
|
XML Java Maven
eclipse 、idea 安装activiti插件
eclipse 、idea 安装activiti插件
114 0
|
10月前
|
Java Android开发
eclipse安装SpringBoot插件的无敌办法
eclipse安装SpringBoot插件的无敌办法
100 0
|
10月前
|
Java Android开发 Spring
在 Eclipse 中安装 SpringTools 插件
在 Eclipse 中安装 SpringTools 插件
107 0
|
11月前
|
XML Java 应用服务中间件
Eclipse插件下载地址汇总
Eclipse插件下载地址汇总
256 0
|
存储 Android开发
Eclipse安装Flowable Eclipse Designer插件实现图形建模BPMN 2.0流程图
Eclipse安装Flowable Eclipse Designer插件实现图形建模BPMN 2.0流程图
342 0