Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 342917 - [Compatibility] Show In > Outline or Package Explorer reveals wrong element
Summary: [Compatibility] Show In > Outline or Package Explorer reveals wrong element
Status: VERIFIED FIXED
Alias: None
Product: e4
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 1.0   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 4.1 RC1   Edit
Assignee: Paul Webster CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-15 00:43 EDT by Harendra CLA
Modified: 2011-05-16 22:55 EDT (History)
8 users (show)

See Also:


Attachments
Test class (90 bytes, text/x-java)
2011-04-15 00:44 EDT, Harendra CLA
no flags Details
Fixes ShowIn issue (2.28 KB, patch)
2011-04-26 14:22 EDT, Jesse CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Harendra CLA 2011-04-15 00:43:41 EDT
Build Identifier: I20110407-2200

Eclipse version:I20110407-2200
OS: Ubuntu Linux 10.10
Java Version: JRE 1.6.0 IBM Linux build pxi3260sr9fp1-20110208_03 (SR9 FP1)
Locale: ja_JP.utf8

Reproducible: Always

Steps to Reproduce:
1.Create a new Java project and create a new class with few methods or use the class provides.
2.Click on one of the methods and right click, show in->Outline.
3.The outline view will point at a different method.
Comment 1 Harendra CLA 2011-04-15 00:44:52 EDT
Created attachment 193322 [details]
Test class
Comment 2 Prakash Rangaraj CLA 2011-04-15 00:50:59 EDT
Works for me
Comment 3 Prakash Rangaraj CLA 2011-04-15 01:38:43 EDT
Harendra,

     Are you on e4?
Comment 4 Kentaroh Noji CLA 2011-04-15 02:10:09 EDT
The same problem happens in Windows 7 with Eclipse V4.1. 
The problem does not happen on Eclipse v3.6/3.7.
Comment 5 Harendra CLA 2011-04-15 03:02:39 EDT
(In reply to comment #3)
> Harendra,
> 
>      Are you on e4?

Yes I don't know how, but somehow the versions has changed from 4.1 to 3.7 on bug report. Not being able to revert either. Please refer to the build ID. Sorry for the inconvenience.
Comment 6 Prakash Rangaraj CLA 2011-04-15 03:23:40 EDT
(In reply to comment #5)
> (In reply to comment #3)
> > Harendra,
> > 
> >      Are you on e4?
> 
> Yes I don't know how, but somehow the versions has changed from 4.1 to 3.7 on
> bug report. Not being able to revert either. Please refer to the build ID.
> Sorry for the inconvenience.
 
    No, its my mistake. Usually people leave the version to the default (4.1), but the bug would be in 3.7. So when triaging I change it 3.7. This is a bug for e4 then :-)
Comment 7 Dani Megert CLA 2011-04-15 04:15:49 EDT
In order to consistently reproduce (I used 4.1 M6) in the Outline view one needs to disable 'Link With Editor' via Outline view's view menu. Otherwise the selection is "fixed" by the auto-linking. Selecting a method declaration in the Java editor and then either
    Show In > Outline
or
    Show In > Package Explorer
does most of the time not reveal the correct method in the view.

The bug is not related to DBCS and as mentioned in comment 4 doesn't happen in 3.x.
Comment 8 Jesse CLA 2011-04-26 14:22:25 EDT
Created attachment 194086 [details]
Fixes ShowIn issue

The reason why the wrong element is shown in the Package Explorer and Outline view is because the selected element is only being updated when switching between views. If you select another method within the editor when it's already active, nothing is updated. 

This patch fixes that issue, but there is one awkwardness when selecting a method in the editor when it's not active:
org.eclipse.ui.internal.WorkbenchPage.updateShowInSources(MPart) gets called twice when selecting a method in the editor when it's NOT currently in focus. The first call to 			window.getContext().set(ISources.SHOW_IN_SELECTION, context.getSelection()) is setting the wrong method selection, but the second call sets it to the correct one. I'm not too sure why this is...


Here is the stack trace for when the selection gets updated to the wrong element:

java.lang.Throwable
	at java.lang.Thread.dumpStack(Thread.java:417)
	at org.eclipse.ui.internal.WorkbenchPage.updateShowInSources(WorkbenchPage.java:373)
	at org.eclipse.ui.internal.e4.compatibility.SelectionService$1.selectionChanged(SelectionService.java:76)
	at org.eclipse.e4.ui.internal.workbench.SelectionServiceImpl.notifyListeners(SelectionServiceImpl.java:123)
	at org.eclipse.e4.ui.internal.workbench.SelectionServiceImpl.access$3(SelectionServiceImpl.java:119)
	at org.eclipse.e4.ui.internal.workbench.SelectionServiceImpl$2.changed(SelectionServiceImpl.java:157)
	at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(TrackableComputationExt.java:91)
	at org.eclipse.e4.core.internal.contexts.EclipseContext.processScheduled(EclipseContext.java:326)
	at org.eclipse.e4.core.internal.contexts.EclipseContext.set(EclipseContext.java:343)
	at org.eclipse.e4.ui.internal.workbench.PartSelectionServiceImpl.setSelection(PartSelectionServiceImpl.java:66)
	at org.eclipse.ui.internal.e4.compatibility.SelectionService.selectionChanged(SelectionService.java:319)
	at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:164)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
	at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
	at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:162)
	at org.eclipse.jface.text.TextViewer.fireSelectionChanged(TextViewer.java:2732)
	at org.eclipse.jface.text.TextViewer.selectionChanged(TextViewer.java:2711)
	at org.eclipse.jface.text.TextViewer$4.widgetSelected(TextViewer.java:1830)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:240)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:774)
	at org.eclipse.swt.custom.StyledText.sendSelectionEvent(StyledText.java:8033)
	at org.eclipse.swt.custom.StyledText.clearSelection(StyledText.java:1710)
	at org.eclipse.swt.custom.StyledText.doMouseLocationChange(StyledText.java:2811)
	at org.eclipse.swt.custom.StyledText.handleMouseDown(StyledText.java:6000)
	at org.eclipse.swt.custom.StyledText$7.handleEvent(StyledText.java:5635)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4150)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3739)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$7.run(PartRenderingEngine.java:873)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:789)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:87)
	at org.eclipse.ui.internal.Workbench$3.run(Workbench.java:542)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:522)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
	at java.lang.reflect.Method.invoke(Method.java:611)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)



