Eclipse shut down hook able to stop the termination

后端 未结 1 1501
滥情空心
滥情空心 2021-01-24 12:22

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

相关标签:
1条回答
  • 2021-01-24 12:45

    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.

    0 讨论(0)
提交回复
热议问题