Esempio n. 1
0
  public void fill(Menu menu, int index) {
    if (getParent() instanceof MenuManager) {
      ((MenuManager) getParent()).addMenuListener(menuListener);
    }

    if (!dirty) {
      return;
    }

    if (currentManager != null && currentManager.getSize() > 0) {
      IMenuService service = (IMenuService) locator.getService(IMenuService.class);
      service.releaseContributions(currentManager);
      currentManager.removeAll();
    }

    currentManager = new MenuManager();
    fillMenu(currentManager);
    IContributionItem[] items = currentManager.getItems();
    if (items.length == 0) {
      MenuItem item = new MenuItem(menu, SWT.NONE, index++);
      item.setText(NO_TARGETS_MSG);
      item.setEnabled(false);
    } else {
      for (int i = 0; i < items.length; i++) {
        if (items[i].isVisible()) {
          items[i].fill(menu, index++);
        }
      }
    }
    dirty = false;
  }
Esempio n. 2
0
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.jface.action.ContributionItem#dispose()
  */
 public void dispose() {
   if (currentManager != null && currentManager.getSize() > 0) {
     IMenuService service = (IMenuService) locator.getService(IMenuService.class);
     if (service != null) {
       service.releaseContributions(currentManager);
     }
     currentManager.removeAll();
   }
 }
Esempio n. 3
0
    public final void testAdditionalSomePresent() {
      LabelWrapper lw = new LabelWrapper("Some label", new WorldLocation(1.1, 1.1, 12), Color.red);
      Editable[] editables = new Editable[] {lw};
      MenuManager menu = new MenuManager("Holder");

      RightClickSupport.getDropdownListFor(menu, editables, null, null, null, true);

      // note: this next test may return 4 if run from within IDE,
      // some contributions provided by plugins
      assertEquals("Has items", 2, menu.getSize(), 2);
    }
 private void addToManager(
     MenuManager parentManager, MMenuElement model, IContributionItem menuManager) {
   MElementContainer<MUIElement> parent = model.getParent();
   // technically this shouldn't happen
   if (parent == null) {
     parentManager.add(menuManager);
   } else {
     int index = parent.getChildren().indexOf(model);
     // shouldn't be -1, but better safe than sorry
     if (index > parentManager.getSize() || index == -1) {
       parentManager.add(menuManager);
     } else {
       parentManager.insert(index, menuManager);
     }
   }
 }
Esempio n. 5
0
    public final void testAdditionalNonePresent() {
      ShapeWrapper sw =
          new ShapeWrapper(
              "rect",
              new RectangleShape(
                  new WorldLocation(12.1, 12.3, 12), new WorldLocation(1.1, 1.1, 12)),
              Color.red,
              new HiResDate(2222));
      Editable[] editables = new Editable[] {sw};
      MenuManager menu = new MenuManager("Holder");

      RightClickSupport.getDropdownListFor(menu, editables, null, null, null, true);

      boolean foundTransparent = false;

      // note: this next test may return 4 if run from within IDE,
      // some contributions provided by plugins
      assertEquals("Has items", 2, menu.getSize(), 2);

      IContributionItem[] items = menu.getItems();
      for (int i = 0; i < items.length; i++) {
        IContributionItem thisI = items[i];
        if (thisI instanceof MenuManager) {
          MenuManager subMenu = (MenuManager) thisI;
          IContributionItem[] subItems = subMenu.getItems();
          for (int j = 0; j < subItems.length; j++) {
            IContributionItem subI = subItems[j];
            if (subI instanceof ActionContributionItem) {
              ActionContributionItem ac = (ActionContributionItem) subI;
              String theName = ac.getAction().getText();
              if (theName.equals("Semi transparent")) foundTransparent = true;
            }
          }
        }
      }

      assertTrue("The additional bean info got processed!", foundTransparent);
    }