1

我正在尝试基于 org.eclipse.ui.commands、org.eclipse.ui.menus 和 org.eclipse.ui.handlers 创建一个简单的 eclipse 按钮

但是在调试时,我创建的按钮是灰色的:http: //i.stack.imgur.com/rNpbz.png

这是我的 plugin.xml 和 LoginHandler.java

插件.xml

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

   <extension
         point="org.eclipse.ui.views">
      <category
            name="Server Browsing"
            id="com.abc.serverapi">
      </category>
      <view
            name="Server Browser"
            icon="icons/sample.gif"
            category="com.abc.serverapi"
            class="com.abc.serverapi.views.ServerBrowser"
            id="com.abc.serverapi.views.serverbrowser">
      </view>
   </extension>
   <extension
         point="org.eclipse.ui.perspectiveExtensions">
      <perspectiveExtension
            targetID="org.eclipse.jdt.ui.JavaPerspective">
         <view
               ratio="0.5"
               relative="org.eclipse.ui.views.ProblemView"
               relationship="right"
               id="com.abc.serverapi.views.serverbrowser">
         </view>
      </perspectiveExtension>
   </extension>
   <extension
         point="org.eclipse.help.contexts">
      <contexts
            file="contexts.xml">
      </contexts>
   </extension>
   <extension
         point="org.eclipse.ui.commands">
      <command
            id="com.abc.serverapi.command.login"
            name="Open Server Login">
      </command>
   </extension>
   <extension
         point="org.eclipse.ui.handlers">
      <handler
            class="com.abc.serverapi.handler.LoginHandler"
            commandId="com.abc.serverapi.command.login">
      </handler>
   </extension>
   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            allPopups="false"
            locationURI="menu:org.eclipse.ui.main.menu">
         <menu
               id="com.abc.serverapi.menu.login"
               label="Server Login Menu">
            <command
                  commandId="com.abc.serverapi.command.login"
                  icon="icons/sample.gif"
                  id="com.abc.serverapi.menu.openLoginDialog"
                  mnemonic="O"
                  style="push">
            </command>
         </menu>
      </menuContribution>
   </extension>

</plugin>

这是我的命令处理程序:

package com.abc.serverapi.handler;

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.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;

public class LoginHandler implements IHandler {

    @Override
    public void addHandlerListener(IHandlerListener handlerListener) {
        // TODO Auto-generated method stub

    }

    @Override
    public void dispose() {
        // TODO Auto-generated method stub

    }

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
        MessageDialog.openInformation(
                window.getShell(),
                "Test",
                "Hello, Eclipse world");
        return null;
    }

    @Override
    public boolean isEnabled() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean isHandled() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void removeHandlerListener(IHandlerListener handlerListener) {
        // TODO Auto-generated method stub

    }

}
4

1 回答 1

5

isEnabled()在处理程序中的方法正在返回false- 因此处理程序未启用!

您可以扩展org.eclipse.core.commands.AbstractHandler而不是实现所有IHandler.

于 2013-10-06T15:43:59.793 回答