0

Hi RCP developers,

I want to iplement postWindowClose() in my ECLIPSE RCP application.

Before coding this method, I just did a small test to see if when I close my application, the method is called, so I did that :

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");
    }

}

I am expecting to see : close in ECLIPSE console, but it's still blank after closing the application.

All the required plugins are added , and I have no error while launching or closing the application.

So, AM I missing something ?

The reasons why to implemets this method are :

  1. Msg box : Are you sure you want to close the application
  2. Kill all the running threads, my application upload files and even when I close the application running uploads continues. I want to abort them when closing the application.

Edit :

My life cycle class :

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");
  }
}

My plugin.xml :

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

I hope that I am clear enough.

Ismail

Ismail Sen
  • 571
  • 2
  • 14
  • 27
  • I cannot reproduce your problem on Kepler. I get the opposite problem, in fact: `postWindowClose` is called *twice*. – Marko Topolnik Feb 26 '14 at 08:57
  • To understand the problem and before posting this question, I've created a simple `HelloWorld` application and implemented `postWindowClose`, the console reallys display `close`twice, but the difference is , the class that extends `WorkbenchWindowAdvisor`is generated. In my case, it wasn't there, so I had to created by myself. Another thing, in my project I have the `Application.e4xmi` which doesn't exist in the simple `HelloWorld` – Ismail Sen Feb 26 '14 at 09:24
  • And how have you registered your advisor with the RCP framework? The HelloWorld application has code which does that as well. – Marko Topolnik Feb 26 '14 at 09:42
  • 1
    This sounds like you have an Eclipse 4 (e4) application (using Application.e4xmi) which does not use the old WorkbenchWindowAdvisor (or any of the old 3.x stuff). – greg-449 Feb 26 '14 at 09:52
  • Yes @greg-449, I am using e4. So you are telling me that WorkBenchWindowAdvisor is deprecated in e4 ? – Ismail Sen Feb 26 '14 at 09:55
  • For a pure e4 application you can't use `org.eclipse.ui` code. WorkbenchWindowAdvisor is not used. – greg-449 Feb 26 '14 at 10:05

1 Answers1

2

For a pure Eclipse 4 (e4) application the workbench window advisor (and the other advisors) are not used. You use the @PreSave method of a life cycle class to run code during shutdown.

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

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

declare the life cycle class in the product definition in the 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 ...

For more details see here

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Could you please see my edit. I can't display `open` or `close` – Ismail Sen Feb 26 '14 at 10:40
  • @IsmailSen Is `UploadCenter.Source ` (with a trailing space) really the id of the plugin containing the life cycle class? – greg-449 Feb 26 '14 at 10:57
  • No there is no space, I've edited my post. It was a tape error. Here is my project organisation : `UploadCenter.Product` `UploadCenter.Feature` and `UploadCenter.Source`. The plugin.xml is in `UploadCenter.Source` – Ismail Sen Feb 26 '14 at 11:09
  • 1
    The property name **must** be `lifeCycleURI` not `windowLifeCycle` – greg-449 Feb 26 '14 at 11:13
  • I've changed `windowLifeCycle` to `lifeCycleURI` and `WindowLifeCycle` to `LifeCycle`. It wasn't working too. But, I did another modification , which I think is the most important : I've added to `property` `name` and `value` under the `extension`. `application` and not under the extension `product`, and know it's working as i want. Is it working for you under `extension` `prodcut` like in your answer ? – Ismail Sen Feb 26 '14 at 13:17
  • You don't normally have an `application` extension for e4 apps, you just use the `org.eclipse.e4.ui.workbench.swt.E4Application` application. – greg-449 Feb 26 '14 at 13:48
  • I've added a `MessageDialog` and `@PreDestroy`| `@PreSave` annotations. In both cases, the `MessageDialog` is displayed , but the application is already closed. Basing on this : [link](http://eclipsesource.com/blogs/tutorials/eclipse-4-e4-tutorial-part-6-behavior-annotations/) , I can't see another way to display my `MessageDialog` before closing the application. – Ismail Sen Mar 04 '14 at 10:12
  • 1
    If you are try to stop the application closing use an `IWindowCloseHandler`. – greg-449 Mar 04 '14 at 10:17
  • Now, `LifeCycle implements IWindwoCloseHanlder` and I've added a `Handler` in `Application.e4xmi`. Need to add more things ? – Ismail Sen Mar 04 '14 at 11:14
  • You can't do that. You need to ask a new question about how to use it. – greg-449 Mar 04 '14 at 11:43