ViewPart Command Handler ActivePart vs EventSource
===

I have run into a problem with development of my Eclipse RCP Application that I believe is related to my lack of understanding of the platform architecture.

I have a ViewPart that has a TreeViewer with a ContextMenu.  The ContextMenu has Commands that are handled by IHandlers like so:

    @Override
	public Object execute(ExecutionEvent event) throws ExecutionException {

		final MyInterface i = (MyInterface)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().getActivePart().getAdapter(MyInterface.class);
        i.doStuff();

    }

I use this approach pervasively, but I have a feeling that it's the wrong way to do things in the case of a context menu.

If the event were generated by a MainMenu button, or a Keyboard Event, I could see how this (commands architecture) works well, however in the case of a context menu, I need to reference the ViewPart where the context menu appeared, not necessarily the active part.  In fact, sometimes the user can bring up the context menu without that part becoming active, so I had to use a hack like so:

    getViewer().getTree().addMouseListener(new MouseAdapter(){

			public void mouseDown(MouseEvent e){
				IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
				if (activePage != null) 
					activePage.activate(this);
			}

		});

My understanding is that the following does the same and simply returns the active part, not necessarily anything related to the source of the event:

    HandlerUtil.getActivePart(event)


Any advice is greatly appreciated!

/P
