예제 #1
0
 /**
  * Creates the menu item for the editor descriptor.
  *
  * @param menu the menu to add the item to
  * @param descriptor the editor descriptor, or null for the system editor
  * @param preferredEditor the descriptor of the preferred editor, or <code>null</code>
  */
 private MenuItem createMenuItem(
     Menu menu, final IEditorDescriptor descriptor, final IEditorDescriptor preferredEditor) {
   // XXX: Would be better to use bold here, but SWT does not support it.
   final MenuItem menuItem = new MenuItem(menu, SWT.RADIO);
   boolean isPreferred =
       preferredEditor != null && descriptor.getId().equals(preferredEditor.getId());
   menuItem.setSelection(isPreferred);
   menuItem.setText(descriptor.getLabel());
   Image image = getImage(descriptor);
   if (image != null) {
     menuItem.setImage(image);
   }
   Listener listener =
       new Listener() {
         public void handleEvent(Event event) {
           switch (event.type) {
             case SWT.Selection:
               if (menuItem.getSelection()) {
                 openEditor(descriptor, false);
               }
               break;
           }
         }
       };
   menuItem.addListener(SWT.Selection, listener);
   return menuItem;
 }
 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);
   }
 }
예제 #3
0
  public void createDefaultMenuItem(Menu menu, final IFileRevision revision) {
    final MenuItem menuItem = new MenuItem(menu, SWT.RADIO);
    menuItem.setSelection(Utils.getDefaultEditor(revision) == null);
    menuItem.setText(TeamUIMessages.LocalHistoryPage_OpenWithMenu_DefaultEditorDescription);

    Listener listener =
        new Listener() {
          public void handleEvent(Event event) {
            switch (event.type) {
              case SWT.Selection:
                if (menuItem.getSelection()) {
                  openEditor(Utils.getDefaultEditor(revision), false);
                }
                break;
            }
          }
        };

    menuItem.addListener(SWT.Selection, listener);
  }
  /*
   * (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);
        }
      }
    }
  }