Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Selection service is triggered on focus for a treeviewer ?
Selection service is triggered on focus for a treeviewer ? [message #1059200] Fri, 17 May 2013 09:14 Go to next message
Oliver Kolling is currently offline Oliver KollingFriend
Messages: 24
Registered: April 2010
Junior Member
I have two independent tree viewer on two different parts in my application which on selection of a tree item are calling setSelection(item) for the selection service.
searchRsltTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
			public void selectionChanged(SelectionChangedEvent event) {
				IStructuredSelection selection = (IStructuredSelection) event.getSelection();
				// set the selection to the service
				selectionService.setSelection(
						//-- return always the first selected element
						selection.getFirstElement());
			}
		});


My third part receives the selection then via @Inject
	public void setSelection(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) Object selObj) {}


So far nothing special. But the special here is the behavior. When in both tree viewers different objects are selected, my third part will receive the selection from the tree viewer that gets the focus. And by focus I mean focus not selection. The third part toggles between the two selected tree objects when clicking on the tree viewers scroll bars or the parts hosting them. Even better: when debugging, the switch in selection is done without running into the selectionChangeListener-code. If this is some sort of wanted behavior/feature, how can I suppress/dissable this. IMHO this should only happen when I explicitly put code for that under the @Focus.

But when I use the @Focus it is executed after the selection service is set ....?
Re: Selection service is triggered on focus for a treeviewer ? [message #1059515 is a reply to message #1059200] Mon, 20 May 2013 08:23 Go to previous messageGo to next message
Sopot Cela is currently offline Sopot CelaFriend
Messages: 597
Registered: December 2010
Senior Member

I'm not sure I got this correctly but if you have two parts which have set a selection (have an entry in the tree selected) and a single point of consumption, the selection at a certain point in time is called the selection in anyone of the trees which is focused, no (*active*_selection)? Suppose you have 10 parts and all of them have tree viewers, which one would you call the selected object to be consumed in the 11th part? In the IDE for example you can have the Outline and the Project Explorer trees which both have a selection but one has focus and the other is selected but not focused (it is grayed out). At that moment the active selection makes sense to be the focused one.

Internally this happens because of the switching of the active context which causes a reinjection. If you don't want this behavior than put the values in the parent context with separate keys so you can respond differently to selection change in different parts.
Re: Selection service is triggered on focus for a treeviewer ? [message #1059655 is a reply to message #1059515] Tue, 21 May 2013 06:34 Go to previous message
Oliver Kolling is currently offline Oliver KollingFriend
Messages: 24
Registered: April 2010
Junior Member
If I'm right, the bottom-line of your comment is, that switching between the active parts triggers a re-injection of the active selection in the parent context. In that case "separate keys" would be a work around, I agree, but that's exactly my point. I see that this behavior might be helpful in some situations, but I think it should be controllable in some way, like via the @Focus. My point is, that it is not a good idea to auto-trigger the re-injection (if it can not be controlled by the developer), when the tree receives the focus - it might be more reasonable on selection change ?
Previous Topic:The visibleWhen of toolbar does not work well on Eclipse 4.2
Next Topic:"Install new software" window not showing properly in Debian 7
Goto Forum:
  


Current Time: Fri Nov 28 19:44:08 GMT 2014

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

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