Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 435808

Summary: Double items in contextual menu
Product: [Modeling] Sirius Reporter: Julien Dupont <julien.dupont>
Component: DiagramAssignee: Maxime Porhel <maxime.porhel>
Status: CLOSED FIXED QA Contact: Pierre-Charles David <pierre-charles.david>
Severity: normal    
Priority: P3 CC: maxime.porhel, pierre-charles.david
Version: 1.0.0M7Keywords: triaged
Target Milestone: 1.0.0   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on: 435949    
Bug Blocks:    
Attachments:
Description Flags
Double Items in Contextual menu none

Description Julien Dupont CLA 2014-05-26 11:58:31 EDT
Created attachment 243498 [details]
Double Items in Contextual menu

Items named "Refresh", "Validate Diagram" and "Unsynchronized" are duplicate in the contextual menu.
See image attached.
Comment 1 Pierre-Charles David CLA 2014-05-27 05:51:13 EDT
I confirm the bug using Eclipse SDK 4.4RC2 and a pre-rc2 Sirius 1.0.0 (1.0.0.201405261437).

However I do not see the bug using Eclipse SDK 4.4M7 + Sirius M7, or with Eclipse SDK 4.4M7 + a pre-rc2 Sirius 1.0.0 (1.0.0.201405261437).
Comment 2 Maxime Porhel CLA 2014-05-27 10:00:09 EDT
Those items are provided by an extension to org.eclipse.ui.menus:

 <extension
      point="org.eclipse.ui.menus">
   ...
     <menuContribution
         locationURI="popup:org.eclipse.ui.popup.any?after=org.eclipse.sirius.diagram.ui.popup.otherActions">
      <command
            commandId="org.eclipse.sirius.diagram.ui.command.validateDiagram"
            label="Validate diagram"
            style="push">
         <visibleWhen
   ...
         </visibleWhen>
     </menuContribution>
   </extension>

This occurs for three menu contributions with command to org.eclipse.ui.menus.
Comment 3 Maxime Porhel CLA 2014-05-27 10:04:05 EDT
Step to reproduce: 
 . Install Sirius SDK in an Eclipse SDK Luna RC2
 . Open the Modeling perspective
 . Create a Modeling Project
 . Create an EMF Project
 . Activate the Design Viewpoint
 . Open or create a diagram
 . Right clic the diagram
Comment 4 Maxime Porhel CLA 2014-05-27 10:07:32 EDT
Each of our three menu contribution with command is added twice, here is the stack: 

Thread [main] (Suspended (breakpoint at line 328 in ContributionManager))	
	DiagramEditorContextMenuProvider(ContributionManager).insert(int, IContributionItem) line: 328	
	MenuManagerRenderer.addToManager(MenuManager, MMenuElement, IContributionItem) line: 624	
	MenuManagerRenderer.processHandledItem(MenuManager, MHandledMenuItem) line: 820	
	MenuManagerRenderer.modelProcessSwitch(MenuManager, MMenuElement) line: 673	
	MenuManagerRenderer.processContents(MElementContainer<MUIElement>) line: 606	
	PopupMenuExtender.addMenuContributions(IMenuManager) line: 423	
	PopupMenuExtender.menuAboutToShow(IMenuManager) line: 393	
	DiagramEditorContextMenuProvider(MenuManager).fireAboutToShow(IMenuManager) line: 352	
	DiagramEditorContextMenuProvider(MenuManager).handleAboutToShow() line: 492	
	MenuManager.access$1(MenuManager) line: 487	
	MenuManager$2.menuShown(MenuEvent) line: 519	
	TypedListener.handleEvent(Event) line: 255	
	EventTable.sendEvent(Event) line: 84	
	Display.sendEvent(EventTable, Event) line: 4353
Comment 5 Maxime Porhel CLA 2014-05-27 11:01:20 EDT
Each of the duplicated menus has two org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem. 

It looks like we have some duplicated org.eclipse.e4.ui.model.application.ui.menu.impl.HandledMenuItemImpl which cause the duplicated HandledContributionItem and resulting menus.
Comment 6 Maxime Porhel CLA 2014-05-27 11:35:51 EDT
As expected only one HandledMenuItemImpl is created for each contribution during startup: 
Thread [main] (Suspended (breakpoint at line 137 in HandledMenuItemImpl))	
	owns: RunnableLock  (id=63)	
	HandledMenuItemImpl.setCommand(MCommand) line: 137	
	MenuAdditionCacheEntry.createMenuCommandAddition(IConfigurationElement) line: 258	
	MenuAdditionCacheEntry.addMenuChildren(MElementContainer<MMenuElement>, IConfigurationElement, String) line: 212	
	MenuAdditionCacheEntry.mergeIntoModel(ArrayList<MMenuContribution>, ArrayList<MToolBarContribution>, ArrayList<MTrimContribution>) line: 167	
	MenuPersistence.readAdditions() line: 163	
	MenuPersistence.read() line: 111	
	WorkbenchMenuService.readRegistry() line: 573	
	Workbench$46.runWithException() line: 2386	
	Workbench$46(StartupThreading$StartupRunnable).run() line: 32	
	RunnableLock.run() line: 35
Comment 7 Maxime Porhel CLA 2014-05-27 11:51:24 EDT
In MenuManagerRenderer.generateContributions(), curList contains each MMenuContribution twice.

MenuManagerRenderer.generateContributions(MMenu, ArrayList<MMenuContribution>, boolean) line: 495	
MenuManagerRenderer.processContributions(MMenu, String, boolean, boolean) line: 460	
PopupMenuExtender.addMenuContributions(IMenuManager) line: 421	
PopupMenuExtender.menuAboutToShow(IMenuManager) line: 393	


It seems to comes from org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer.XXXgatherMenuContributions(MMenu, List<MMenuContribution>, String, ArrayList<MMenuContribution>, ExpressionContext, boolean)
Comment 8 Maxime Porhel CLA 2014-05-27 12:02:54 EDT
The issue comes from org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer.XXXgatherMenuContributions(MMenu, List<MMenuContribution>, String, ArrayList<MMenuContribution>, ExpressionContext, boolean) :

   if (!filtered && menuContribution.isToBeRendered() && popupAny) {
      // process POPUP_ANY first
      toContribute.add(menuContribution);
   } else if (filtered || (!popupTarget && !parentID.equals(id))
					|| !menuContribution.isToBeRendered()) {
     continue;
   }
   includedPopups.add(menuContribution);
 }
 toContribute.addAll(includedPopups);


The popupAny contributions (locationUri popup:org.eclipse.ui.popup.anybefore=additions for example) are added twice !

The if/else if block should be improved to avoid duplicated entries or a LinkedHAshSet should be used.
Comment 9 Maxime Porhel CLA 2014-05-28 03:13:54 EDT
Bug 435949 has been created to track the issue in Platform UI. 

I have submitted a patch set to Gerrit.
Comment 10 Maxime Porhel CLA 2014-05-28 09:08:03 EDT
The sumbitted patch has been merged (see Bug 435949). 

It will be available in Luna RC3 (should be available in staging from next Monday).
Comment 11 Maxime Porhel CLA 2014-06-02 04:47:30 EDT
Submitted patch have merged in Bug 435949.
Comment 12 Pierre-Charles David CLA 2014-06-02 04:59:12 EDT
Verified using Eclipse SDK 4.4RC3 (I20140528-2000) and a current Sirius build (between rc2 and rc3).
Comment 13 Pierre-Charles David CLA 2014-06-25 10:14:47 EDT
Available in Sirius 1.0.0.