简体   繁体   English

Eclipse RCP-如何在工作台初始化之前关闭

[英]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.

相关问题 使用Eclipse RCP进行工作台应用程序开发::可以增加多少? - Workbench application development using Eclipse RCP :: How rich can it get? 如何在Eclipse RCP中重置工作台零件(仅一个视图) - How to reset a workbench part (one view alone) in eclipse RCP 如何在eclipse rcp中编辑workbench.xml的特定节点的值 - how to edit values of specific nodes of workbench.xml in eclipse rcp 不要在Eclipse RCP应用程序中保存工作台状态 - Do not save workbench state in a eclipse RCP app Eclipse RCP 4.10 Workbench本地文件历史记录 - Eclipse RCP 4.10 Workbench local file History 在Eclipse RCP中以编程方式关闭嵌入式Jetty服务器 - Shutdown Embedded Jetty Server programmatically in Eclipse RCP 将选择侦听器添加到Eclipse RCP Workbench时,应该如何知道要使用的ID? - When adding a selection listener to the Eclipse RCP Workbench how are you supposed to know the ID to use? 如何在RCP工作台工具栏和RCP视图之间进行通信 - How to communicate between a RCP workbench toolbar and RCP views 是否可以在Eclipse-RCP中为ViewPart或Workbench定义最小尺寸? - Is possible to define a minimum size for a ViewPart or Workbench in Eclipse-RCP? 为Eclipse RCP应用程序添加Shutdown Hook的正确方法是什么? - What is the correct way to add a Shutdown Hook for an Eclipse RCP application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM