/*
   * (non-Javadoc)
   *
   * @see org.eclipse.jface.action.ContributionItem#fill(org.eclipse.swt.widgets.Menu,
   *      int)
   */
  public void fill(Menu parent, int index) {
    if (command == null) {
      return;
    }
    if (widget != null || parent == null) {
      return;
    }

    // Menus don't support the pulldown style
    int tmpStyle = style;
    if (tmpStyle == STYLE_PULLDOWN) tmpStyle = STYLE_PUSH;

    MenuItem item = null;
    if (index >= 0) {
      item = new MenuItem(parent, tmpStyle, index);
    } else {
      item = new MenuItem(parent, tmpStyle);
    }
    item.setData(this);

    item.addListener(SWT.Dispose, getItemListener());
    item.addListener(SWT.Selection, getItemListener());
    widget = item;

    update(null);
  }
 private void setChecked(boolean checked) {
   if (checkedState == checked) {
     return;
   }
   checkedState = checked;
   if (widget instanceof MenuItem) {
     ((MenuItem) widget).setSelection(checkedState);
   } else if (widget instanceof ToolItem) {
     ((ToolItem) widget).setSelection(checkedState);
   }
 }
 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;
   }
 }
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.jface.action.ContributionItem#update(java.lang.String)
   */
  public void update(String id) {
    if (widget != null) {
      if (widget instanceof MenuItem) {
        MenuItem item = (MenuItem) widget;

        String text = label;
        if (text == null) {
          if (command != null) {
            try {
              text = command.getCommand().getName();
            } catch (NotDefinedException e) {
              WorkbenchPlugin.log(
                  "Update item failed " //$NON-NLS-1$
                      + getId(),
                  e);
            }
          }
        }
        // TODO: [bm] key bindings
        //				text = updateMnemonic(text);
        //
        //				String keyBindingText = null;
        //				if (command != null) {
        //					TriggerSequence[] bindings = bindingService
        //							.getActiveBindingsFor(command);
        //					if (bindings.length > 0) {
        //						keyBindingText = bindings[0].format();
        //					}
        //				}
        //				if (text != null) {
        //					if (keyBindingText == null) {
        item.setText(text);
        //					} else {
        //						item.setText(text + '\t' + keyBindingText);
        //					}
        //				}

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

        boolean shouldBeEnabled = isEnabled();
        if (item.getEnabled() != shouldBeEnabled) {
          item.setEnabled(shouldBeEnabled);
        }
      } else if (widget instanceof ToolItem) {
        ToolItem item = (ToolItem) widget;

        if (icon != null) {
          updateIcons();
        } else if (label != null) {
          item.setText(label);
        }

        if (tooltip != null) item.setToolTipText(tooltip);
        else {
          String text = label;
          if (text == null) {
            if (command != null) {
              try {
                text = command.getCommand().getName();
              } catch (NotDefinedException e) {
                WorkbenchPlugin.log(
                    "Update item failed " //$NON-NLS-1$
                        + getId(),
                    e);
              }
            }
          }
          if (text != null) {
            item.setToolTipText(text);
          }
        }

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

        boolean shouldBeEnabled = isEnabled();
        if (item.getEnabled() != shouldBeEnabled) {
          item.setEnabled(shouldBeEnabled);
        }
      }
    }
  }