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

Bug 100156

Summary: [IDE] RenameResourceAction should use IAdaptable for IResource lookuop
Product: [Eclipse Project] Platform Reporter: Dmitry Stadnik <dimzzy>
Component: UIAssignee: Tod Creasey <Tod_Creasey>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P2 Keywords: helpwanted
Version: 3.1   
Target Milestone: 3.2   
Hardware: PC   
OS: All   
Whiteboard:

Description Dmitry Stadnik CLA 2005-06-15 08:37:40 EDT
Consider the following setup: there is a tree viewer that contains
TreeElementWrapper instances. TreeElementWrapper class is an IAdaptable and may
sometimes adapt to IResource instance.

   When RenameResourceAction receives selectionChanged() it enables itself
(since wrapper adapts to resource) but in runWithInlineEditor() method it
queries raw selection instead of adapted resources list - thus CCE.

java.lang.ClassCastException: com.xcom.TreeElementWrapper
        at
org.eclipse.ui.actions.RenameResourceAction.runWithInlineEditor(RenameResourceAction.java:462)
        at
org.eclipse.ui.actions.RenameResourceAction.run(RenameResourceAction.java:454)
        at
org.eclipse.ui.actions.BaseSelectionListenerAction.runWithEvent(BaseSelectionListenerAction.java:167)
        at com.xcom.CompositeAction.runWithEvent(CompositeAction.java:26)
        at org.eclipse.ui.commands.ActionHandler.execute(ActionHandler.java:182)
        at
org.eclipse.ui.internal.handlers.LegacyHandlerWrapper.execute(LegacyHandlerWrapper.java:108)
        at org.eclipse.core.commands.Command.execute(Command.java:311)
        at
org.eclipse.core.commands.ParameterizedCommand.execute(ParameterizedCommand.java:396)
        at
org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:452)
        at
org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:722)
        at
org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:766)
        at
org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:543)
        at
org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:486)
        at
org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:110)
Comment 1 Michael Van Meekeren CLA 2005-06-15 13:27:28 EDT
Tod can you investigate?
Comment 2 Tod Creasey CLA 2005-06-15 14:07:09 EDT
Correct - (IResource) getStructuredSelection().getFirstElement() will throw a
CastCastException because TreeElementWrapper is not an IResource.

All of the code in RenameResourceAction assumes that it is an IResource being
used. This action should be not used for viewers that are not showing resources.

We should be more explicit about this in the javadoc for this type. Renaming to
reflect this.
Comment 3 Dmitry Stadnik CLA 2005-06-16 03:26:20 EDT
I think that you should not take it that radically - this is a minor
inconsistency problem; this action works with resources or (!) objects adaptable
to resources, so every time you need selected resources you have to call
getSelectedResources() method and direct access to the structured selection here
is an inconsitency that have led to the problem; just call
getSelectedResources() in the reported line.
Comment 4 Tod Creasey CLA 2005-06-16 08:48:25 EDT
You so your point is more that we should use getAdapter(IResource) rather than
casting? That is a reasonable idea.

Does com.xcom.TreeElementWrapper adapt to IResource?
Comment 5 Dmitry Stadnik CLA 2005-06-16 08:53:42 EDT
Sure! That's how that action got enabled.
Comment 6 Tod Creasey CLA 2005-06-16 09:00:25 EDT
Renaming an upping proirity. Thanks for the clarification. If you have a
suggested patch (and a test case if you have one) I would be happy to review it.
Comment 7 Dmitry Stadnik CLA 2005-06-21 06:31:23 EDT
Just call getSelectedResources() at the line 462; run() actually does this!
Can you fix it in release?
Comment 8 Tod Creasey CLA 2005-06-21 06:43:22 EDT
It's too close to the 3.1 release now for us to do this (3 days away) but we
could consider it for 3.1.1.

Upping priority
Comment 9 Tod Creasey CLA 2005-06-30 13:50:04 EDT
Fixed for build >20050630.
Comment 10 Tod Creasey CLA 2005-08-09 14:33:17 EDT
Verified in 20050808