So I have my IWorkbenchWiondow
object, window
.
I add this listener to it:
window.addPageListener(new IPageListener()
{
@Override
public void pageOpened(IWorkbenchPage page)
{
// method stub
}
/**
* Whenever the user tries to close the workbench window, this method gets called.
*/
@Override
public void pageClosed(IWorkbenchPage page)
{
if (MessageDialog.openQuestion(page.getWorkbenchWindow().getShell(), "Question", "Do you really want to close the application?"))
{
// YES, then no problem, close
return;
}
else
{
// NO
System.out.println("Now what?");
}
}
@Override
public void pageActivated(IWorkbenchPage page)
{
// method stub
}
});
How can I stop the window
from closing if the user says No
?
Or how can I achieve the same end result?
Caveat: I've only given this technique a minimal test and it appears to work as expected.
From the IWorkBenchWindow
get an IWorkbench object.
Add an IWorkbenchListener
to the workbench object.
The listener has a preShutdown
method that should allow you to veto the close.