Update MenuManagerHideProcessor to the latest platform code

This will fix bug 535586.

Bug 535586: [e4] dynamic menu: direct menu item or handler are not
executed
https://bugs.eclipse.org/bugs/show_bug.cgi?id=535586

Change-Id: Id1a4dfc03320c474ed8243ba79a195e134259f0e
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerHideProcessor.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerHideProcessor.java
index 3d48923..3c3c374 100644
--- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerHideProcessor.java
+++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerHideProcessor.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2014 IBM Corporation and others.
+ * Copyright (c) 2010, 2016 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
  *     IBM Corporation - initial API and implementation
  *     Marco Descher <marco@descher.at> - Bug 403081, 403083
  *     Bruce Skingle <Bruce.Skingle@immutify.com> - Bug 442570
+ *     Lars Vogel <Lars.Vogel@vogella.com> - Bug 472654
  *******************************************************************************/
 package org.eclipse.e4.ui.workbench.renderers.swt;
 
@@ -77,7 +78,7 @@
 	private void processDynamicElements(final MenuManager menuManager, Menu menu, final MMenu menuModel) {
 		// We need to make a copy of the dynamic items which need to be removed
 		// because the actual remove happens asynchronously.
-		final Map<MDynamicMenuContribution, ArrayList<MMenuElement>> toBeHidden = new HashMap<MDynamicMenuContribution, ArrayList<MMenuElement>>();
+		final Map<MDynamicMenuContribution, ArrayList<MMenuElement>> toBeHidden = new HashMap<>();
 
 		for (MMenuElement currentMenuElement : menuModel.getChildren()) {
 			if (currentMenuElement instanceof MDynamicMenuContribution) {
@@ -88,16 +89,6 @@
 						.get(MenuManagerShowProcessor.DYNAMIC_ELEMENT_STORAGE_KEY);
 
 				toBeHidden.put((MDynamicMenuContribution) currentMenuElement, mel);
-
-				// make existing entries for this dynamic contribution item
-				// invisible if there are any
-				if (mel != null && mel.size() > 0) {
-
-					for (MMenuElement item : mel) {
-						item.setVisible(false);
-					}
-				}
-				currentMenuElement.getTransientData().remove(MenuManagerShowProcessor.DYNAMIC_ELEMENT_STORAGE_KEY);
 			}
 		}
 
@@ -113,6 +104,7 @@
 						ArrayList<MMenuElement> mel = entry.getValue();
 
 						dynamicMenuContext.set(List.class, mel);
+						dynamicMenuContext.set(MDynamicMenuContribution.class, currentMenuElement);
 						IEclipseContext parentContext = modelService.getContainingContext(currentMenuElement);
 						ContextInjectionFactory.invoke(contribution, AboutToHide.class, parentContext,
 								dynamicMenuContext, null);
@@ -122,6 +114,14 @@
 						if (mel != null && mel.size() > 0) {
 							renderer.removeDynamicMenuContributions(menuManager, menuModel, mel);
 						}
+
+						// make existing entries for this dynamic contribution
+						// item invisible if there are any
+						if (mel != null && mel.size() > 0) {
+							for (MMenuElement item : mel) {
+								item.setVisible(false);
+							}
+						}
 					}
 				}
 			});