![](/img/trans.png)
[英]Workbench application development using Eclipse RCP :: How rich can it get?
[英]Eclipse RCP - How to shutdown before workbench initializes
我有一个类似于下面的设置:
<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.
}
}
在上述情况下,正确关闭应用程序的正确方法是什么? 如果我做:
PlatformUI.getWorkbench().close()
我收到一个错误,因为它尚未初始化。 如果我做:
System.exit(0)
然后我杀死了JVM上的所有其他东西(即使建议在这里进行http://www.vogella.com/tutorials/Eclipse4LifeCycle/article.html )
关于如何做到这一点的任何想法/建议?
PlatformUI
在e4应用程序中不可用,请不要尝试使用它。
@PostConstruct
在LifeCycle类中做任何事情还为时过早。 您应该尝试执行任何操作的第一点是@PostContextCreate
方法。
您可以注入org.eclipse.e4.ui.workbench.IWorkbench
并调用close
方法来关闭e4应用程序。 但是,在应用程序启动完成之前,工作台不可用,因此您需要等待此事件。
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();
}
}
如果您正在使用SWT渲染器,则System.exit()是当前中止E4启动的唯一方法。
如果从e(fx)clipse使用JavaFX渲染器,则可以从@PostContextCreate返回FALSE到关闭状态。
有关更多信息,请参见以下博客: 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.