如何在Eclipse 4 RCP中获取IHandlerService对象? [英] How to get an IHandlerService object in Eclipse 4 RCP?

查看:44
本文介绍了如何在Eclipse 4 RCP中获取IHandlerService对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个测试项目,并遵循了 Vogella的RCP教程 。之后,我对其进行了一些更改,例如。创建了 JFace TreeView 。现在,我希望如果用户双击 TreeView 元素,它将打开另一个 Part 。我有命令,但是,我不知道如何调用它。如果您看一下该教程,您可能会注意到它仅使用部件而不使用视图,并且我没有启动工作台的 Application.java 类。因此,以下方法对我不起作用:

I am working on a test project and followed Vogella's RCP tutorial. After that I made some changes on it, eg. created a JFace TreeView. Now I want that if the user double clicks on a TreeView element it opens up another Part. I have the command for it but, I do not know how to call it. If you look at the tutorial you may notice it only uses Parts, not Views and, I do not have an Application.java class that starts the workbench. Therefore the following methods do not work for me:


  1. IHandlerService handlerService =(IHandlerService)viewer.getSite()。 getService(IHandlerService.class);

  2. IWorkbenchWindow window = PlatformUI.getWorkbench()。getActiveWorkbenchWindow();
    IHandlerService handlerService =(IHandlerService)window.getService(IHandlerService.class);
    handlerService.executeCommand(cmdID,null );

  1. IHandlerService handlerService = (IHandlerService) viewer.getSite().getService(IHandlerService.class);
  2. IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IHandlerService handlerService = (IHandlerService)window.getService(IHandlerService.class); handlerService.executeCommand(cmdID, null);

两者都给了我 NullPointerException

推荐答案

这个旧备用数据库怎么样:

How about this old standby:

Command command = ((ICommandService)getSite().getService(ICommandService.class)).getCommand(commandId);
...
final Event trigger = new Event();
ExecutionEvent executionEvent = ((IHandlerService)getSite().getService(IHandlerService.class)).createExecutionEvent(command, trigger);
command.executeWithChecks(executionEvent);

这篇关于如何在Eclipse 4 RCP中获取IHandlerService对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