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

后端 未结 3 621
轻奢々
轻奢々 2021-01-01 06:37

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
相关标签:
3条回答
  • 2021-01-01 06:51

    You can also cancel the saving in

    @Override
    public void doSave(IProgressMonitor monitor) {
    

    by calling

    monitor.setCanceled(true);
    

    In the EditorPart implementation

    0 讨论(0)
  • 2021-01-01 06:53

    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

    0 讨论(0)
  • 2021-01-01 07:05

    Not directly related but I was looking for a way to prevent an Editor to be closed and found this little hack, hope it could help.

    page.addPartListener(new IPartListener2() {
        // [...]
        @Override
        public void partClosed(IWorkbenchPartReference partRef) {
            try {
                page.openEditor(input, id);
            } catch (PartInitException e) {
                e.printStackTrace();
            }
        }
    });
    
    0 讨论(0)
提交回复
热议问题