Then it gets called again about a second later with the correct selection:

java.lang.Throwable
	at java.lang.Thread.dumpStack(Thread.java:417)
	at org.eclipse.ui.internal.WorkbenchPage.updateShowInSources(WorkbenchPage.java:373)
	at org.eclipse.ui.internal.e4.compatibility.SelectionService$1.selectionChanged(SelectionService.java:76)
	at org.eclipse.e4.ui.internal.workbench.SelectionServiceImpl.notifyListeners(SelectionServiceImpl.java:123)
	at org.eclipse.e4.ui.internal.workbench.SelectionServiceImpl.access$3(SelectionServiceImpl.java:119)
	at org.eclipse.e4.ui.internal.workbench.SelectionServiceImpl$2.changed(SelectionServiceImpl.java:157)
	at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(TrackableComputationExt.java:91)
	at org.eclipse.e4.core.internal.contexts.EclipseContext.processScheduled(EclipseContext.java:326)
	at org.eclipse.e4.core.internal.contexts.EclipseContext.set(EclipseContext.java:343)
	at org.eclipse.e4.ui.internal.workbench.PartSelectionServiceImpl.setSelection(PartSelectionServiceImpl.java:66)
	at org.eclipse.ui.internal.e4.compatibility.SelectionService.selectionChanged(SelectionService.java:319)
	at org.eclipse.jface.text.TextViewer.firePostSelectionChanged(TextViewer.java:2749)
	at org.eclipse.jface.text.TextViewer.firePostSelectionChanged(TextViewer.java:2697)
	at org.eclipse.jface.text.TextViewer$5.run(TextViewer.java:2676)
	at org.eclipse.swt.widgets.Display.runTimer(Display.java:4251)
	at org.eclipse.swt.widgets.Display.messageProc(Display.java:3338)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2525)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3737)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$7.run(PartRenderingEngine.java:873)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:789)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:87)
	at org.eclipse.ui.internal.Workbench$3.run(Workbench.java:542)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:522)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
	at java.lang.reflect.Method.invoke(Method.java:611)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Comment 9 Dani Megert CLA 2011-04-27 03:01:30 EDT
Maybe the service listens for normal selection and post-selection? Also note that textual editors do not send out a selection changed event if the selection length is 0 (e.g. when typing or setting the caret). To get any selection change a post selection changed listener needs to be used.
Comment 10 Remy Suen CLA 2011-05-09 10:19:08 EDT
(In reply to comment #8)
> The first call to            
> window.getContext().set(ISources.SHOW_IN_SELECTION, context.getSelection()) is
> setting the wrong method selection, but the second call sets it to the correct
> one. I'm not too sure why this is...

Haven't checked this yet but for the tree case, it seems like the activation happens before the selection event so the first attempt to get a selection gets the original selection and then the second go gets the item that was clicked on.
Comment 11 Paul Webster CLA 2011-05-09 12:54:47 EDT
(In reply to comment #8)
> Created attachment 194086 [details]
> Fixes ShowIn issue

I've released this fix while we look at the first selection event.

PW
Comment 12 Paul Webster CLA 2011-05-13 14:41:17 EDT
Show in now reveals the correct element.  I've created bug 345768 to investigate the first call with the old value.

PW
Comment 13 Dani Megert CLA 2011-05-16 06:48:23 EDT
Verified in 4.1 build: I20110515-0800.
Comment 14 Harendra CLA 2011-05-16 22:55:08 EDT
Working in I20110516-1455