Bug 414888 - [WorkbenchParts] Context menu retained cross editors
Summary: [WorkbenchParts] Context menu retained cross editors
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: 4.5 M7   Edit
Assignee: Snjezana Peco CLA
QA Contact: Brian de Alwis CLA
URL:
Whiteboard:
Keywords: greatfix
Depends on:
Blocks: 397478
  Show dependency tree
 
Reported: 2013-08-12 11:49 EDT by Nan Li CLA
Modified: 2015-04-28 12:52 EDT (History)
6 users (show)

See Also:


Attachments
Stack Trace (4.55 KB, text/plain)
2013-08-13 09:43 EDT, Nan Li CLA
no flags Details
.log (4.67 KB, text/plain)
2013-08-13 09:54 EDT, Nan Li CLA
no flags Details
Step1: Right click in "Resource" perspective. (19.66 KB, image/png)
2013-09-10 04:11 EDT, Soenke Broihan CLA
no flags Details
Step2: Right click in "Tasks" view (18.14 KB, image/png)
2013-09-10 04:12 EDT, Soenke Broihan CLA
no flags Details
Normal context menu (12.02 KB, image/png)
2013-09-10 04:12 EDT, Soenke Broihan CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nan Li CLA 2013-08-12 11:49:20 EDT
First a little bit background info, in Dali we have a view called the JPA Structure View. This view is much like an Outline view in that it has a tree of objects (PersistentTypes and PersistentAttributes) that correspond to the currently edited file (either an XML file or a Java file). We keep the tree's selection in sync with the position of the cursor in the active editor. 

Here is the problem:

If I first right-click the root node of an XML file in the structure view, and then switch to a Java file and *directly* right-click the root node in the structure view without first left-clicking it, the context menu for the root node will be the one for the XML file. (And vice-versa.) Selecting the context menu will lead to class cast exception at this point. 

I have investigated the code by setting a breakpoint in WorkbenchSourceProvider.selectionChanged(...). It looks like the new selection is the right element and our plugin.xml looks fine so it could be that the Eclipse platform is using the wrong selection when evaluating our 'visibleWhen' XML specification.

Please take bug 375741 for the reference to our plugin.xml entries, an example JPA project and more related info.
Comment 1 Dani Megert CLA 2013-08-13 09:34:50 EDT
(In reply to comment #0)
> First a little bit background info, in Dali we have a view called the JPA
> Structure View. This view is much like an Outline view in that it has a tree
> of objects (PersistentTypes and PersistentAttributes) that correspond to the
> currently edited file (either an XML file or a Java file). We keep the
> tree's selection in sync with the position of the cursor in the active
> editor. 
> 
> Here is the problem:
> 
> If I first right-click the root node of an XML file in the structure view,
> and then switch to a Java file and *directly* right-click the root node in
> the structure view without first left-clicking it, the context menu for the
> root node will be the one for the XML file. (And vice-versa.) Selecting the
> context menu will lead to class cast exception at this point. 

Please attach the .log with the CCE.
Comment 2 Nan Li CLA 2013-08-13 09:43:48 EDT
Created attachment 234353 [details]
Stack Trace

here it is
Comment 3 Nan Li CLA 2013-08-13 09:54:55 EDT
Created attachment 234354 [details]
.log

here is the .log
Comment 4 Brian de Alwis CLA 2013-08-27 17:19:30 EDT
Your handler's @Execute method is configured to be injected by something that's not a matching class.  Unfortunately it's not clear what handler class it is.

Put a breakpoint on InjectionException and you'll see what instance is being injected, and the problematic field.

!STACK 0
org.eclipse.e4.core.di.InjectionException: java.lang.ClassCastException: org.eclipse.jpt.jpa.core.internal.jpa2.context.java.GenericJavaPersistentType2_0 cannot be cast to org.eclipse.jpt.jpa.core.context.orm.EntityMappings
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:243)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:224)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
	at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:167)
	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:499)
Comment 5 Soenke Broihan CLA 2013-09-10 04:11:23 EDT
Created attachment 235333 [details]
Step1: Right click in "Resource" perspective.
Comment 6 Soenke Broihan CLA 2013-09-10 04:12:03 EDT
Created attachment 235334 [details]
Step2: Right click in "Tasks" view
Comment 7 Soenke Broihan CLA 2013-09-10 04:12:31 EDT
Created attachment 235335 [details]
Normal context menu
Comment 8 Soenke Broihan CLA 2013-09-10 04:14:46 EDT
I recognized the same behavior lately (in Kepler 4.3). However this is not related to custom plugins only.

When I right click on the "META-INF" folder of a plugin project in the "Resource" perspective and then do a right click in the "Tasks" view, the sub menu "Plug-in Tools" gets added to the context menu of the "Tasks" view.

The context menu changes depending on what was previously selected. The attachments.
Comment 9 Paul Webster CLA 2013-09-12 17:11:37 EDT
It's possible we're having a race condition with the new view activation and creation of the popup menu.

PW
Comment 10 Eclipse Genie CLA 2015-03-20 11:26:20 EDT
New Gerrit change created: https://git.eclipse.org/r/44257
Comment 11 Snjezana Peco CLA 2015-03-20 11:28:43 EDT
The issue happens because the CompatibilityPart class doesn't initialize a selection properly. It can be reproduced in the Tasks, Problems, Bookmarks, Error Log ... view. If you select an entry in a view, the issue will disappear.

 https://git.eclipse.org/r/#/c/44257 fixes the issue.
Comment 13 Brian de Alwis CLA 2015-03-27 12:19:37 EDT
Thanks Snjezana.  I'm unable to reproduce the issue above but the patch looks correct.
Comment 14 Brian de Alwis CLA 2015-03-27 12:28:21 EDT
(In reply to Brian de Alwis from comment #13)
> Thanks Snjezana.  I'm unable to reproduce the issue above but the patch
> looks correct.

Ah, reproduced it on a subsequent try, and patch fixes the issue.
Comment 15 Brian de Alwis CLA 2015-04-28 12:52:54 EDT
Verified in I20150428-0800