Bug 498320 - RCP: Unable to fully delete ("remove") Menus
Summary: RCP: Unable to fully delete ("remove") Menus
Status: CLOSED DUPLICATE of bug 374568
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.6   Edit
Hardware: All All
: P3 normal with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Kalyan Prasad Tatavarthi CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-22 00:40 EDT by DaveLaw CLA
Modified: 2019-12-12 15:07 EST (History)
7 users (show)

See Also:


Attachments
Thread Dump shows mMenuElement.setVisible(false); waiting (1.95 KB, text/plain)
2017-06-21 06:39 EDT, DaveLaw CLA
no flags Details
InjectionException StackTrace (4.98 KB, text/plain)
2017-06-21 13:57 EDT, DaveLaw CLA
no flags Details
PopupMenu addDelete test (75.57 KB, application/x-zip-compressed)
2018-04-23 04:23 EDT, Kalyan Prasad Tatavarthi CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description DaveLaw CLA 2016-07-22 00:40:37 EDT
After deleting some old Menus & adding some new Menus, the old deleted Menus remain as shadows or ghosts.

Selecting one of the old Menus leads to an Exception:
InjectionException: Unable to process "DirectContributionItem.contribFactory"

The following (simplified) code illustrates this...
	public static void rebuildMenus(final MMenu root) {

		final List<MMenuElement> childMenus = root.getChildren();

		childMenus.clear();

		final MDynamicMenuContribution contrib = MMenuFactory.INSTANCE.createDynamicMenuContribution();
		/**/                           contrib.setContributionURI("bundleclass://...");

		final MMenu newMenu = MMenuFactory.INSTANCE.createMenu();
		/**/        newMenu.setLabel  ("Label");
		/**/        newMenu.setVisible(true);
		/**/        newMenu.getChildren().add(contrib);

		childMenus.add(newMenu);
	}

See also Eclipse RCP Forum Posting:
https://www.eclipse.org/forums/index.php/t/1079242/
Comment 1 DaveLaw CLA 2017-06-21 06:39:24 EDT
Created attachment 268996 [details]
Thread Dump shows mMenuElement.setVisible(false); waiting

As almost a year has passed by with absolutely no reaction, here is some more Info.
>
Firstly: I really don't see why Eclipse RCP has no functioning mechanism to remove Menu Items.
Incredible!
>
As a workround we just make them invisible with mMenuElement.setVisible(false);
That is a very bad workaround.
Anyway, I noticed in a Thread Dump yesterday that sometimes the Workaround waits...
...and waits, and waits without end.
>
Please see attached Thread Dump.
Comment 2 Andrey Loskutov CLA 2017-06-21 08:58:26 EDT
(In reply to DaveLaw Missing name from comment #1)
> Created attachment 268996 [details]
> Thread Dump shows mMenuElement.setVisible(false); waiting
> 
> As almost a year has passed by with absolutely no reaction

I guess this is because: 1) wrong product assignment and 2) not clear bug description. I honestly can only guess what is the original issue here (e4 menus can't be hiddedn once added?).

Can you please provide a better description (steps to reproduce/observed/expected) and simple example project, where one can see the problem.
Comment 3 DaveLaw CLA 2017-06-21 13:55:43 EDT
Not sure what the right product might be: I've change it to e4/UI.
Actually the description is 100% spot on:
there is no way of deleting Menus.
You add them with something like:
MMenu.getChildren().add(MMenuFactory.INSTANCE.createMenu());
(pseudocode: see above for exact code)
You might expect removal would be:
MMenu.getChildren().clear()
...but it doesn't work.
After clear() the Menus are still there but cause an InjectionException.
(see attached StackTrace)
AS A WORKAROUND...
...we are setting the Menus invisible.
But, this consumes resources & as I noticed today, the...
MMenu.getChildren().setvisible(false)
...Method is resulting in endless waits.
(see previously attached Thread Dump)
Comment 4 DaveLaw CLA 2017-06-21 13:57:10 EDT
Created attachment 269004 [details]
InjectionException StackTrace
Comment 5 DaveLaw CLA 2017-06-25 06:16:03 EDT
It looks like the Bug is related to Dynamic Menu Contributions.
It is sporadic: sometimes it works.
Bug occurs on all of the following:
a) DynamicMenuContributionImpl.setVisible(false);
b) EcoreUtil.remove(DynamicMenuContributionImpl);
c) MElementContainer<MMenuElement>.getChildren().remove(DynamicMenuContributionImpl);
a), b) & c) all result in an indefinite wait, which is my definition of "blocker", so setting importance to "blocker".
Hope this Bug does not get ignored for another year.
Comment 6 DaveLaw CLA 2017-06-26 05:53:00 EDT
Supplement: its NOT confined to Dynamic Menus.
Happens with all Menus.
Comment 7 DaveLaw CLA 2017-07-26 06:48:20 EDT
Still happening with Neon.
Comment 8 Kalyan Prasad Tatavarthi CLA 2017-07-26 08:01:17 EDT
Can you please provide a sample project where we can reproduce this problem?
Comment 9 DaveLaw CLA 2017-07-27 04:26:25 EDT
I'm afraid I can't, its a very large and complex Project with many subprojects.
-> I think the first course of action would be to check the Stacktrace & figure out what's going on...
-> but I would also like an answer to the question:
"what is the correct way to delete menus"
(childMenus.clear(); has no effect)
Comment 10 Shashwat Anand CLA 2017-07-30 04:10:16 EDT
private void clearMenuItems(final List<MMenuElement> menuElements) {
	for (MMenuElement menuElement : menuElements) {
		// For some reason removing the element from it's parent doesn't
		// hide the element, so make it invisible
		// Important - change the visibility before removing from the toolbar
		menuElement.setToBeRendered(false);
		menuElement.setVisible(false);
	}
	menuElements.clear();
}

