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.