Prompt user before closing Eclipse / RCP application

The following snippet prompts the user before the RCP application gets closed. The method "preShutdown" must be overwritten in "ApplicationWorkbenchAdvisor".

@Override
public boolean preShutdown() {
 boolean canClose = super.preShutdown();
 if (canClose) {
  canClose = true;
  IWorkbench workbench = PlatformUI.getWorkbench();
  final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();

  MessageBox dialog = new MessageBox(window.getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
  dialog.setText("Close?");
  dialog.setMessage("Do you want to close the application?");
  int result = dialog.open();

  if(result == SWT.YES) {
   canClose = true;
  } else {
   canClose = false;
  }  
 }
 return canClose;
}

Werbung



comments powered by Disqus

Copyright Dunkel & Iwer GbR | Datenschutzerklärung | Impressum