0

How do I add a dynamic toolbar item?

I can add a dynamic Menu item via the 'Add Child->Dynamic Menu Contribution' option in the Application.e4xmi file, and pointing to my own file which does:

@AboutToShow
public void aboutToShow(final List<MMenuElement> items) {
    final MDirectMenuItem dynamicItem = MMenuFactory.INSTANCE.createDirectMenuItem();
    ...
}

However, there is no 'Add Child->Dynamic Toolbar contribution' option in the Application.e4xmi file. If there was I assume I could do:

@AboutToShow
public void aboutToShow(final List<MToolBarElement> toolItems) {       
    final MDirectToolItem dynamicToolItem = MMenuFactory.INSTANCE.createDirectToolItem();
    ...
}

So does anyone know how I'm supposed to hook into my class from the Application.e4.xmi file to dynamically create toolbar items?

The reason that I'm doing this is to be able to dynamically set the icons and label text using values from a properties file. If there's an easier way to do this through the Application.e4xmi file, please let me know!

greg-449
  • 109,219
  • 232
  • 102
  • 145
user2992188
  • 283
  • 1
  • 5
  • 18
  • I don't think there is any special support for this so you would have to add items to the `MToolBar` children in your code. – greg-449 Nov 28 '14 at 14:25
  • D'oh, I figured there would be based on the text on the tutorial page at http://www.vogella.com/tutorials/EclipseRCP/article.html which says: "29.3. Dynamic menu and toolbar entries You can also create menu and toolbar entries at runtime with the DynamicMenuContribution model element." – user2992188 Nov 28 '14 at 19:20

0 Answers0