[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: How to notify View of Editor changes

OK - I found this answer for myself, but thought I'd note it here for future reference, plus details of some curious behaviour which somebody may be able to help me with.

SOLUTION:

I register each editor's viewer with the site, using code of the form:

   getSite().setSelectionProvider(myViewer);

In my view, I have registered a listener to handle events from my editor(s), thus:

   getSite().getPage().addSelectionListener(mySelectionListener);

PROBLEM:

The issue I have is that if I specify a typeId as the first parameter for the 'addSelectionListener' method, then I *only* seem to get events for the most recently created editor instance. However, if I do not give a typeId then I get events for all instances (which is what I want).

This would be fine, since I can always filter on the class of the IWorkbenchPart that gets passed into my handler. However, this does not work for the null case (which I also need to process). In this case I can't test the part because it is null. However in the case of the null handler the registration process seems to work correctly when I give the optional typeId in the call to 'addSelectionListener' (though only for null events).

I have therefore had to register two handlers - one with no typeId specified to process 'normal' events (doing hand-written filtering), and a special null handler which is registered using a typeId and which *only* processes null events.

Note: my 'normal' handler implemented the INullHandler interface, since I wanted it to process both normal and null events.

As always - any advice most appreciated.

   Andy D


Andy D wrote:

I have a view defined whose purpose is to show some details for the currently selected item in my editor - both the editor and view are optional (though obviously the view will be empty if the editor does not exist or does not have a current selection).

What is the recommended way of connecting these two 'things' so that the event get propagated correctly and that the lifetimes etc are also managed correctly?

My guess is that I need to register the view with some common 'manager' - e.g. the workspace - which can then be notified by the editor(s), but there do not appear to be any built-in mechanisms for me to use (or more likely, I can't find them).

Any advice would be gratefully received