Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » IServiceConstants.ACTIVE_SELECTION gotcha(limits use as a selectionChanged event)
IServiceConstants.ACTIVE_SELECTION gotcha [message #1758899] Tue, 04 April 2017 11:12 Go to next message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
I saw an example (vogella) suggesting use of injected IServiceConstants.ACTIVE_SELECTION to decouple monitoring of selection changed events ... the code example below. I used this in two MParts for signalling selectionchanged events, with the potential benefits of it being isolated locally per Window, without having to specify the specific viewer.

public void setTodo(@Optional

However, I discovered during debug that just alternating selection of the two MPart menu bars would fire off events to the listener above, even though the treeviewer's selection hadn't changed!

So, for my case, where I really need to know that the tree selection has changed, I can't use this method without having to figure out how to screen for this extra selectionChanged event.

Anyone solved this kind of problem previously? I fell back to using IEventBroker events as a workaround, as demo'd in another piece of his examples below, but that gives up the IEclipseContext isolation.

private void subscribeTopicTodoUpdated
Todo todo) {
Re: IServiceConstants.ACTIVE_SELECTION gotcha [message #1759426 is a reply to message #1758899] Tue, 11 April 2017 07:38 Go to previous message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 876
Registered: January 2012
Senior Member

Realize that any parts that provide a selection will trigger your `ACTIVE_SELECTION` listener. The active selection is an example of a context variable in the IEclipseContext hierarchy. It's a named value that is hosted at some point in the context hierarchy. To change a variable, you use `IEclipseContext#modify("name", value)` instead of `#set("name", value)`: `#modify()` will climb the hierarchy to find the variable and then sets that value there.

You can define a context variable either by hand via `IEclipseContext#declareModifiable()` on the appropriate context (e.g., the window context), or
by declaring in your E4 model either using the model editors (Supplementary > Variables) or programmatically via `MContext#getVariables()`.

Checkout the wiki page on contexts:


Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Previous Topic:Eclipse Hang w/ JDK 1.8.0_121
Next Topic:Eclipse 4 on ARM?
Goto Forum:

Current Time: Sat Sep 19 13:40:38 GMT 2020

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

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

Back to the top