Tuesday, August 17, 2010

Closing Editors

IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorReference[] editors = page.getEditorReferences();
for (int i = 0; i < editors.length; i++) {
IEditorInput otherInput;
try {
otherInput = editors[i].getEditorInput();
return page.closeEditor(editors[i].getEditor(false), false);
} catch (PartInitException e) {
handleException(e);
}
}

3 comments:

Prakash G. R. said...

IWorkbenchPage.closeAllEditors() would do

Aravind said...

Thanks Prakash

Aravind said...

Suppose, if we are having 3 editors opened and only need to close 1 of them which is deleted from an other view...(for ex: the object is deleted from a tree) we have done this way by passing the object to the close editor method.

Would that be fine?