简体   繁体   English

如何在e4中迁移选择提供程序

[英]how to migrate the selection provider in e4

I'm migrating Eclipse views to using the e4 framework, currently we use Ecipse 4.4.1 in compability mode. 我正在将Eclipse视图迁移到使用e4框架,当前,我们在兼容模式下使用Ecipse 4.4.1。

In most views I'm setting the selection provider of the site: 在大多数视图中,我都在设置网站的选择提供商:

site.setSelectionProvider(treeViewer);

In different handlers I then use code like this to get the selection: 然后,在不同的处理程序中,我使用如下代码来获取选择:

IWorkbenchSite site = HandlerUtil.getActiveSite(event);
ISelectionProvider selectionProvider = site.getSelectionProvider();
ISelection selection = selectionProvider.getSelection();

Some handler even use the selection provider and if it is Viewer work with it eg refersh, expand... 一些处理程序甚至使用选择提供程序,如果是Viewer,则使用它,例如Referh,expand ...

ISelectionProvider selectionProvider = activeSite.getSelectionProvider();
if (selectionProvider instanceof StructuredViewer) {
...
}

The wiki describes how to handle selections new in e4. Wiki描述了如何处理e4中的新选择。 https://wiki.eclipse.org/E4/EAS/Selection https://wiki.eclipse.org/E4/EAS/Selection

What I can't find is a way to migrate using the actual selection provider? 我找不到使用实际选择提供程序进行迁移的方法吗?

In an e4 handler you use something like: 在e4处理程序中,您可以使用以下命令:

@Execute
void execute(@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection
{
  ...
}

to get the active selection. 获得主动选择。

If you want to look at the active part you can use: 如果要查看活动部分,可以使用:

@Execute
void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart)
{
  Object object = activePart.getObject();

  // 'object' is the class you defined for the part in the Application.e4xmi
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM