Eclipse关闭钩可以停止终止 [英] Eclipse shut down hook able to stop the termination
问题描述
我刚刚发现如何挂断出来的命令来清理思考。 (插件的激活器具有 stop()
方法。)但是Eclipse将永远终止。
一位同事帮我解决问题。解决方案其实很简单。所有我需要的是一个注册激活器的worgbench监听器。监听器有两种方法用于事件之前和后期。第一个返回布尔值。如果它返回true,则Eclipse退出。否则出口程序中断,用户可以继续工作。
在激活类中:
public void start(BundleContext context){
...
IWorkbench iwb = PlatformUI.getWorkbench();
WBListener wbl = new ...;
iwb.addWorkbenchListener(wbl);
...
}
课程代码 WBListener
:
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchListener;
public class WBListener实现IWorkbenchListener {
@Override
public void postShutdown(IWorkbench w){
}
@覆盖
public boolean preShutdown(IWorkbench w,boolean b){
boolean exitEclipse = ...; //得到它某种方式
return exitEclipse;
}
}
这些都是。
I'm working on a plugin. The plugin executes external tools and I have to provide a confirm dialog, if the user tries to exit Eclipse, when a process is running yet. There are running processes. Do you really want to exit? If the user clicks No, the Eclipse may not terminate.
I've just found, how to hook the exit command to clean thinks up. (The plugin's activator has the stop()
method.) But the Eclipse will always terminate inevitably.
One colleague helped me to solve the problem. The solution is actually easy. All I need is a worgbench listener registered in activator. The listener has two methods for events pre- and postshutdown. The first one returns boolean. If it has returned true, the Eclipse exits. Otherwise the exit procedure is interrupted and the user can continue in his work.
In activator class:
public void start(BundleContext context) {
...
IWorkbench iwb = PlatformUI.getWorkbench();
WBListener wbl = new ...;
iwb.addWorkbenchListener(wbl);
...
}
The code of class WBListener
:
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchListener;
public class WBListener implements IWorkbenchListener {
@Override
public void postShutdown(IWorkbench w) {
}
@Override
public boolean preShutdown(IWorkbench w, boolean b) {
boolean exitEclipse = ...; //get it somehow
return exitEclipse;
}
}
That's all.
这篇关于Eclipse关闭钩可以停止终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!