Eclipse RCP - managing selections.

This might be a little obscure for here, but I know theres a couple of people who’ve used the Eclipse RCP around here so it’s worth a shot…

I’m making a level editor, so far I have two views and an editor which I’m trying to make communicate.

The user selects a level element (enemy, powerup, etc.) from the ‘pallete’ (which is a view), and can then draw one or more of these onto the canvas (an editor). A ‘properties’ view shows details of the current element instance within the editor (so they can change properties about that specific instance in the level).

Currently these selections are managed via selection providers and the selection service, so it’s all event based and no part ever has to directly talk to another part.

  1. However when a new editor is opened it doesn’t know what the current element selection is (since the original selection change event was triggered way before it was created).

I had initially tried using a part listener in the pallete and refreshing/reselecting the selection whenever a new editor is opened. Unfortunately this only works when the pallete has the focus - if a new editor is opened and the focus is elsewhere then the the selection listeners for the pallete have been removed and republishing the selection has no effect.

Currently my workaround is for the editor to manually find the correct part, cast it to my concrete pallete class, and query it for the current selection. This feels hacky and tightly couples the two together. Does anyone know a better way of doing this?

  1. Similarly when an editor is closed I need to send a null/empty selection changed event so that the properties view doesn’t show information about an instance which has been closed. I’ve tried using the dispose() of the editor to do this, but by this time it seems that all the selection listeners have been unregistered so it has no effect. Is there any other events I can hook into when the editor is being closed so I can send an updated selection?

Any ideas or pointers appreciated. Thanks.