/* (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 updateToolBar() {
    if (toolbar != null) {
      ResourceManager parentResourceManager = JFaceResources.getResources();
      LocalResourceManager localManager = new LocalResourceManager(parentResourceManager);

      for (int i = 0; i < toolbar.getItemCount(); i++) {
        ToolItem item = toolbar.getItem(i);
        IAction action = (IAction) actionMap.get(item);
        if (action != null) {
          ImageDescriptor image = null;
          if (action.isEnabled() && action.getImageDescriptor() != null)
            image = action.getImageDescriptor();
          else if (action.isEnabled() && action.getImageDescriptor() != null)
            image = action.getDisabledImageDescriptor();
          if (image != null) item.setImage(localManager.createImageWithDefault(image));

          item.setToolTipText(action.getToolTipText());
          if (IAction.AS_CHECK_BOX == action.getStyle()) {
            item.setSelection(action.isChecked());
          }
        }
      }

      disposeOldImages();
      imageManager = localManager;

      if (toolbar.isFocusControl()) toolbar.setFocus();
    }
  }
 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;
   }
 }
  /* (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;
      }
    }
  }
 /*
  * @see org.eclipse.jface.dialogs.Dialog#close()
  */
 @Override
 public boolean close() {
   OwlUI.safeDispose(fAddMenu);
   fResources.dispose();
   if (!fOkPressed) {
     fPreferences.putIntegers(DefaultPreferences.TOOLBAR_ITEMS, fInitialToolBarItems);
     fPreferences.putInteger(DefaultPreferences.TOOLBAR_MODE, fInitialToolBarMode);
   }
   return super.close();
 }
 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;
   }
 }
  @Override
  public void update(ViewerCell cell) {
    super.update(cell);

    SourceFilesViewer.TranslationUnitInfo tuInfo = null;
    Object element = cell.getElement();
    if (element instanceof ITranslationUnit) {
      tuInfo = SourceFilesViewer.fetchTranslationUnitInfo((Executable) viewer.getInput(), element);
    }

    int orgColumnIndex = cell.getColumnIndex();

    if (orgColumnIndex == 0) {
      if (element instanceof String) {
        cell.setText((String) element);
        Font italicFont =
            resourceManager.createFont(
                FontDescriptor.createFrom(viewer.getTree().getFont()).setStyle(SWT.ITALIC));
        cell.setFont(italicFont);
      } else {
        cell.setFont(viewer.getTree().getFont());
      }
    } else if (orgColumnIndex == 1) {
      cell.setText(null);
      if (tuInfo != null) {
        if (tuInfo.location != null) {
          cell.setText(tuInfo.location.toOSString());
          if (tuInfo.exists)
            cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
          else cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));
        }
      }
      cell.setImage(null);
    } else if (orgColumnIndex == 2) {
      cell.setText(null);
      if (tuInfo != null && tuInfo.originalLocation != null) {
        cell.setText(tuInfo.originalLocation.toOSString());
        if (tuInfo.originalExists)
          cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
        else cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));
      }
      cell.setImage(null);
    } else if (orgColumnIndex == 3) {
      cell.setText(null);
      if (tuInfo != null) {
        if (tuInfo.exists) {
          cell.setText(Long.toString(tuInfo.fileLength));
        }
      }
      cell.setImage(null);
    } else if (orgColumnIndex == 4) {
      cell.setText(null);
      if (tuInfo != null) {
        if (tuInfo.exists) {
          String dateTimeString =
              DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)
                  .format(new Date(tuInfo.lastModified));
          cell.setText(dateTimeString);
        }
      }
      cell.setImage(null);
    } else if (orgColumnIndex == 5) {
      cell.setText(null);
      if (tuInfo != null) {
        if (tuInfo.location != null) {
          String fileExtension = tuInfo.location.getFileExtension();
          if (fileExtension != null) cell.setText(fileExtension.toLowerCase());
        }
      }
      cell.setImage(null);
    }
  }
 /** Dispose any images allocated for this menu */
 private void disposeOldImages() {
   if (imageManager != null) {
     imageManager.dispose();
     imageManager = null;
   }
 }
 @Override
 public boolean close() {
   fVisibleInstance = null;
   fResources.dispose();
   return super.close();
 }
  /*
   * @see org.eclipse.jface.dialogs.TrayDialog#close()
   */
  @Override
  public boolean close() {
    fResources.dispose();

    return super.close();
  }
 private void disposeOldImages() {
   if (localResourceManager != null) {
     localResourceManager.dispose();
     localResourceManager = null;
   }
 }
 @Override
 public void dispose() {
   resourceManager.dispose();
 }