private void updateIcons() {
   if (this.widget instanceof MenuItem) {
     final MenuItem item = (MenuItem) this.widget;
     final LocalResourceManager m = new LocalResourceManager(JFaceResources.getResources());
     try {
       item.setImage(this.icon == null ? null : m.createImage(this.icon));
     } catch (final DeviceResourceException e) {
       this.icon = ImageDescriptor.getMissingImageDescriptor();
       item.setImage(m.createImage(this.icon));
       // as we replaced the failed icon, log the message once.
       StatusManager.getManager()
           .handle(
               new Status(
                   IStatus.ERROR,
                   SharedUIResources.PLUGIN_ID,
                   "Failed to load image",
                   e)); //$NON-NLS-1$
     }
     disposeOldImages();
     this.localResourceManager = m;
   } else if (this.widget instanceof ToolItem) {
     final ToolItem item = (ToolItem) this.widget;
     final LocalResourceManager m = new LocalResourceManager(JFaceResources.getResources());
     item.setDisabledImage(this.disabledIcon == null ? null : m.createImage(this.disabledIcon));
     item.setHotImage(this.hoverIcon == null ? null : m.createImage(this.hoverIcon));
     item.setImage(this.icon == null ? null : m.createImage(this.icon));
     disposeOldImages();
     this.localResourceManager = m;
   }
 }
Ejemplo n.º 2
0
  /* (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 updateIcons() {
   if (widget instanceof MenuItem) {
     MenuItem item = (MenuItem) widget;
     LocalResourceManager m = new LocalResourceManager(JFaceResources.getResources());
     item.setImage(icon == null ? null : m.createImage(icon));
     disposeOldImages();
     localResourceManager = m;
   } else if (widget instanceof ToolItem) {
     ToolItem item = (ToolItem) widget;
     LocalResourceManager m = new LocalResourceManager(JFaceResources.getResources());
     // TODO: [bm] dis/hot images of item
     //			item.setDisabledImage(disabledIcon == null ? null : m
     //					.createImage(disabledIcon));
     //			item.setHotImage(hoverIcon == null ? null : m
     //					.createImage(hoverIcon));
     item.setImage(icon == null ? null : m.createImage(icon));
     disposeOldImages();
     localResourceManager = m;
   }
 }
Ejemplo n.º 4
0
  /* (non-Javadoc)
   * @see org.eclipse.jface.action.IContributionItem#update(java.lang.String)
   */
  public void update(String property) {
    IContributionItem items[] = getItems();

    for (int i = 0; i < items.length; i++) {
      items[i].update(property);
    }

    if (menu != null && !menu.isDisposed() && menu.getParentItem() != null) {
      if (IAction.TEXT.equals(property)) {
        String text = getOverrides().getText(this);

        if (text == null) {
          text = getMenuText();
        }

        if (text != null) {
          ExternalActionManager.ICallback callback =
              ExternalActionManager.getInstance().getCallback();

          if (callback != null) {
            int index = text.indexOf('&');

            if (index >= 0 && index < text.length() - 1) {
              char character = Character.toUpperCase(text.charAt(index + 1));

              if (callback.isAcceleratorInUse(SWT.ALT | character) && isTopLevelMenu()) {
                if (index == 0) {
                  text = text.substring(1);
                } else {
                  text = text.substring(0, index) + text.substring(index + 1);
                }
              }
            }
          }

          menu.getParentItem().setText(text);
        }
      } else if (IAction.IMAGE.equals(property) && image != null) {
        LocalResourceManager localManager = new LocalResourceManager(JFaceResources.getResources());
        menu.getParentItem().setImage(localManager.createImage(image));
        disposeOldImages();
        imageManager = localManager;
      }
    }
  }