简体   繁体   English

从Eclipse RCP中的另一个插件激活一个插件

[英]Activate a plugin from another plugin in Eclipse RCP

I have 2 plugins that work properly when I start them from the menu. 我有2个从菜单启动时可以正常工作的插件。 I would however like to start the second plugin when I click on a button on the UI of the first plugin. 但是,当我单击第一个插件的UI上的按钮时,我想启动第二个插件。

I have looked into getBundle().start() method as advised here: https://www.eclipse.org/forums/index.php/t/99869/ but it did not produce any result. 我已经按照建议的方式研究了getBundle()。start()方法: https : //www.eclipse.org/forums/index.php/t/99869/但它没有产生任何结果。 The second bundle shows its bundle state as ACTIVE when printed on console, but its UI doesn't show on the screen. 当在控制台上打印时,第二个捆绑软件将其捆绑软件状态显示为“活动”,但其UI不在屏幕上显示。

Any help would be greatly appreciated! 任何帮助将不胜感激!

Make your second plugin provide an API that displays the graph that the first plugin can call when the button is clicked. 让您的第二个插件提供一个API,该API显示单击按钮时第一个插件可以调用的图形。 This API might be as simple as a single method to call, it will probably be similar to the code you use in the menu. 该API可能就像调用一个方法一样简单,可能与您在菜单中使用的代码相似。

In the second plugin add the package containing the API to the 'Export-Package' list in the MANIFEST.MF (in the MANIFEST.MF editor you do this on the 'Runtime' tab in the 'Exported Packages' list). 在第二个插件中,将包含API的程序包添加到MANIFEST.MF的“导出程序包”列表中(在MANIFEST.MF编辑器中,您可以在“导出的程序包”列表中的“运行时”选项卡上执行此操作)。

In the first plugin add the second plugin to its dependencies - the 'Require-Bundle' list in the MANIFEST.MF (in the editor this is the 'Required Plug-ins' on the 'Dependencies' tab). 在第一个插件中,将第二个插件添加到其依赖项中-MANIFEST.MF中的“ Require-Bundle”列表(在编辑器中,这是“ Dependencies”选项卡上的“ Required Plug-ins”)。

I referred to the following post: Programmatically showing a View from an Eclipse Plug-in 我提到了以下文章:以编程方式显示Eclipse插件的视图

The following code finally worked for me: 以下代码终于对我有用:

Display.getDefault().asyncExec(new Runnable() {
    @Override
    public void run() {
       PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("viewId");

    }
});

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

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