3

A 3.* based RCP application will be restarted if IApplication.start returns IApplication.EXIT_RESTART. The class E4Application seems to always return EXIT_OK.

org.eclipse.ui.IWorkbench also has a restart method, org.eclipse.e4.ui.workbench.IWorkbench does not.

So how can I restart an e4 RCP application?

4 Answers 4

2

The current implementation in Eclipse 4.2 leads to a command with id org.eclipse.ui.file.restartWorkbench which ultimately leads to the handler class RestartWorkbenchHandler. This class is implemented as follows

public Object execute(ExecutionEvent event){

    PlatformUI.getWorkbench().restart();
    return null;
}

Which means, that it is Eclipse 3.x dependent, as the PlatformUI class is not available in a pure Eclipse 4 based application anymore. So if you want to solve this task in your e4 Application, create a command, implement the handler and currently you will have some E3 code dependency!

2

Until this feature is introduced into e4 my workaround goes like this: I use my IApplication implementation as a wrapper to the E4Application. This way, I can return IApplication.EXIT_RESTART from the start method and Equniox will do the restart.

Beware though, that this workaround uses an internal API, which is likely to change in the future!

package de.emsw.gosa.e4.application;

import org.eclipse.e4.ui.internal.workbench.swt.E4Application;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;

public class MyE4Application implements IApplication {

    private static MyE4Application instance;

    public static MyE4Application getInstance() {
        return instance;
    }

    private Integer exitRet = IApplication.EXIT_OK;
    private E4Application e4app;

    public void setRestart() {
        exitRet = IApplication.EXIT_RESTART;
    }

    @Override
    public Object start(IApplicationContext context) throws Exception {
        instance = this;
        e4app = new E4Application();
        e4app.start(context);
        return exitRet;
    }

    @Override
    public void stop() {
        e4app.stop();
    }
}

When you you want to restart, you can now use the Singleton to set the return value:

@Execute
public void execute(IWorkbench workbench) {
    MyE4Application.getInstance().setRestart();
    workbench.close();
}

I used a Singleton here, because it is easier to explain this way. A better solution is to register your IApplication as an OSGi service and have DI inject it into your handler.

2

org.eclipse.e4.ui.workbench.IWorkbench does now have a restart method in Eclipse Kepler (4.3).

0

You can Try this

    public void restart() {Display.getDefault().asyncExec(new Runnable(){
         @Override
          public void run() {
          PlatformUI.getWorkbench().restart();
        }
    });
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.