簡體   English   中英

Eclipse RCP-如何在工作台初始化之前關閉

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM