Package org.eclipse.swt.widgets

Examples of org.eclipse.swt.widgets.MenuItem


    when( page.getDescriptor() ).thenReturn( descriptor );

    webUI.pageCreated( page );

    assertEquals( 1, webUI.getPageSwitcherMenu().getItemCount() );
    MenuItem item = webUI.getPageSwitcherMenu().getItem( 0 );
    assertEquals( "Title", item.getText() );
    assertSame( descriptor, item.getData() );
    assertTrue( item.isListening( SWT.Selection ) );
  }
View Full Code Here


  }

  @Test
  public void testDoSearch_clearsMenuItems() {
    webSearchAction.open();
    new MenuItem( proposalsMenu, SWT.PUSH );

    text.notifyListeners( SWT.DefaultSelection, new Event() );

    assertEquals( 0, proposalsMenu.getItemCount() );
  }
View Full Code Here

  private void addSamplesMenu() {

    sampleMenu = new Menu(shell, SWT.POP_UP);

    showSampleItem = new MenuItem(sampleMenu, SWT.PUSH);
    showSampleItem.setText(BaseMessages.getString(PKG, "RubyStepDialog.SamplesMenu.ShowSample"));
    //showSampleItem.setImage(libScriptImage);
    showSampleItem.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event e) {
        for (TreeItem item : wSamplesTree.getSelection()) {
View Full Code Here

  private void addScriptPopupMenu() {

    scriptMenu = new Menu(shell, SWT.POP_UP);

    MenuItem addNewItem = new MenuItem(scriptMenu, SWT.PUSH);
    addNewItem.setText(BaseMessages.getString(PKG, "RubyStepDialog.Menu.AddNewTab"));
    addNewItem.setImage(addImage);
    addNewItem.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event e) {
        RubyScriptMeta script = RubyScriptMeta.createScriptWithUniqueName(collectScripts());
        addScriptTab(script);
        input.setChanged();
        changedInDialog = true;

        wScriptsFolder.setSelection(wScriptsFolder.getItemCount() - 1); // select newest tab

      }
    });
    new MenuItem(scriptMenu, SWT.SEPARATOR);

    renameItem = new MenuItem(scriptMenu, SWT.PUSH);
    renameItem.setText(BaseMessages.getString(PKG, "RubyStepDialog.Menu.RenameScript"));
    renameItem.setImage(renameImage);
    renameItem.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event e) {
        RubyStepRenameDialog d = new RubyStepRenameDialog(shell);
        String newName = d.open(wScriptsFolder.getSelection().getText(), collectInactiveScriptNames());
        if (newName != null) {
          wScriptsFolder.getSelection().setText(newName);
          input.setChanged();
          changedInDialog = true;
        }
      }
    });
    new MenuItem(scriptMenu, SWT.SEPARATOR);

    rowScriptItem = new MenuItem(scriptMenu, SWT.RADIO);
    rowScriptItem.setText(BaseMessages.getString(PKG, "RubyStepDialog.Menu.RowScript"));
    rowScriptItem.setImage(rowScriptImage);
    rowScriptItem.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {
        MenuItem item = (MenuItem) e.widget;
        if (item.getSelection()) {
          setActiveTabRowScript();
        }
      }
    });

    libScriptItem = new MenuItem(scriptMenu, SWT.RADIO);
    libScriptItem.setText(BaseMessages.getString(PKG, "RubyStepDialog.Menu.LibScript"));
    libScriptItem.setImage(libScriptImage);
    libScriptItem.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {
        MenuItem item = (MenuItem) e.widget;
        if (item.getSelection()) {
          setActiveTabLibScript();
        }
      }
    });

    initScriptItem = new MenuItem(scriptMenu, SWT.RADIO);
    initScriptItem.setText(BaseMessages.getString(PKG, "RubyStepDialog.Menu.InitScript"));
    initScriptItem.setImage(initScriptImage);
    initScriptItem.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {
        MenuItem item = (MenuItem) e.widget;
        if (item.getSelection()) {
          setActiveTabInitScript();
        }
      }
    });

    disposeScriptItem = new MenuItem(scriptMenu, SWT.RADIO);
    disposeScriptItem.setText(BaseMessages.getString(PKG, "RubyStepDialog.Menu.DisposeScript"));
    disposeScriptItem.setImage(disposeScriptImage);
    disposeScriptItem.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {
        MenuItem item = (MenuItem) e.widget;
        if (item.getSelection()) {
          setActiveTabDisposeScript();
        }
      }
    });
