views:

393

answers:

2

I have built a simple Eclipse plugin where a user may use a tableViewer of database resources to open an editor on any of those resources.

Users may therefore have zero upwards instances of the editor running.

Is there an API available to get a list of those editor instances?

M.

+1  A: 

You can get references to all open editors with:

PlatformUI.getWorkbench().getActiveWorkbenchWindow()
    .getActivePage().getEditorReferences();

And then check these to select the ones that reference instances of your editor type.

Fabian Steeg
A: 

Be aware the such an enumeration will not respect the tab order

Here is an example of an enumeration of editors:

IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
IWorkbenchPage page = window.getActivePage();
IEditorPart actEditor = page.getActiveEditor();
IEditorReference[] editors = page.getEditorReferences();
for (int i=0; i<editors.length-1; i++) {
  if (editors[i].getEditor(true) == actEditor) {
    page.activate(editors[i+1].getEditor(true));
    return null;
  }
}
VonC