[英]RCP: How to call a class from a command handler
我有一个菜单,其中有一个绑定到命令的标签。
可以说:
plugin.xml
<menu label="Settings">
<command
commandId="prototype.standalone.MainDirectory"
label="Main">
</command>
</menu>
public class MainDirectory extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// How can I call from here all my business methods from my main View.
// Do I have to use DI? If yes, can you give me an easy example related to this snippet?
return null;
}
}
如评论中所问。 如何调用我的方法? 因为如果我从不实例化MainDirectory
那么我也不能仅从createControls
传递对象-我认为我必须使用依赖注入,但我不知道如何。 有人可以给我一个例子或其他解决方案吗
编辑:或者是否有可能将侦听器添加到菜单项? 将使一切变得容易。 没有找到任何东西
似乎是不使用org.eclipse.ui.menu
创建菜单的最简单方法,而是仅使用基本的SWT Menu
并将其添加到框架中-我仍然有一个独立的应用程序,因此eclipse菜单将是一个过大的杀伤力
您还应该在plugin.xml
包含以下内容
<extension point="org.eclipse.ui.commands">
<command
defaultHandler="your MainDirectory class path"
id="prototype.standalone.MainDirectory"
name="My Label">
</command>
</extension>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.