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();
 }
 /**
  * @param menuModel
  * @param isMenuBar
  * @param isPopup
  */
 public void processContributions(MMenu menuModel, boolean isMenuBar, boolean isPopup) {
   if (menuModel.getElementId() == null) {
     return;
   }
   final ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>();
   ContributionsAnalyzer.XXXgatherMenuContributions(
       menuModel,
       application.getMenuContributions(),
       menuModel.getElementId(),
       toContribute,
       null,
       isPopup);
   generateContributions(menuModel, toContribute, isMenuBar);
   for (MMenuElement element : menuModel.getChildren()) {
     if (element instanceof MMenu) {
       processContributions((MMenu) element, false, isPopup);
     }
   }
 }
Esempio n. 3
0
 private MMenu getPopupMenu(final MApplication inApplication, final EModelService inModel) {
   if (popupStyles == null) {
     final MPart lPart = (MPart) inModel.find(RelationsConstants.PART_INSPECTOR, inApplication);
     for (final MMenu lMenu : lPart.getMenus()) {
       if (RelationsConstants.POPUP_INSPECTOR.equals(lMenu.getElementId())) {
         popupStyles = lMenu;
         break;
       }
     }
   }
   return popupStyles;
 }
 /**
  * @param parentManager
  * @param menuModel
  */
 private void processMenu(MenuManager parentManager, MMenu menuModel) {
   MenuManager menuManager = getManager(menuModel);
   if (menuManager == null) {
     String menuText = getText(menuModel);
     ImageDescriptor desc = getImageDescriptor(menuModel);
     menuManager = new MenuManager(menuText, desc, menuModel.getElementId());
     linkModelToManager(menuModel, menuManager);
     menuManager.setVisible(menuModel.isVisible());
     addToManager(parentManager, menuModel, menuManager);
   }
   // processContributions(menuModel, false);
   List<MMenuElement> parts = menuModel.getChildren();
   if (parts != null) {
     MMenuElement[] plist = parts.toArray(new MMenuElement[parts.size()]);
     for (int i = 0; i < plist.length; i++) {
       MMenuElement childME = plist[i];
       modelProcessSwitch(menuManager, childME);
     }
   }
 }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#processContents
   * (org.eclipse.e4.ui.model.application.ui.MElementContainer)
   */
  @Override
  public void processContents(MElementContainer<MUIElement> container) {
    if (container.getChildren().size() == 0) {
      Object obj = container.getWidget();
      if (obj instanceof MenuItem) {
        MenuItem mi = (MenuItem) obj;
        if (mi.getMenu() == null) {
          mi.setMenu(new Menu(mi));
        }
        Menu menu = mi.getMenu();
        MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
        menuItem.setText(MenuManagerRendererFilter.NUL_MENU_ITEM);
        menuItem.setEnabled(false);
      }
    }

    super.processContents(container);

    Object obj = container.getWidget();
    Object menuObj = container;
    if ((obj instanceof Menu)
        && (((Menu) obj).getStyle() & SWT.BAR) != 0
        && (menuObj instanceof MMenu)) {
      MMenu menuModel = (MMenu) menuObj;
      IEclipseContext ctx = getContext(container);
      ExpressionContext eContext = new ExpressionContext(ctx);
      ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>();
      ContributionsAnalyzer.gatherMenuContributions(
          menuModel,
          application.getMenuContributions(),
          menuModel.getElementId(),
          toContribute,
          eContext,
          false);
      addMenuBarContributions(menuModel, toContribute, ctx, eContext);
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#createWidget
   * (org.eclipse.e4.ui.model.application.ui.MUIElement, java.lang.Object)
   */
  @Override
  public Object createWidget(MUIElement element, Object parent) {
    if (!(element instanceof MMenu)) return null;

    final MMenu menuModel = (MMenu) element;
    Menu newMenu = null;
    MenuManager menuManager = null;
    boolean menuBar = false;

    if (parent instanceof Decorations) {
      MUIElement container = (MUIElement) ((EObject) element).eContainer();
      if (container instanceof MWindow) {
        menuManager = getManager(menuModel);
        if (menuManager == null) {
          menuManager = new MenuManager(NO_LABEL, menuModel.getElementId());
          linkModelToManager(menuModel, menuManager);
        }
        newMenu = menuManager.createMenuBar((Decorations) parent);
        ((Decorations) parent).setMenuBar(newMenu);
        newMenu.setData(menuManager);
        menuBar = true;
      } else {
        menuManager = getManager(menuModel);
        if (menuManager == null) {
          menuManager = new MenuManager(NO_LABEL, menuModel.getElementId());
          linkModelToManager(menuModel, menuManager);
        }
        newMenu = menuManager.createContextMenu((Control) parent);
        // we can't be sure this is the correct parent.
        // ((Control) parent).setMenu(newMenu);
        newMenu.setData(menuManager);
      }
    } else if (parent instanceof Menu) {
      // Object data = ((Menu) parent).getData();
      logger.debug(
          new Exception(),
          "Trying to render a sub menu " //$NON-NLS-1$
              + menuModel
              + "\n\t"
              + parent); //$NON-NLS-1$
      return null;

    } else if (parent instanceof Control) {
      menuManager = getManager(menuModel);
      if (menuManager == null) {
        menuManager = new MenuManager(NO_LABEL, menuModel.getElementId());
        linkModelToManager(menuModel, menuManager);
      }
      newMenu = menuManager.createContextMenu((Control) parent);
      // we can't be sure this is the correct parent.
      // ((Control) parent).setMenu(newMenu);
      newMenu.setData(menuManager);
    }
    if (!menuManager.getRemoveAllWhenShown()) {
      processContributions(menuModel, menuBar, menuModel instanceof MPopupMenu);
    }
    if (newMenu != null) {
      newMenu.addDisposeListener(
          new DisposeListener() {
            public void widgetDisposed(DisposeEvent e) {
              cleanUp(menuModel);
            }
          });
    }
    return newMenu;
  }