Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 405471 - Incorrectly handling of MMenu element contributions in DynamicMenuContribution
Summary: Incorrectly handling of MMenu element contributions in DynamicMenuContribution
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.3   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: 4.3 M7   Edit
Assignee: Paul Webster CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-11 09:41 EDT by Christophe Bouhier CLA
Modified: 2020-03-06 06:30 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 Christophe Bouhier CLA 2013-04-11 09:41:17 EDT
Hello, 

When I use a MDynamicMenuContribution and I populate it with MMenu objects, these are not cleaned (In the renderer?). 

To reproduce: 

1. Add a Dynamic Menu Contribution to a Part.

2. Create a class with this implementation. 
@AboutToHide
	public void aboutToHide(List<MMenuElement> items) {

// Clearing items here, has no effect. 
		items.clear();
	}

	@AboutToShow
	public void aboutToShow(List<MMenuElement> items) {

		MMenu menu = MMenuFactory.INSTANCE.createMenu();
		menu.setLabel("Test");//$NON-NLS-1$
		menu.setElementId("test.menu.id");
		
		MDirectMenuItem createDirectMenuItem = MMenuFactory.INSTANCE.createDirectMenuItem();
		createDirectMenuItem.setElementId("test.id.whatever");
		createDirectMenuItem.setLabel("test");
		createDirectMenuItem.setContributorURI("platform://....");
		createDirectMenuItem.setContributionURI("bundleclass://...");
		createChildMenuManager.getChildren().add(createDirectMenuItem);
		
		items.add(createChildMenuManager);
}

will try to diagnose, if this is indeed recognized as a bug. 
Note, no response on the forum, hence the bug report.
Comment 1 Nobody - feel free to take it CLA 2013-04-11 09:45:16 EDT
Potentially related to bug 375393.
Comment 2 Marco Descher CLA 2013-04-12 05:30:30 EDT
As mentioned in the forum http://www.eclipse.org/forums/index.php/mv/msg/472828/1037345/#msg_1037345 , your usage scenario does not make sense to me.

I see this bug as invalid, please discuss in the forum.
Comment 3 Marco Descher CLA 2013-04-12 07:46:28 EDT
This bug is valid, please change the title of the bug to:

"Incorrectly handling of MMenu element contributions in DynamicMenuContribution "

Adding an MMenu element in a DynamicMenuContribution class leads to inconsistent behaviour. The respective contributions are not cleared as expected.
Comment 4 Christophe Bouhier CLA 2013-04-12 07:53:02 EDT
Thx Marco, 
Did you manage to reproduce? You want me to provide a patch?
Comment 5 Marco Descher CLA 2013-04-12 07:56:02 EDT
Yes, could reproduce! If you want you can certainly try a patch, I will try to bring one up too! :)
Comment 6 Marco Descher CLA 2013-04-12 08:39:05 EDT
I already got something that causes it. In MenuManagerRenderer#removeDynamicMenuContributions the contributions are incorrectly removed.

This is due to the fact that MMenu does not have an associated IContributionItem.

I could already provide a quick fix, by employing 

menuManager.removeAll();

instead of 

menuManager.remove(ici) per ContributionItem

@Paul A question:
- We do want to remove all items anyway before freshly populating the list. Wouldn't it be generally better to just call menuManager.removeAll() once instead of menuManager.remove(ici) n times? Like for performance etc.?
- Should structurs like nested DynamicMenuContributions be supported?

Remark: Will have to test for nested (>2) scenarios of MMenu contributions.
Comment 7 Paul Webster CLA 2013-04-12 08:45:35 EDT
You're right, for MMenus we need to use getManager(*) instead of getContribution(*).  The MenuManager returned from getManager(*) is its ICI.

PW
Comment 8 Marco Descher CLA 2013-04-12 10:02:23 EDT
Pushed a possible solution to https://git.eclipse.org/r/#/c/11856/

please review!

I checked nested menus, they do work now. The ici==null comparison is for performance reasons as I think it is faster than the instanceof, now is it?
Comment 9 Marco Descher CLA 2013-04-12 17:40:16 EDT
@Paul: I refactored the patch, unfortunatley I still do not seem to get the hang of gerrit, so sorry for the messed up patch, I hope it's okay though! The new dependencies came as I was not able to push the new patch without a pull ....
Comment 10 Marco Descher CLA 2013-04-13 06:55:33 EDT
I completely reworked the patch in https://git.eclipse.org/r/#/c/11880/ please consider reviewing this one.
Comment 12 Marco Descher CLA 2013-04-17 03:57:49 EDT
Christophe, thanks for pointing this bug out! :)
Comment 13 Christophe Bouhier CLA 2013-04-17 05:09:29 EDT
Thanks for solving it! Do I need to be on edge, with the latest commit to get this fix? When do you expect it to show up in a build?
Comment 14 Lars Vogel CLA 2013-04-17 05:21:34 EDT
@Christophe, official build should be available soon via http://download.eclipse.org/e4/downloads/.

AFAIK it is created daily, or you can use the vogella integration build which is triggered every 15 min if their is a new commit: p2 update site: http://download.vogella.com/kepler/e4tools
Comment 15 Lars Vogel CLA 2013-04-17 05:22:26 EDT
Ah, sorry this is for platform not the tools. Check out the nightly build from http://download.eclipse.org/eclipse/downloads/
Comment 16 Paul Webster CLA 2013-05-17 12:25:21 EDT
In 4.3.0.I20130516-2200
PW
Comment 17 Christoph Laeubrich CLA 2020-03-06 06:30:49 EST
I see the same problem with Eclipse 4.8 when using DirectMenuItems (the menu itself is created with model editor).
Was this fix special for MMenu types?