简体   繁体   English

Eclipse,创建WorkBench窗口后如何在捆绑包中执行代码?

[英]Eclipse, How do I execute code in a bundle after the WorkBench window has been created?

So I have a bundle that needs access to the workbench window to add some items to a menu programmatically, which I can do fine. 因此,我有一个捆绑包,需要访问工作台窗口以编程方式将一些项目添加到菜单中,我可以做得很好。

But what I run into is when there's a race condition where my bundle is started before the workbench window is finished being instantiated and it will spit out an error about the workbench not existing yet when my bundle tries to add stuff to a menu with code. 但是我遇到的情况是,在一种竞争条件下,我的捆绑包在实例化工作台窗口之前就已启动,并且当我的捆绑包尝试使用代码向菜单中添加内容时,它会吐出一个关于工作台尚不存在的错误。

So is there an extension point or something that I can use to tell the program to execute such and such code after the workbench window has loaded? 那么,是否有扩展点或某些东西可以用来告诉程序在工作台窗口加载后执行此类代码? I don't want to muck around with start levels for my bundles. 我不想乱砍我的捆绑包的开始水平。

  • In Eclipse 3 you can register org.eclipse.ui.application.WorkbenchWindowAdvisor to listen for window lifecycle events. 在Eclipse 3中,您可以注册org.eclipse.ui.application.WorkbenchWindowAdvisor来侦听窗口生命周期事件。
  • If your items are not dynamically you can add them via plugin.xml (instead of programmatically adding them). 如果您的商品不是动态的,则可以通过plugin.xml添加它们(而不是通过编程方式添加它们)。 Eclipse will load this extensions when appropriate and you don't have to worry about the lifecycle. Eclipse将在适当的时候加载此扩展,而您不必担心生命周期。

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

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