[英]Eclipse RCP - How to shutdown before workbench initializes
I have a similar setup to below: 我有一个类似于下面的设置:
<extension
id="product"
point="org.eclipse.core.runtime.products">
<product
name="%product.name"
application="org.eclipse.e4.ui.workbench.swt.E4Application">
<property
name="lifeCycleURI"
value="bundleclass://plugin-id/package.LifeCycle">
</property>
.... more properties ...
public class LifeCycle
{
@PostConstruct
public void doWork()
{
// Show a login screen. If the user cancels out of it, shut down
// the application.
}
}
In the scenario above, what is the correct way to properly shutdown the application? 在上述情况下,正确关闭应用程序的正确方法是什么? If I do:
如果我做:
PlatformUI.getWorkbench().close()
I get an error since it's not initialized yet. 我收到一个错误,因为它尚未初始化。 If I do:
如果我做:
System.exit(0)
then I kill all other things on the JVM (Even though it is suggested to do it here http://www.vogella.com/tutorials/Eclipse4LifeCycle/article.html ) 然后我杀死了JVM上的所有其他东西(即使建议在这里进行http://www.vogella.com/tutorials/Eclipse4LifeCycle/article.html )
Any ideas/suggestions on how this could be done? 关于如何做到这一点的任何想法/建议?
PlatformUI
is not available in an e4 application, do not try and use it. PlatformUI
在e4应用程序中不可用,请不要尝试使用它。
@PostConstruct
is too early to do anything in the LifeCycle class. @PostConstruct
在LifeCycle类中做任何事情还为时过早。 The first point you should try and do anything is the @PostContextCreate
method. 您应该尝试执行任何操作的第一点是
@PostContextCreate
方法。
You can inject org.eclipse.e4.ui.workbench.IWorkbench
and call the close
method to shutdown the e4 application. 您可以注入
org.eclipse.e4.ui.workbench.IWorkbench
并调用close
方法来关闭e4应用程序。 However the workbench is not available until the application startup is complete so you need to wait for this event. 但是,在应用程序启动完成之前,工作台不可用,因此您需要等待此事件。
public class LifeCycle
{
@PostContextCreate
public void postContextCreate(IEclipseContext context, IEventBroker eventBroker)
{
...
eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE,
new AppStartupCompleteEventHandler(eventBroker, context));
}
}
class AppStartupCompleteEventHandler implements EventHandler
{
private IEventBroker _eventBroker;
private IEclipseContext _context;
AppStartupCompleteEventHandler(IEventBroker eventBroker, IEclipseContext context)
{
_eventBroker = eventBroker;
_context = context;
}
@Override
public void handleEvent(final Event event)
{
_eventBroker.unsubscribe(this);
IWorkbench workbench = _context.get(IWorkbench.class);
workbench.close();
}
}
System.exit() is the only way to currently abort the E4 startup if you are using the SWT renderer. 如果您正在使用SWT渲染器,则System.exit()是当前中止E4启动的唯一方法。
If you use the JavaFX renderer from e(fx)clipse you can return FALSE from @PostContextCreate to shutdown. 如果从e(fx)clipse使用JavaFX渲染器,则可以从@PostContextCreate返回FALSE到关闭状态。
For more information see this blog: http://tomsondev.bestsolution.at/2014/11/03/efxclipse-1-1-new-features-api-to-restart-your-e4-app-on-startup/ 有关更多信息,请参见以下博客: http : //tomsondev.bestsolution.at/2014/11/03/efxclipse-1-1-new-features-api-to-restart-your-e4-app-on-startup/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.