Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop an Eclipse Editor from closing in an RCP

I am working on an Eclipse based RCP. We have a need to prevent one of the opened editors from being closed by the user.

The desired behavior is:

  1. the user clicks the X in the editor window or "CTRL+W"
  2. a dialog pops up saying: "If you close this editor, your activity will stop. Do you want to?"
  3. if they click yes, it closes, if no, it stays open.

Oh yeah, and is this even possible?

Thanks, gk

like image 642
GreenKiwi Avatar asked Oct 22 '25 16:10

GreenKiwi


1 Answers

You could use a org.eclipse.ui.ISaveablePart2, more specifically the method promptToSaveOnClose().

However, as said in this thread,

it will only be shown if the editor is dirty at the time it is closed.

See an example in this SaveableHelper.java source file.

See also the article Prevent that a RCP Editor is closed, which explains how this method works:

alt text

like image 94
VonC Avatar answered Oct 25 '25 04:10

VonC