Bug 87208 - [GlobalActions] CCE in RetargetAction while switching between views and editors
Summary: [GlobalActions] CCE in RetargetAction while switching between views and editors
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.1 M6   Edit
Assignee: Nick Edgar CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks:
 
Reported: 2005-03-05 05:24 EST by Dmitry Stadnik CLA
Modified: 2005-03-23 12:25 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Stadnik CLA 2005-03-05 05:24:43 EST
java.lang.ClassCastException: org.eclipse.ui.actions.RetargetAction
	at org.eclipse.ui.actions.RetargetAction.propagateChange(RetargetAction.java:197)
	at org.eclipse.ui.actions.RetargetAction$1.propertyChange(RetargetAction.java:60)
	at org.eclipse.jface.action.Action.firePropertyChange(Action.java:597)
	at org.eclipse.jface.action.Action.firePropertyChange(Action.java:582)
	at org.eclipse.ui.actions.RetargetAction.setActionHandler(RetargetAction.java:265)
	at org.eclipse.ui.actions.RetargetAction.partActivated(RetargetAction.java:146)
	at org.eclipse.ui.internal.PartListenerList$1.run(PartListenerList.java:52)
	at
org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1015)
	at org.eclipse.core.runtime.Platform.run(Platform.java:757)
	at
org.eclipse.ui.internal.PartListenerList.firePartActivated(PartListenerList.java:50)
	at
org.eclipse.ui.internal.WWinPartService.firePartActivated(WWinPartService.java:209)
	at org.eclipse.ui.internal.WWinPartService.access$0(WWinPartService.java:206)
	at org.eclipse.ui.internal.WWinPartService$1.partActivated(WWinPartService.java:36)
	at org.eclipse.ui.internal.PartListenerList2$1.run(PartListenerList2.java:48)
	at
org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1015)
	at org.eclipse.core.runtime.Platform.run(Platform.java:757)
	at
org.eclipse.ui.internal.PartListenerList2.firePartActivated(PartListenerList2.java:46)
	at org.eclipse.ui.internal.WorkbenchPage.firePartActivated(WorkbenchPage.java:1501)
	at org.eclipse.ui.internal.WorkbenchPage.setActivePart(WorkbenchPage.java:2821)
	at org.eclipse.ui.internal.WorkbenchPage.requestActivation(WorkbenchPage.java:2479)
	at org.eclipse.ui.internal.PartPane.requestActivation(PartPane.java:314)
	at org.eclipse.ui.internal.PartPane.setFocus(PartPane.java:356)
	at
org.eclipse.ui.internal.PartStack.presentationSelectionChanged(PartStack.java:728)
	at org.eclipse.ui.internal.PartStack.access$0(PartStack.java:711)
	at org.eclipse.ui.internal.PartStack$1.selectPart(PartStack.java:93)
	at
org.eclipse.ui.internal.presentations.newapi.TabbedStackPresentation$1.handleEvent(TabbedStackPresentation.java:116)
	at
org.eclipse.ui.internal.presentations.newapi.AbstractTabFolder.fireEvent(AbstractTabFolder.java:263)
	at
org.eclipse.ui.internal.presentations.newapi.AbstractTabFolder.fireEvent(AbstractTabFolder.java:272)
	at
org.eclipse.ui.internal.presentations.defaultpresentation.DefaultTabFolder.access$1(DefaultTabFolder.java:1)
	at
org.eclipse.ui.internal.presentations.defaultpresentation.DefaultTabFolder$2.handleEvent(DefaultTabFolder.java:81)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:842)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:866)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:851)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:659)
	at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:3141)
	at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1925)
	at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:287)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:842)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2908)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2541)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1612)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1578)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:293)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:144)
	at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:102)
	at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:228)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:333)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:150)
	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:585)
	at org.eclipse.core.launcher.Main.invokeFramework(Main.java:268)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:260)
	at org.eclipse.core.launcher.Main.run(Main.java:887)
	at org.eclipse.core.launcher.Main.main(Main.java:871)
Comment 1 Nick Edgar CLA 2005-03-07 13:55:59 EST
Seems to be a result of the 3.0.1 fix for bug 70503.

The same propertyChangeListener is being hooked on both the handling action and
the IActionBars of the active part.  RetargetAction expects P_ACTION_HANDLERS
notifications to come only from the IActionBars, and for this to be the source
of the event.
Comment 2 Douglas Pollock CLA 2005-03-07 14:10:02 EST
I disagree.  The line at which the exception occurs seems to have been in since
revision 1.1 of RetargetAction.  I believe the line he's referring to is:

    setActionHandler(((IActionBars)
event.getSource()).getGlobalActionHandler(getId()));

If I've got the line wrong, please let me know which line it is....
Comment 3 Nick Edgar CLA 2005-03-07 14:37:11 EST
Dmitri, are you instantiating the RetargetAction (either directly or via
ActionFactory)?  It looks like you're setting a RetargetAction as the handler of
another RetargetAction.

Comment 4 Nick Edgar CLA 2005-03-07 15:37:43 EST
Although the CCE occurs at line 197, the property change event is being
triggered by the fix for bug 70503 at line 265.

Rather than reuse SubActionBars.P_ACTION_HANDLERS to notify the ActionHandler of
a change to the RetargetAction's handler, it would be better to define a new
property P_HANDLER in RetargetAction.

Dmitri, could you please describe the setup that lead to this (that is, how
you're creating actions and setting handlers)?
We're trying to assess the severity of this bug, and whether a fix needs to go
into 3.0.2.
Comment 5 Dmitry Stadnik CLA 2005-03-10 05:46:02 EST
I have to handle rename action in my custom view part. The requirements are to
enable workbench menu (File->Rename), to provide the same item in context menu
(with F2 shortcut visible!) and to handle keyboard shortcut with inplace editor. 

I can't use org.eclipse.ui.popupMenus extension point since the same objects
appear in GEF editor and require another action handler. When I've provided a
couple of object contributions there was a conflict that was resolved by
workbench so keyboard shortcut was disabled (((.

The solution was to set my custom action as global action handler for the view's
action bars and to register it in keybinding service:

actionBars.setGlobalActionHandler(actionId, newAction); // 'rename'
getViewSite().getKeyBindingService().registerAction(newAction);

To populate context menu I create RetargetAction instance
(ActionFactory.RENAME.create(window)) and add it to the context menu
(menu.appendToGroup(StandardMenuGroups.GROUP_MANIPULATION, action)).

The requirements are met but sometimes(!) this exception is thrown on context
menu invocation.
Comment 6 Nick Edgar CLA 2005-03-23 11:57:41 EST
Dmitri, please try adding your handling action (newAction) to the context menu,
instead of a RetargetAction.  To get the key binding to show up, ensure that
newAction's actionDefinitionId is "org.eclipse.ui.edit.rename".

There is still a bug here, but this is the recommended way of both hooking an
action as a global action handler and putting it in the context menu.
Comment 7 Nick Edgar CLA 2005-03-23 11:58:15 EST
> There is still a bug here.

That was probably confusing.  To clarify, if you do as I suggest, you should not
hit this bug.
Comment 8 Nick Edgar CLA 2005-03-23 12:25:13 EST
Actually, since this requires new API, it needs to be done for M6.

I've added a RetargetAction.HANDLER property, which is now used in ActionHandler
instead of SubActionBars.P_ACTION_HANDLERS.

I've also added an instanceof check in RetargetAction.propagateChange.

Patch reviewed by Doug.  The tests pass.

Will write a regression test for this case.  See bug 88889.