Question

I can get opened editors

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

this way, but they are unordered(always returned the same way, it doesnt matter which window is first and which second). For plugin I implement its important for me to get them in order they are opened it, is there any way to do that?

Was it helpful?

Solution

There's some indication here that you can't get what you want directly from the API.

But how about this: register an IPartListener (or, better yet, IPartListener2) with the page's IPartService. Then you ought to get part-opened and part-closed messages. From that you can keep your own ordering of editor parts (IEditorPart). You can use that directly, or combine it with what you get from getEditorReferences().

So I'm talking about something like:

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().addPartListener(
   new IPartListener2() {
      private Stack<IWorkbenchPartReference> partStack = new Stack<IworkbenchPartReference>();

      public void partOpened(IWorkbenchPartReference ref) {
          partStack.push(ref);
      }

      public void partClosed(IWorkbenchPartReference ref) {
          partStack.pop(ref);
      }

      /* you'll need to implement or stub out the other methods of IPartListener2 */
      public void partActivated(IWorkbenchpartReference ref) {}
      public void partDeactivated(IWorkbenchpartReference ref) {}
      /* etc */

   }
);

Then you'll access that stack in your plugin.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top