How to stop the Eclipse editor from closing in RCP

I am working on Rcl based on Eclipse. We need to prevent the user from closing one of the open editors.

Desired behavior:

  • user presses X in the editor window or "CTRL + W"
  • a dialog box appears that says: "If you close this editor, your activity will stop. Do you want to?"
  • if they click yes, it closes; if not, it remains open.

Oh yes, and is it possible?

Thanks dk

+3
source share
3 answers

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

However, as said in this thread ,

, .

. SaveableHelper.java .

. RCP, , :

alt text

+6

@Override
public void doSave(IProgressMonitor monitor) {

monitor.setCanceled(true);

EditorPart

+4

, , , .

page.addPartListener(new IPartListener2() {
    // [...]
    @Override
    public void partClosed(IWorkbenchPartReference partRef) {
        try {
            page.openEditor(input, id);
        } catch (PartInitException e) {
            e.printStackTrace();
        }
    }
});
+1

Source: https://habr.com/ru/post/1730438/


All Articles