0

RCP开发人员,

我想postWindowClose()在我的ECLIPSE RCP应用程序中实现。

在编写这个方法之前,我只是做了一个小测试,看看当我关闭我的应用程序时,是否调用了该方法,所以我这样做了:

import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;


public class MainWindowControl extends WorkbenchWindowAdvisor{

    public MainWindowControl(IWorkbenchWindowConfigurer configurer) {
        super(configurer);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void postWindowClose() {
        // TODO Auto-generated method stub
        super.postWindowClose();
        System.out.println("close");
    }

}

我期待看到:closeECLIPSE控制台中,但关闭应用程序后它仍然是空白的。

添加了所有必需的插件,启动或关闭应用程序时我没有错误。

那么,我错过了什么吗?

实施此方法的原因是:

  1. 消息框:Are you sure you want to close the application
  2. 杀死所有正在运行的线程,我的应用程序上传文件,甚至当我关闭应用程序运行上传继续。我想在关闭应用程序时中止它们。

编辑 :

我的生命周期课程:

package upload.center.util;

import org.eclipse.e4.ui.workbench.lifecycle.PostContextCreate;
import org.eclipse.e4.ui.workbench.lifecycle.PreSave;

public class WindowLifeCycle {

 @PostContextCreate
 public void postContextCreate()
  {
    // TODO start up code here
     System.out.println("open");
  }

@PreSave
  public void preSave()
  {
     // TODO add shutdown code here
    System.out.println("close");
  }
}

我的 plugin.xml :

<product ....
<property
           name="windowLifeCycle"
           value="bundleclass://UploadCenter.Source/upload.center.util.WindowLifeCycle">
     </property>
 ...</product>

我希望我足够清楚。

伊斯梅尔

4

1 回答 1

2

对于纯 Eclipse 4 (e4) 应用程序,不使用工作台窗口顾问(和其他顾问)。您使用@PreSave生命周期类的方法在关闭期间运行代码。

public class LifeCycle
{
  @PostContextCreate
  public void postContextCreate()
  {
    // TODO start up code here
  }

  @PreSave
  public void preSave()
  {
     // TODO add shutdown code here
  }
}

在产品定义中声明生命周期类plugin.xml

<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 ...

有关更多详细信息,请参见此处

于 2014-02-26T10:04:25.667 回答