This feature is implemented as Kepler M4, for detailed usage information see my blog.
I want to implement a fully dynamic menu tab in the handler menu located on the view toolbar. In Eclipse 3, you could add โdynamicโ as the contribution of org.eclipse.ui.menus to the menu!
I already learned about www.vogella.com/blog/2010/10/26/processors-e4-model explaining how to dynamically contribute to a menu using processor model extensions, but I'm talking about a fully dynamic menu implementation that changes when every call resp. submenu. As already mentioned, this is not a problem for implementation in Eclipse 3.x through the contribution of the dynamic menu, and the set isDynamic () is true.
I have already tried several approaches:
Open, Proven Solutions
- Inserting a ToolControl to use the SWT approach -> rather complicated, but may work
I had been banging my head for several seconds, but I donโt seem to understand the correct implementation of this problem in E4.
- This question was also asked in the Eclipse Forum - dynamic menu tabs
----- UPDATE
I have tried a different approach so far:
I added HandledToolItem to the menu (see the following image)

and with the following code, I am trying to intervene in a way to create a menu where the code is called using resp. as it shown on the picture.
@CanExecute public boolean canExecute(@Optional MApplication application) { System.out.println("CanExecute Counter="+counter); // --- 1 --- // Find the required MMenu Entry in the Application Model if(application == null) return true; EModelService modelService = (EModelService) application.getContext().get(EModelService.class.getName()); MPart part = (MPart) modelService.find("at.medevit.emr.contacts.ui.contactselector", application); List<MToolBarElement> lmte = part.getToolbar().getChildren(); HandledToolItemImpl htil = null; for (MToolBarElement mToolBarElement : lmte) { if(mToolBarElement.getElementId().equals("at.medevit.emr.contacts.ui.contactselector.toolbar.handledtoolitem.filter")) htil = (HandledToolItemImpl) mToolBarElement; } if(htil != null) { MMenu elemMenu = htil.getMenu(); // --- 2 --- // Found it hopefully, let start the real work, simply add a new item MDirectMenuItem mdi = MMenuFactory.INSTANCE.createDirectMenuItem(); mdi.setLabel("Counter "+counter); counter++; // --- 3 --- elemMenu.getChildren().add(mdi); // ConcurrentModificationException }
As you can see, this code is requested after creating the menu to determine whether the command is executable or not. All the code from 1 to 2 is the search for the correct MMenu element to work. The code from 2 - 3 creates the MenuItem and increments the counter in the field.
BUT in 3 I encounter java.util.ConcurrentModificationException the first time I open the menu! I assume that at this point the menu iterates over the Memu.getChildren () element, and I am not allowed to include!
So, that all the fuzz around the entire e4 model is changing all the time;) (just kiddin 'I know this is a haaaad hack !!!)
The fact is that I really think that the ability to add fully dynamic parts of the menu is one of the best usability tools, and if it is impossible to implement in E4, as it was in E3, this is a very serious deterioration of features !!!
- UPDATE
Eclipse bug bug for this https://bugs.eclipse.org/bugs/show_bug.cgi?id=389063