Bug 552361 - PopupMenuExtender does not handle multiple MenuManager instances correctly
Summary: PopupMenuExtender does not handle multiple MenuManager instances correctly
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.13   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.14 M3   Edit
Assignee: Sebastian Ratz CLA
QA Contact:
URL:
Whiteboard:
Keywords: regression
: 550986 553108 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-10-23 12:43 EDT by Sebastian Ratz CLA
Modified: 2019-12-06 07:42 EST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Ratz CLA 2019-10-23 12:43:55 EDT
Bug 549818 caused bug 396796 to re-appear.

A similar problem with MultiPageEditorPart was addressed in bug 550986, but that is not sufficient in general.

Example:
- Try to contribute to a context menu entry to org.eclipse.debug.ui.DebugView, e.g.:

   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            allPopups="true"
            locationURI="popup:org.eclipse.debug.ui.DebugView">
         <command
               commandId="some.custom.command"
               label="Foo"
               style="push">
         </command>
      </menuContribution>
   </extension>

- Right click in the Debug view and notice that the command is not there
- In the debug view, go to the view menu -> Layout -> Breadcrumb
- Right click now and notice that the custom command shows up now.


Reason:
- The debug view creates *two* MenuManager instances for the *same* menu ID org.eclipse.debug.ui.DebugView, one in
  org.eclipse.debug.ui.AbstractDebugView.createContextMenu(Control)
  and once in
  org.eclipse.debug.internal.ui.views.launch.LaunchViewBreadcrumb.createMenuManager()
- For MenuManagers a PopupMenuExtender is created
- Since the change in 549818, the MPopupMenu menu model is *re-used* for the 2nd instance.
- This sounds reasonable since the models are supposed to be identical.
- However, later in org.eclipse.ui.internal.PopupMenuExtender.createModelFor(String),
  org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer.linkModelToManager(MMenu, MenuManager)
  is called. And that one builds and expects a bi-directional 1:1 relationship between MMenu and MenuManager.
- Result: When the breadcrumb MenuManager is created and the *same* MMenu is re-used, that 1:1 relationship is broken, we have now
  2 MenuManager instances but only 1 MMenu:
  mmenu1 -> menumanager2
  menumanager1 -> mmenu1
  menumanager2 -> mmenu1
- Now, when the context menu is actually updated, org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer.getManager(MMenu) comes into play, returning the 2nd MenuManager for the breadcrumb, and only that once receives the custom command contribution.
Comment 1 Sebastian Ratz CLA 2019-10-28 14:11:48 EDT
I propose to revert the change to PopupMenuExtender ( https://git.eclipse.org/r/#/c/147881/ ):

Being unable to contribute to certain menus is kind of a blocker.

The persistence of duplicate menu entries described in bug 549818 should actually never happen, since the menu models created by PopupMenuExtender are never persisted anyways from what I can tell. (The duplicate menu entries mentioned by 549818 were created by code).

Any objections?
Comment 2 Eclipse Genie CLA 2019-10-28 14:52:14 EDT
New Gerrit change created: https://git.eclipse.org/r/151712
Comment 3 Andrey Loskutov CLA 2019-10-28 15:59:34 EDT
(In reply to Sebastian Ratz from comment #1)
> I propose to revert the change to PopupMenuExtender (
> https://git.eclipse.org/r/#/c/147881/ ):
> 
> Being unable to contribute to certain menus is kind of a blocker.
> 
> The persistence of duplicate menu entries described in bug 549818 should
> actually never happen, since the menu models created by PopupMenuExtender
> are never persisted anyways from what I can tell. (The duplicate menu
> entries mentioned by 549818 were created by code).
> 
> Any objections?

+1. Bug 549818 must be reopened once the patch is reverted.
Comment 4 Rolf Theunissen CLA 2019-10-29 04:03:51 EDT
(In reply to Sebastian Ratz from comment #1)
> I propose to revert the change to PopupMenuExtender (
> https://git.eclipse.org/r/#/c/147881/ ):
> 
> Being unable to contribute to certain menus is kind of a blocker.
> 
> The persistence of duplicate menu entries described in bug 549818 should
> actually never happen, since the menu models created by PopupMenuExtender
> are never persisted anyways from what I can tell. (The duplicate menu
> entries mentioned by 549818 were created by code).
> 
> Any objections?

No objection to the revert, though the original code is functionally incorrect (it checks for conditions that never can be true).
W.r.t. the duplication and persistence, even when model entries are created in code they must be cleaned actively. That cleaning is not done, but adding a non-persist tag will do the trick for now. That workaround can be pushed for Bug 549818.

The issue with the one-to-one relation between M(Popup)Menu and MenuManager must be investigated further, my suspicion is that EMenuService suffers a similar issue.
Comment 5 Rolf Theunissen CLA 2019-10-29 04:15:57 EDT
The persistence flag is already set, by the fixes for Bug 509371, that fixes Bug 549818 too.
Comment 7 Andrey Loskutov CLA 2019-10-30 06:28:05 EDT
Verified that example works again with build I20191030-0010.
Comment 8 Andrey Loskutov CLA 2019-10-30 06:29:00 EDT
(In reply to Andrey Loskutov from comment #3)
> Bug 549818 must be reopened once the patch is reverted.

Any comment on this?
Comment 9 Andrey Loskutov CLA 2019-10-31 08:08:16 EDT
*** Bug 550986 has been marked as a duplicate of this bug. ***
Comment 10 Andrey Loskutov CLA 2019-11-15 11:21:32 EST
*** Bug 553108 has been marked as a duplicate of this bug. ***