Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sapphire » Adding listener to a ListSelectionService from outside Sapphire?
Adding listener to a ListSelectionService from outside Sapphire? [message #1008459] Tue, 12 February 2013 15:22 Go to next message
Ellen Badgley is currently offline Ellen Badgley
Messages: 35
Registered: October 2012
Member
First of all: Sapphire is pretty darn amazing and is substantially changing the way we do XML editing within several projects. Kudos!

On to my question:

I'm in a situation where I need to link a separate View with my Sapphire editor, such that changes to the model in one are reflected instantly in the other, and vice-versa. (For more details: Sapphire is used to edit a model that defines several geolocated objects, and we have a Worldwind-based view that can be used to edit the locations and characteristics of the model objects as well.) I'm finding it difficult to locate examples of this kind of interaction to build from.

As a simple use case: we have a list property editor used to define a list of sensors, and selecting a sensor from the list should cause the corresponding object in the Worldwind view to be highlighted (and vice-versa).

Is there a recommended way to locate the correct ISapphirePart for access to the ListSelectionService, so that I can add an external listener for the selection change?
Re: Adding listener to a ListSelectionService from outside Sapphire? [message #1008716 is a reply to message #1008459] Wed, 13 February 2013 17:28 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin Komissarchik
Messages: 942
Registered: July 2009
Senior Member
You will need to locate your editor in the workbench, grab its root Sapphire part and traverse through parts until you find the one that you need. There isn't much in a way of convenience API to simplify searching through the parts. If you think of something that would be helpful, do suggest that on this forum or open an enhancement request in bugzilla.

You will also want to listen on the part's dispose event. Depending on the parts above the list property editor, some event in the editor can cause the list property editor to be disposed and possibly re-created.

- Konstantin

PS: When you need a break from development, tell us more about the cool things you are doing with Sapphire on the adopters wiki.

http://wiki.eclipse.org/Sapphire/Adopters
Re: Adding listener to a ListSelectionService from outside Sapphire? [message #1008717 is a reply to message #1008716] Wed, 13 February 2013 17:31 Go to previous messageGo to next message
Ellen Badgley is currently offline Ellen Badgley
Messages: 35
Registered: October 2012
Member
Konstantin,

Thanks very much. I was suspecting that something like that might be the case (and if I come up with any good suggestions as to how to streamline it, I'll be sure to suggest them).

Will definitely see if we can post some examples once we get the Worldwind link up and running!

- Ellen
Re: Adding listener to a ListSelectionService from outside Sapphire? [message #1037486 is a reply to message #1008717] Tue, 09 April 2013 16:05 Go to previous messageGo to next message
Ellen Badgley is currently offline Ellen Badgley
Messages: 35
Registered: October 2012
Member
An update: I've been able to get the interactions between the Sapphire editor and my WorldWind-based View up and running, by locating the PropertyEditorPart (which only took about 20 lines of code) and accessing the ListSelectionService as described above.

Now I have a new wrinkle: I'd like to retrieve and set list selections for two separate list property editors, on two separate FormEditorPages. Basically I have two list properties within my model, each of which contains a list of geolocated objects (Sensors and FusionCenters). Only one object at a time (out of the full set of both types) can be highlighted in the linked map view.

Accordingly, if the user has a Sensor selected and they switch pages and select a FusionCenter from the other list property editor, I'd like to tell the ListSelectionService on the Sensors list to clear the selection. I've tried the following:

sensorSelectionService.select((Sensor)null);


but I'm getting an exception on that line of code, like so:

java.lang.IllegalArgumentException
	at org.eclipse.sapphire.ui.PageBookPart.changePage(PageBookPart.java:255)
	at org.eclipse.sapphire.ui.PageBookPart.changePage(PageBookPart.java:247)
	at org.eclipse.sapphire.ui.SapphireListControlledPageBook$2$1.run(SapphireListControlledPageBook.java:155)
	at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:180)
	at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
	at org.eclipse.swt.widgets.Display.syncExec(Display.java:4683)
	at org.eclipse.sapphire.ui.SapphireListControlledPageBook$2.handle(SapphireListControlledPageBook.java:159)
	at org.eclipse.sapphire.ListenerContext$BroadcastJob.run(ListenerContext.java:182)
	at org.eclipse.sapphire.ListenerContext.broadcast(ListenerContext.java:120)
	at org.eclipse.sapphire.ListenerContext.broadcast(ListenerContext.java:127)
	at org.eclipse.sapphire.services.Service.broadcast(Service.java:126)
	at org.eclipse.sapphire.ui.ListSelectionService.select(ListSelectionService.java:65)
        ...


What am I doing wrong here? Is it appropriate or possible to call select(null) on a ListSelectionService, or is there another approach I should be taking?
Re: Adding listener to a ListSelectionService from outside Sapphire? [message #1037513 is a reply to message #1037486] Tue, 09 April 2013 16:50 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin Komissarchik
Messages: 942
Registered: July 2009
Senior Member
It looks like the IModelElement variant of select method does not handle null by either throwing an exception of treating it as an empty selection. Could you open a bug for this?

The List variant of the select method should work. Just pass in an empty list.

- Konstantin
Re: Adding listener to a ListSelectionService from outside Sapphire? [message #1038190 is a reply to message #1037513] Wed, 10 April 2013 14:22 Go to previous message
Ellen Badgley is currently offline Ellen Badgley
Messages: 35
Registered: October 2012
Member
Done! https://bugs.eclipse.org/bugs/show_bug.cgi?id=405367
Previous Topic:Implementing multiple Services on the same Property?
Next Topic:DerivedValueService not working
Goto Forum:
  


Current Time: Sat Oct 25 13:27:38 GMT 2014

Powered by FUDForum. Page generated in 0.02018 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software