View Full Code Here

    data.heightHint = 150;
    data.horizontalSpan = 2;
    list.setLayoutData(data);
    list.setFont(parent.getFont());
    Menu copyMenu = new Menu(list);
    MenuItem copyItem = new MenuItem(copyMenu, SWT.NONE);
    copyItem.addSelectionListener(new SelectionListener() {
      /*
       * @see SelectionListener.widgetSelected (SelectionEvent)
       */
      public void widgetSelected(SelectionEvent e) {
        copyToClipboard();
      }

      /*
       * @see SelectionListener.widgetDefaultSelected(SelectionEvent)
       */
      public void widgetDefaultSelected(SelectionEvent e) {
        copyToClipboard();
      }
    });
    copyItem.setText(JFaceResources.getString("copy")); //$NON-NLS-1$
    list.setMenu(copyMenu);
    listCreated = true;
    return list;
  }
View Full Code Here

   
    // this would need extra work to make this accessible
    // from the workbench command framework.
    Menu menu = new Menu(fMessageLabel);
    fMessageLabel.setMenu(menu);
    copyMenuItem = new MenuItem(menu, SWT.PUSH);
    copyMenuItem.setText(JFaceResources.getString("copy")); //$NON-NLS-1$
    copyMenuItem.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {
        String text = fMessageLabel.getText();
        if (text != null && text.length() > 0) {
View Full Code Here

     * @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);
View Full Code Here

        } else if (style == IAction.AS_DROP_DOWN_MENU) {
          flags = SWT.CASCADE;
        }
      }

      MenuItem mi = null;
      if (index >= 0) {
        mi = new MenuItem(parent, flags, index);
      } else {
        mi = new MenuItem(parent, flags);
      }
      widget = mi;

      mi.setData(this);
      mi.addListener(SWT.Dispose, getMenuItemListener());
      mi.addListener(SWT.Selection, getMenuItemListener());
      if (action.getHelpListener() != null) {
        mi.addHelpListener(action.getHelpListener());
      }

      if (flags == SWT.CASCADE) {
        // just create a proxy for now, if the user shows it then
        // fill it in
        Menu subMenu = new Menu(parent);
        subMenu.addListener(SWT.Show, getMenuCreatorListener());
        subMenu.addListener(SWT.Hide, getMenuCreatorListener());
        mi.setMenu(subMenu);
      }

      update(null);

      // Attach some extra listeners.
