A 3.* based RCP application will be restarted if IApplication.start returns IApplication.EXIT_RESTART. The class E4Application seems to always return EXIT_OK.
一个3。*基于RCP的应用程序将在IApplication时重新启动。开始返回IApplication.EXIT_RESTART。类E4Application似乎总是返回EXIT_OK。
org.eclipse.ui.IWorkbench also has a restart method, org.eclipse.e4.ui.workbench.IWorkbench does not.
引用。IWorkbench也有一个restart方法,org.eclipse.e4. workbench。IWorkbench没有。
So how can I restart an e4 RCP application?
那么如何重启e4 RCP应用程序呢?
3 个解决方案
#1
1
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
Eclipse 4.2中的当前实现将生成一个带有id org. eclipsee .ui.file的命令。restartWorkbench最终导致处理程序类RestartWorkbenchHandler。这个类实现如下。
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!
也就是说,它是Eclipse 3。依赖于x的,因为PlatformUI类在纯基于Eclipse 4的应用程序中不再可用。因此,如果您想在e4应用程序中解决此任务,请创建一个命令,实现处理程序,目前您将拥有一些E3代码依赖项!
#2
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.
在e4中引入这个特性之前,我的解决方案是这样的:我使用IApplication实现作为E4Application的包装器。这样,我就可以返回IApplication。EXIT_RESTART from start方法,Equniox将重新启动。
Beware though, that this workaround uses an internal API, which is likely to change in the future!
但是要注意,这个解决方案使用了一个内部API,这在将来可能会改变!
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:
当您想重新启动时,现在可以使用Singleton来设置返回值:
@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.
我在这里使用了单例,因为这样更容易解释。更好的解决方案是将IApplication注册为OSGi服务,并让DI将其注入到处理程序中。
#3
2
org.eclipse.e4.ui.workbench.IWorkbench
does now have a restart
method in Eclipse Kepler (4.3).
org.eclipse.e4.ui.workbench。IWorkbench现在在Eclipse Kepler(4.3)中有一个重新启动方法。
#1
1
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
Eclipse 4.2中的当前实现将生成一个带有id org. eclipsee .ui.file的命令。restartWorkbench最终导致处理程序类RestartWorkbenchHandler。这个类实现如下。
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!
也就是说,它是Eclipse 3。依赖于x的,因为PlatformUI类在纯基于Eclipse 4的应用程序中不再可用。因此,如果您想在e4应用程序中解决此任务,请创建一个命令,实现处理程序,目前您将拥有一些E3代码依赖项!
#2
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.
在e4中引入这个特性之前,我的解决方案是这样的:我使用IApplication实现作为E4Application的包装器。这样,我就可以返回IApplication。EXIT_RESTART from start方法,Equniox将重新启动。
Beware though, that this workaround uses an internal API, which is likely to change in the future!
但是要注意,这个解决方案使用了一个内部API,这在将来可能会改变!
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:
当您想重新启动时,现在可以使用Singleton来设置返回值:
@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.
我在这里使用了单例,因为这样更容易解释。更好的解决方案是将IApplication注册为OSGi服务,并让DI将其注入到处理程序中。
#3
2
org.eclipse.e4.ui.workbench.IWorkbench
does now have a restart
method in Eclipse Kepler (4.3).
org.eclipse.e4.ui.workbench。IWorkbench现在在Eclipse Kepler(4.3)中有一个重新启动方法。