Exemplo n.º 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;
 }
Exemplo n.º 2
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);
  }