/* (non-Javadoc)
   * @see org.eclipse.jface.action.IContributionItem#fill(org.eclipse.swt.widgets.Menu, int)
   */
  public void fill(Menu parent, int index) {
    if (menuItem == null || menuItem.isDisposed()) {
      if (index >= 0) {
        menuItem = new MenuItem(parent, SWT.CASCADE, index);
      } else {
        menuItem = new MenuItem(parent, SWT.CASCADE);
      }

      String text = getMenuText();
      if (text != null) {
        menuItem.setText(text);
      }

      if (image != null) {
        LocalResourceManager localManager = new LocalResourceManager(JFaceResources.getResources());
        menuItem.setImage(localManager.createImage(image));
        disposeOldImages();
        imageManager = localManager;
      }

      if (!menuExist()) {
        menu = new Menu(parent);
        menu.setData(MANAGER_KEY, this);
      }

      menuItem.setMenu(menu);

      initializeMenu();

      setDirty(true);
    }
  }
  private void updateMenuItem() {
    final MenuItem item = (MenuItem) this.widget;

    final boolean shouldBeEnabled = isEnabled();

    // disabled command + visibility follows enablement == disposed
    if (item.isDisposed()) {
      return;
    }

    String text = this.label;
    text = updateMnemonic(text);

    final String keyBindingText = null;
    if (text != null) {
      if (keyBindingText == null) {
        item.setText(text);
      } else {
        item.setText(text + '\t' + keyBindingText);
      }
    }

    if (item.getSelection() != this.checkedState) {
      item.setSelection(this.checkedState);
    }

    if (item.getEnabled() != shouldBeEnabled) {
      item.setEnabled(shouldBeEnabled);
    }
  }
 private boolean isTopLevelMenu() {
   if (menu != null && !menu.isDisposed() && menuItem != null && !menuItem.isDisposed()) {
     Menu parentMenu = menuItem.getParent();
     return parentMenu != null && ((parentMenu.getStyle() & SWT.BAR) == SWT.BAR);
   }
   return false;
 }
Beispiel #4
0
 /**
  * Sets the default menu item to the argument or removes the default emphasis when the argument is
  * <code>null</code>.
  *
  * @param item the default menu item or null
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_INVALID_ARGUMENT - if the menu item has been disposed
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public void setDefaultItem(MenuItem item) {
   checkWidget();
   if (item != null) {
     if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
     if (item.parent != this) return;
     OS.QMenu_setDefaultAction(handle, item.handle);
   } else {
     OS.QMenu_setDefaultAction(handle, 0);
   }
 }
Beispiel #5
0
 void releaseChildren_pp(boolean destroy) {
   MenuItem[] items = getItems();
   for (int i = 0; i < items.length; i++) {
     MenuItem item = items[i];
     if (item != null && !item.isDisposed()) {
       item.release(false);
     }
   }
   super.releaseChildren_pp(destroy);
 }
 protected void disposeMenuItems() {
   if (fMenu == null || fMenu.isDisposed()) {
     return;
   }
   MenuItem[] items = fMenu.getItems();
   for (int i = 0; i < items.length; i++) {
     MenuItem menuItem = items[i];
     if (!menuItem.isDisposed()) {
       menuItem.dispose();
     }
   }
 }
Beispiel #7
0
 public void clearMenu() {
   for (org.eclipse.swt.widgets.MenuItem item : menu.getItems()) {
     if (!item.isDisposed()) {
       item.dispose();
     }
   }
   if (isIconReloadEnqueued) {
     IconFactory.getInstance().cleanup();
     IconFactory.getInstance().loadResources();
     isIconReloadEnqueued = false;
   }
 }
 /**
  * Updates the menu item for this sub menu. The menu item is disabled if this sub menu is empty.
  * Does nothing if this menu is not a submenu.
  */
 private void updateMenuItem() {
   /*
   * Commented out until proper solution to enablement of
   * menu item for a sub-menu is found. See bug 30833 for
   * more details.
   *
   if (menuItem != null && !menuItem.isDisposed() && menuExist()) {
   IContributionItem items[] = getItems();
   boolean enabled = false;
   for (int i = 0; i < items.length; i++) {
   IContributionItem item = items[i];
   enabled = item.isEnabled();
   if(enabled) break;
   }
   // Workaround for 1GDDCN2: SWT:Linux - MenuItem.setEnabled() always causes a redraw
   if (menuItem.getEnabled() != enabled)
   menuItem.setEnabled(enabled);
   }
   */
   // Partial fix for bug #34969 - diable the menu item if no
   // items in sub-menu (for context menus).
   if (menuItem != null && !menuItem.isDisposed() && menuExist()) {
     boolean enabled = removeAllWhenShown || menu.getItemCount() > 0;
     // Workaround for 1GDDCN2: SWT:Linux - MenuItem.setEnabled() always causes a redraw
     if (menuItem.getEnabled() != enabled) {
       // We only do this for context menus (for bug #34969)
       Menu topMenu = menu;
       while (topMenu.getParentMenu() != null) {
         topMenu = topMenu.getParentMenu();
       }
       if ((topMenu.getStyle() & SWT.BAR) == 0) {
         menuItem.setEnabled(enabled);
       }
     }
   }
 }
 /**
  * The default implementation of this <code>IContributionItem</code> method does nothing.
  * Subclasses may override.
  */
 @Override
 public void dispose() {
   if (subMenuItem != null && !subMenuItem.isDisposed()) {
     subMenuItem.dispose();
   }
 }