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
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.