Project: Eclipse_Platform_UI
Bug 226746 [Commands] Handler updates UI using wrong selection after right-click in different view
Reported: 2008-04-11 14:56:36 | Status: verified fixed

Using the attached plugin project: - Create a new Java project and a new Java class. Open Java class in editor. - Check to make sure that "Test Command" is available in popup menu in Navigator view. - Select text in Java editor, immediately right click on any object in Navigator view I receive the below error in TestCommandHandler#updateUI(UIElement, Map) The problem is that I am expecting an IStructuredSelection (since the handler is only enabled for the Navigator view) but I am getting a TextSelection from the no-longer active Java editor. Note that I never receive an exception when executing the handler, only when updating it. The selection is *always* an IStructuredSelection when executing. Note also that the enablement of the handler does seem to always use the correct selection object. java.lang.ClassCastException: org.eclipse.jface.text.TextSelection cannot be cast to org.eclipse.jface.viewers.IStructuredSelection at test.plugin.TestCommandHandler.updateElement(TestCommandHandler.java:32) at org.eclipse.ui.internal.handlers.HandlerProxy.updateElement(HandlerProxy.java:422) at org.eclipse.ui.internal.commands.CommandService$1.run(CommandService.java:242) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37) at org.eclipse.ui.internal.commands.CommandService.refreshElements(CommandService.java:246) at org.eclipse.ui.internal.handlers.HandlerAuthority.updateCommand(HandlerAuthority.java:460) at org.eclipse.ui.internal.handlers.HandlerAuthority.processChangedCommands(HandlerAuthority.java:631) at org.eclipse.ui.internal.handlers.HandlerAuthority.access$1(HandlerAuthority.java:610) at org.eclipse.ui.internal.handlers.HandlerAuthority$1.propertyChange(HandlerAuthority.java:175) at org.eclipse.ui.internal.services.EvaluationAuthority$1.run(EvaluationAuthority.java:252) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37) at org.eclipse.ui.internal.services.EvaluationAuthority.fireServiceChange(EvaluationAuthority.java:246) at org.eclipse.ui.internal.services.EvaluationAuthority.endSourceChange(EvaluationAuthority.java:197) at org.eclipse.ui.internal.services.EvaluationAuthority.sourceChanged(EvaluationAuthority.java:135) at org.eclipse.ui.internal.services.ExpressionAuthority.sourceChanged(ExpressionAuthority.java:306) at org.eclipse.ui.internal.services.ExpressionAuthority.sourceChanged(ExpressionAuthority.java:285) at org.eclipse.ui.AbstractSourceProvider.fireSourceChanged(AbstractSourceProvider.java:99) at org.eclipse.ui.internal.services.ActivePartSourceProvider.checkActivePart(ActivePartSourceProvider.java:210) at org.eclipse.ui.internal.services.ActivePartSourceProvider$1.partDeactivated(ActivePartSourceProvider.java:99) at org.eclipse.ui.internal.PartListenerList$4.run(PartListenerList.java:117) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37) at org.eclipse.core.runtime.Platform.run(Platform.java:880) at org.eclipse.ui.internal.PartListenerList.fireEvent(PartListenerList.java:57) at org.eclipse.ui.internal.PartListenerList.firePartDeactivated(PartListenerList.java:115) at org.eclipse.ui.internal.PartService.firePartDeactivated(PartService.java:113) at org.eclipse.ui.internal.PartService.setActivePart(PartService.java:165) at org.eclipse.ui.internal.WWinPartService.updateActivePart(WWinPartService.java:124) at org.eclipse.ui.internal.WWinPartService.access$0(WWinPartService.java:115) at org.eclipse.ui.internal.WWinPartService$1.partDeactivated(WWinPartService.java:48) at org.eclipse.ui.internal.PartListenerList2$4.run(PartListenerList2.java:113) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37) at org.eclipse.core.runtime.Platform.run(Platform.java:880) at org.eclipse.ui.internal.PartListenerList2.fireEvent(PartListenerList2.java:53) at org.eclipse.ui.internal.PartListenerList2.firePartDeactivated(PartListenerList2.java:111) at org.eclipse.ui.internal.PartService.firePartDeactivated(PartService.java:116) at org.eclipse.ui.internal.PartService.setActivePart(PartService.java:165) at org.eclipse.ui.internal.WorkbenchPagePartList.fireActivePartChanged(WorkbenchPagePartList.java:56) at org.eclipse.ui.internal.PartList.setActivePart(PartList.java:126) at org.eclipse.ui.internal.WorkbenchPage.setActivePart(WorkbenchPage.java:3387) at org.eclipse.ui.internal.WorkbenchPage.requestActivation(WorkbenchPage.java:2930) at org.eclipse.ui.internal.PartPane.requestActivation(PartPane.java:266) at org.eclipse.ui.internal.PartPane.handleEvent(PartPane.java:230) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:83) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1002) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1026) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1007) at org.eclipse.swt.widgets.Shell.setActiveControl(Shell.java:1349) at org.eclipse.swt.widgets.Shell.WM_MOUSEACTIVATE(Shell.java:2174) at org.eclipse.swt.widgets.Control.windowProc(Control.java:3824) at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:334) at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1555) at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:1916) at org.eclipse.swt.widgets.Display.windowProc(Display.java:4486) at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method) at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2334) at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:77) at org.eclipse.swt.widgets.Control.windowProc(Control.java:3871) at org.eclipse.swt.widgets.Display.windowProc(Display.java:4486) at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method) at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2334) at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:77) at org.eclipse.swt.widgets.Control.windowProc(Control.java:3871) at org.eclipse.swt.widgets.Display.windowProc(Display.java:4486) at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method) at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2334) at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:77) at org.eclipse.swt.widgets.Control.windowProc(Control.java:3871) at org.eclipse.swt.widgets.Display.windowProc(Display.java:4486) at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method) at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2334) at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:77) at org.eclipse.swt.widgets.Control.windowProc(Control.java:3871) at org.eclipse.swt.widgets.Display.windowProc(Display.java:4486) at org.eclipse.swt.internal.win32.OS.CallWindowProcW(Native Method) at org.eclipse.swt.internal.win32.OS.CallWindowProc(OS.java:2253) at org.eclipse.swt.widgets.Tree.callWindowProc(Tree.java:1489) at org.eclipse.swt.widgets.Control.windowProc(Control.java:3871) at org.eclipse.swt.widgets.Tree.windowProc(Tree.java:5627) at org.eclipse.swt.widgets.Display.windowProc(Display.java:4486) at org.eclipse.swt.internal.win32.OS.PeekMessageW(Native Method) at org.eclipse.swt.internal.win32.OS.PeekMessage(OS.java:2848) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3367) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2375) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2339) at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2205) at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:478) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:473) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193) 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:362) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:175) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504) at org.eclipse.equinox.launcher.Main.run(Main.java:1236) at org.eclipse.equinox.launcher.Main.main(Main.java:1212)

Files changed in fix:
bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ShowInMenu.java bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/ActivePartSourceProvider.java bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/ActiveShellSourceProvider.java bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/CurrentSelectionSourceProvider.java bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/WorkbenchSourceProvider.java tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/CommandEnablementTest.java tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/services/EvaluationServiceTest.java