Try this work around
Comment 11 Eclipse Genie CLA 2018-04-17 04:04:07 EDT
New Gerrit change created: https://git.eclipse.org/r/121227
Comment 12 Lakshmi P Shanmugam CLA 2018-04-23 02:44:18 EDT
Kalyan,
Can you please provide a test-case or test-project to verify the fix?
Comment 13 Kalyan Prasad Tatavarthi CLA 2018-04-23 04:23:05 EDT
Created attachment 273728 [details]
PopupMenu addDelete test

Import the attached project,
Run it as a Product.

Selecting the Main menu item "Add Menu" adds a menu item "Label" to the popup menu.
Selecting the popup menu item "Delete Menu" deletes the added "Label" menu item from the popup menu.
Comment 14 Lakshmi P Shanmugam CLA 2018-04-24 13:54:26 EDT
Verified that the patch fixes the problem in the test project.
Please see gerrit for comments.
Comment 16 Andrey Loskutov CLA 2018-05-06 06:04:22 EDT
This introduces a blocker regression for EGit: History menu loses almost every entries, so that operating the Git history is not possible anymore (switch head to commit, create branch etc), and for me this meant I have to switch to the older SDK build to be able to bisect the problem with this commit.

I see the change is not obvious, so I would propose to revert commit 951b5ae0f9aa34876c15974e7b71b66c57bd6abe immediately because every Git user will be unable to work with the current SDK state.
Comment 17 Eclipse Genie CLA 2018-05-06 06:06:24 EDT
New Gerrit change created: https://git.eclipse.org/r/122225
Comment 19 DaveLaw CLA 2018-05-07 01:28:09 EDT
(In reply to Andrey Loskutov from comment #16)
> This introduces a blocker regression for EGit: History menu loses almost
> every entries, so that operating the Git history is not possible anymore
> (switch head to commit, create branch etc), and for me this meant I have to
> switch to the older SDK build to be able to bisect the problem with this
> commit.
> 
> I see the change is not obvious, so I would propose to revert commit
> 951b5ae0f9aa34876c15974e7b71b66c57bd6abe immediately because every Git user
> will be unable to work with the current SDK state.

Backing out this change is not the solution.

Removing Menus is basic & necessary logic.

If EGit has a problem with this, then EGit needs to be corrected.
Please open a corresponding change to EGit.

What does "I see the change is not obvious" mean?
Comment 20 Andrey Loskutov CLA 2018-05-07 02:44:01 EDT
(In reply to DaveLaw Missing name from comment #19)
> (In reply to Andrey Loskutov from comment #16)
> > This introduces a blocker regression for EGit: History menu loses almost
> > every entries, so that operating the Git history is not possible anymore
> > (switch head to commit, create branch etc), and for me this meant I have to
> > switch to the older SDK build to be able to bisect the problem with this
> > commit.
> > 
> > I see the change is not obvious, so I would propose to revert commit
> > 951b5ae0f9aa34876c15974e7b71b66c57bd6abe immediately because every Git user
> > will be unable to work with the current SDK state.
> 
> Backing out this change is not the solution.

Breaking running software neither. This week we have 4.8 M7 build and keeping the patch in the code would mean, that 4.8 M7 will be unusable for all Git users.

> Removing Menus is basic & necessary logic.

Sure. But: looks like the bug is pretty old, so we somehow survived without the fix.

> If EGit has a problem with this, then EGit needs to be corrected.
> Please open a corresponding change to EGit.

I'm not the one who needs the patch (yet), I'm one who is affected by the regression. Feel free to debug the problem with the patch and either fix the patch or create appropriate bugs to all affected plugins (not sure that EGit is the only affected plugin).

> What does "I see the change is not obvious" mean?

There was no explanation at all *what* and *how* the patch is supposed to fix, neither here nor on the commit message. "Try this work around" in comment 10 is not enough to understand the patch, so I've failed to get an idea about the proposed change and so it is for me "not obvious".

Please try understand, that *all* platform developers and most of users outside are using EGit plugin. Fixing an old issue by introducing breaking EGit regression means to hinder the work of all those people. This is not acceptable.

Here are steps to continue with this bug:

1. Debug the problem with EGit menus.
2. Understand, where the problem is - is this the patch, is this EGit, is there another bug in platform uncovered by the patch.
3. Document findings here. 
4. Fix the problem (wherever it is).
5. Provide updated patch explaining what id does and why, in the commit message or on this bug. 
6. Validate that basic plugins are still working.
7. Merge the patch.
Comment 21 Dani Megert CLA 2018-09-20 06:56:05 EDT
Kalyan, please fix for 4.10 M1.
Comment 22 Kalyan Prasad Tatavarthi CLA 2018-10-26 05:43:11 EDT

*** This bug has been marked as a duplicate of bug 461655 ***
Comment 23 Kalyan Prasad Tatavarthi CLA 2018-11-22 01:23:56 EST
Reopening this bug and targeting it for 4.11.
Comment 24 Rolf Theunissen CLA 2019-04-15 09:28:43 EDT
The regression might have been caused by Bug 543827. As a result of that bug, the model is not up-to-date for Opaque menu items. That is, the opaque items are not added to the model.

Though not sure which solution will be better, the patch included in this bug or the patch for bug 461655
Comment 25 Rolf Theunissen CLA 2019-12-12 15:07:33 EST

*** This bug has been marked as a duplicate of bug 374568 ***