以编程方式显示来自 Eclipse 插件的视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/171824/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Programmatically showing a View from an Eclipse Plug-in
提问by Brian
I have a plug-in to an Eclipse RCP application that has a view. After an event occurs in the RCP application, the plug-in is instantiated, its methods are called to populate the plug-in's model, but I cannot find how to make the view appear without going to the "Show View..." menu.
我有一个带有视图的 Eclipse RCP 应用程序的插件。在 RCP 应用程序中发生事件后,将实例化插件,调用其方法来填充插件的模型,但我无法找到如何在不转到“显示视图...”菜单的情况下显示视图.
I would think that there would be something in the workbench singleton that could handle this, but I have not found out how anywhere.
我认为工作台单例中会有一些东西可以处理这个问题,但我还没有在任何地方找到方法。
回答by ILikeCoffee
You are probably looking for this:
你可能正在寻找这个:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("viewId");
回答by Imaskar
If called from handler of a command
如果从命令的处理程序调用
HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().showView(viewId);
would be better, as I know.
会更好,据我所知。
回答by Imaskar
I found the need to bring the view to the front after it had been opened and pushed to the background. The activate method does the trick.
我发现需要将视图打开并推到背景后将其置于前面。activate 方法可以解决问题。
PlatformUI.getWorkbench()
.getActiveWorkbenchWindow()
.getActivePage()
.activate(workbenchPartToActivate);
NOTE: The workbenchPartToActivate is an instance of IWorkbenchPart
.
注意: workbenchPartToActivate 是IWorkbenchPart
.
回答by Max Hohenegger
In e4, the EPartService is responsible for opening Parts. This can also be used to open e3 ViewParts. Instantiate the following class through your IEclipseContext, call the openPart-Method, and you should see the Eclipse internal browser view.
在 e4 中,EPartService 负责打开 Parts。这也可用于打开 e3 ViewParts。通过您的 IEclipseContext 实例化以下类,调用 openPart-Method,您应该会看到 Eclipse 内部浏览器视图。
public class Opener {
@Inject
EPartService partService;
public void openPart() {
MPart part = partService.createPart("org.eclipse.ui.browser.view");
part.setLabel("Browser");
partService.showPart(part, PartState.ACTIVATE);
}
}
Hereyou can find an example of how this works together with your Application.e4xmi.
您可以在此处找到有关如何与您的 Application.e4xmi 协同工作的示例。