0
我添加了一个主菜单按钮,一个Eclipse插件,并生成该代码来处理操作时按下按钮:添加菜单按钮Eclipse插件
package de.vogella.plugin.experiment;
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.Shell;
import org.eclipse.ui.handlers.HandlerUtil;
public class SomethingHandler 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 {
System.out.println("Hello");
// TODO Auto-generated method stub
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
}
}
我加入了打印语句的执行类以测试我按下按钮时是否会发生任何事情。但是,当我将此插件作为eclipse应用程序运行时,并按下按钮,按钮将保持按下状态,直到我再次单击它为止,并且没有其他事情发生。按下按钮时如何执行某些事件?然后让程序完成,所以我不必再次按下按钮关闭它?
编辑:
这里是我的plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin
>
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="de.vogella.plugin.experiment.SomethingHandler"
id="de.vogella.plugin.experiment.SomethingHandler"
name="name">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="SomethingHandler"
commandId="de.vogella.plugin.experiment.SomethingHandler">
</handler>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="menu:org.eclipse.ui.main.menu">
<command
commandId="de.vogella.plugin.experiment.SomethingHandler"
label="DoSomething"
style="push">
</command>
</menuContribution>
</extension>
</plugin>
扩展'org.eclipse.core.commands.AbstractHandler'而不是从头实现'IHandler',它将处理除'execute'以外的所有内容。 “plugin.xml”中定义的菜单,命令和处理程序如何? –
我扩展了AbstractHandler,它运行了但它仍然没有改变任何东西。菜单,命令和处理程序的命令ID以及命令的默认处理程序都是相同的,处理程序的类是我在上面显示的类。 –
我认为我们确实需要看到plugin.xml –