private void cleanUpContributionCache() {
    if (!actionContributionCache.isEmpty()) {
      PluginActionContributionItem[] items =
          actionContributionCache.toArray(
              new PluginActionContributionItem[actionContributionCache.size()]);
      actionContributionCache.clear();
      for (int i = 0; i < items.length; i++) {
        items[i].dispose();
      }
    }

    if (modelPart == null || menuModel == null) {
      return;
    }
    IEclipseContext modelContext = modelPart.getContext();
    if (modelContext != null) {
      IRendererFactory factory = modelContext.get(IRendererFactory.class);
      if (factory != null) {
        AbstractPartRenderer obj = factory.getRenderer(menuModel, null);
        if (obj instanceof MenuManagerRenderer) {
          MenuManagerRenderer renderer = (MenuManagerRenderer) obj;
          renderer.cleanUp(menuModel);
        }
      }
    }
  }
 private void createModelFor(String id) {
   if (id == null) {
     id = getClass().getName() + '.' + System.identityHashCode(this);
   }
   menuModel = null;
   for (MMenu item : modelPart.getMenus()) {
     if (id.equals(item.getElementId())
         && item instanceof MPopupMenu
         && item.getTags().contains(ContributionsAnalyzer.MC_POPUP)) {
       menuModel = (MPopupMenu) item;
       break;
     }
   }
   if (menuModel == null) {
     menuModel = MenuFactoryImpl.eINSTANCE.createPopupMenu();
     menuModel.setElementId(id);
     menuModel.getTags().add(ContributionsAnalyzer.MC_POPUP);
     modelPart.getMenus().add(menuModel);
   }
   IRendererFactory factory = modelPart.getContext().get(IRendererFactory.class);
   AbstractPartRenderer obj = factory.getRenderer(menuModel, null);
   if (obj instanceof MenuManagerRenderer) {
     ((MenuManagerRenderer) obj).linkModelToManager(menuModel, menu);
   }
   registerE4Support();
   cleanUpContributionCache();
 }
 /**
  * well, this goes to the renderer.
  *
  * @param mgr
  */
 private void addMenuContributions(IMenuManager mgr) {
   IRendererFactory factory = modelPart.getContext().get(IRendererFactory.class);
   AbstractPartRenderer obj = factory.getRenderer(menuModel, null);
   if (obj instanceof MenuManagerRenderer) {
     MenuManagerRenderer renderer = (MenuManagerRenderer) obj;
     renderer.reconcileManagerToModel(menu, menuModel);
     renderer.processContributions(menuModel, false, true);
     // double cast because we're bad people
     renderer.processContents((MElementContainer<MUIElement>) ((Object) menuModel));
   }
 }
  /** Dispose of the menu extender. Should only be called when the part is disposed. */
  public void dispose() {
    clearStaticActions();
    final IMenuService menuService = (IMenuService) part.getSite().getService(IMenuService.class);
    if (menuService != null) {
      menuService.releaseContributions(menu);
    }
    Platform.getExtensionRegistry().removeRegistryChangeListener(this);
    menu.removeMenuListener(this);

    if (menuModel != null) {
      // unlink ourselves from the renderer
      IRendererFactory factory = modelPart.getContext().get(IRendererFactory.class);
      AbstractPartRenderer obj = factory.getRenderer(menuModel, null);
      if (obj instanceof MenuManagerRenderer) {
        MenuManagerRenderer renderer = (MenuManagerRenderer) obj;
        unlink(renderer, menuModel);
        renderer.clearModelToManager(menuModel, menu);
      }

      modelPart.getMenus().remove(menuModel);
    }
  }
 private AbstractPartRenderer getRenderer(MUIElement uiElement, Object parent) {
   return curFactory.getRenderer(uiElement, parent);
 }