Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 377345

Summary: Consumer of selection is called twice in ESelectionService
Product: [Eclipse Project] Platform Reporter: Thorsten Lichtenwalter <lichtes>
Component: UIAssignee: Oleg Besedin <ob1.eclipse>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: bsd, emoffatt, kai.toedter, nobody, ob1.eclipse, pwebster
Version: 4.2   
Target Milestone: 4.2 M7   
Hardware: All   
OS: All   
Whiteboard:

Description Thorsten Lichtenwalter CLA 2012-04-22 03:27:06 EDT
Build Identifier: I20120315-1300

While using the ESelectionService by Dependency Injection in the Eclipse 4.2.0 i discovered the following bug: the part which is consuming the selection is called twice.

Snippet of consuming part:
	@Inject
	public void setSelection( @Optional @Named(IServiceConstants.ACTIVE_SELECTION) IContact contact) {
…



Reproducible: Always
Comment 1 Oleg Besedin CLA 2012-04-27 14:47:47 EDT
I'll have a look at this.
Comment 2 Oleg Besedin CLA 2012-05-02 11:54:01 EDT
This turns out to be an interesting situation. The call stack looks like this:

Part context#set(org.eclipse.ui.output.selection)
-> SelectionAggregator 
-> -> Window context #set(org.eclipse.ui.selection)
	(1)
-> -> -> E4Applcation.RAT (active window to app)
-> -> -> -> Workbench context#set(org.eclipse.ui.selection)
!-> -> -> -> DetailsView.setSelection(Contact) line: 204	
	(2)
-> -> -> DetailsView.setSelection(Contact) line: 204	

The selection value is modified at the window level and causes selection update to fire (1); then the previously scheduled update from the window context fires (2). We have a RaT that updates value in the parent context and that causes first call. Of course from the Part's viewpoint this makes no sense as both values (the one set directly and the one set by RaT) are the same.
Comment 3 Oleg Besedin CLA 2012-05-02 14:20:19 EDT
I added an extra check for context children invalidation.

Git reference:

http://git.eclipse.org/c/platform/eclipse.platform.runtime.git/commit/?id=1cb899b8ee8e083da5db26f48e404506133dce4b
Comment 4 Oleg Besedin CLA 2012-05-04 11:13:31 EDT
Verified in I20120503-1800.