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

筅森魡賤 提交于 2019-11-30 15:44:57
VonC

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:

You can also cancel the saving in

@Override
public void doSave(IProgressMonitor monitor) {

by calling

monitor.setCanceled(true);

In the EditorPart implementation

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();
        }
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!