View Full Code Here

        }
        return;
      }

      if (widget instanceof MenuItem) {
        MenuItem mi = (MenuItem) widget;

        if (textChanged) {
          int accelerator = 0;
          String acceleratorText = null;
          IAction updatedAction = getAction();
          String text = null;
          accelerator = updatedAction.getAccelerator();
          ExternalActionManager.ICallback callback = ExternalActionManager
              .getInstance().getCallback();

          // Block accelerators that are already in use.
          if ((accelerator != 0) && (callback != null)
              && (callback.isAcceleratorInUse(accelerator))) {
            accelerator = 0;
          }

          /*
           * Process accelerators on GTK in a special way to avoid Bug
           * 42009. We will override the native input method by
           * allowing these reserved accelerators to be placed on the
           * menu. We will only do this for "Ctrl+Shift+[0-9A-FU]".
           */
          final String commandId = updatedAction
              .getActionDefinitionId();
          if ((Util.isGtk()) && (callback instanceof IBindingManagerCallback)
              && (commandId != null)) {
            final IBindingManagerCallback bindingManagerCallback = (IBindingManagerCallback) callback;
            final IKeyLookup lookup = KeyLookupFactory.getDefault();
            final TriggerSequence[] triggerSequences = bindingManagerCallback
                .getActiveBindingsFor(commandId);
            for (int i = 0; i < triggerSequences.length; i++) {
              final TriggerSequence triggerSequence = triggerSequences[i];
              final Trigger[] triggers = triggerSequence
                  .getTriggers();
              if (triggers.length == 1) {
                final Trigger trigger = triggers[0];
                if (trigger instanceof KeyStroke) {
                  final KeyStroke currentKeyStroke = (KeyStroke) trigger;
                  final int currentNaturalKey = currentKeyStroke
                      .getNaturalKey();
                  if ((currentKeyStroke.getModifierKeys() == (lookup
                      .getCtrl() | lookup.getShift()))
                      && ((currentNaturalKey >= '0' && currentNaturalKey <= '9')
                          || (currentNaturalKey >= 'A' && currentNaturalKey <= 'F') || (currentNaturalKey == 'U'))) {
                    accelerator = currentKeyStroke
                        .getModifierKeys()
                        | currentNaturalKey;
                    acceleratorText = triggerSequence
                        .format();
                    break;
                  }
                }
              }
            }
          }

          if (accelerator == 0) {
            if ((callback != null) && (commandId != null)) {
              acceleratorText = callback
                  .getAcceleratorText(commandId);
            }
          }

          IContributionManagerOverrides overrides = null;

          if (getParent() != null) {
            overrides = getParent().getOverrides();
          }

          if (overrides != null) {
            text = getParent().getOverrides().getText(this);
          }

          mi.setAccelerator(accelerator);

          if (text == null) {
            text = updatedAction.getText();
          }

          if (text != null && acceleratorText == null) {
            // use extracted accelerator text in case accelerator
            // cannot be fully represented in one int (e.g.
            // multi-stroke keys)
            acceleratorText = LegacyActionTools
                .extractAcceleratorText(text);
            if (acceleratorText == null && accelerator != 0) {
              acceleratorText = Action
                  .convertAccelerator(accelerator);
            }
          }

          if (text == null) {
            text = ""; //$NON-NLS-1$
          } else {
            text = Action.removeAcceleratorText(text);
          }

          if (acceleratorText == null) {
            mi.setText(text);
          } else {
            mi.setText(text + '\t' + acceleratorText);
          }
        }

        if (imageChanged) {
          updateImages(false);
        }

        if (enableStateChanged) {
          boolean shouldBeEnabled = action.isEnabled()
              && isEnabledAllowed();

          if (mi.getEnabled() != shouldBeEnabled) {
            mi.setEnabled(shouldBeEnabled);
          }
        }

        if (checkChanged) {
          boolean bv = action.isChecked();

          if (mi.getSelection() != bv) {
            mi.setSelection(bv);
          }
        }

        return;
      }
View Full Code Here

      }
    };

    MenuItem[] items = realMenu.getItems();
    for (int i = 0; i < items.length; i++) {
      final MenuItem realItem = items[i];
      final MenuItem proxyItem = new MenuItem(proxy, realItem.getStyle());
      proxyItem.setData(realItem);
      proxyItem.setAccelerator(realItem.getAccelerator());
      proxyItem.setEnabled(realItem.getEnabled());
      proxyItem.setImage(realItem.getImage());
      proxyItem.setSelection(realItem.getSelection());
      proxyItem.setText(realItem.getText());

      // pass through any events
      proxyItem.addListener(SWT.Selection, passThrough);
      proxyItem.addListener(SWT.Arm, passThrough);
      proxyItem.addListener(SWT.Help, passThrough);

      final Menu itemMenu = realItem.getMenu();
      if (itemMenu != null) {
        // create a proxy for any sub menu items
        final Menu subMenu = new Menu(proxy);
        subMenu.setData(itemMenu);
        proxyItem.setMenu(subMenu);
        subMenu.addListener(SWT.Show, new Listener() {
          public void handleEvent(Event event) {
            event.widget.removeListener(SWT.Show, this);
            if (event.type == SWT.Show) {
              copyMenu(itemMenu, subMenu);
View Full Code Here

TOP

Related Classes of org.eclipse.swt.widgets.MenuItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.