Eclipse关闭钩可以停止终止 [英] Eclipse shut down hook able to stop the termination

查看:338
本文介绍了Eclipse关闭钩可以停止终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个插件。插件执行外部工具,如果用户尝试退出Eclipse,当进程运行时,我必须提供一个确认对话框。正在运行进程。您真的要退出吗?如果用户点击,Eclipse可能不会终止。



我刚刚发现如何挂断出来的命令来清理思考。 (插件的激活器具有 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