public void testExtensionContributionExpression() throws Exception {
    IAction a =
        new Action() {
          @Override
          public void run() {
            System.out.println("Hello action");
          }
        };
    final MenuManager manager = new MenuManager();
    final ActionContributionItem aci = new ActionContributionItem(a);

    IExtensionRegistry reg = Platform.getExtensionRegistry();
    IExtensionPoint menusExtension = reg.getExtensionPoint("org.eclipse.ui.menus");
    IExtension extension = menusExtension.getExtension(EXTENSION_ID);

    IConfigurationElement[] mas = extension.getConfigurationElements();
    final Expression activeContextExpr[] = new Expression[1];
    for (IConfigurationElement ma : mas) {
      IConfigurationElement[] items = ma.getChildren();
      for (IConfigurationElement item : items) {
        String id = item.getAttribute("id");
        if (id != null && id.equals("org.eclipse.ui.tests.menus.itemX1")) {
          IConfigurationElement visibleWhenElement = item.getChildren("visibleWhen")[0];
          activeContextExpr[0] =
              ExpressionConverter.getDefault().perform(visibleWhenElement.getChildren()[0]);
        }
      }
    }
    assertNotNull("Failed to find expression", activeContextExpr[0]);
    AbstractContributionFactory factory =
        new AbstractContributionFactory(LOCATION, TestPlugin.PLUGIN_ID) {
          @Override
          public void createContributionItems(
              IServiceLocator menuService, IContributionRoot additions) {
            additions.addContributionItem(aci, activeContextExpr[0]);
          }
        };

    menuService.addContributionFactory(factory);
    menuService.populateContributionManager(manager, LOCATION);

    assertFalse("starting state", aci.isVisible());

    activeContext = contextService.activateContext(MenuContributionHarness.CONTEXT_TEST1_ID);
    final Menu menu = manager.createContextMenu(window.getShell());
    menu.notifyListeners(SWT.Show, new Event());
    assertTrue("active context", aci.isVisible());
    menu.notifyListeners(SWT.Hide, new Event());

    contextService.deactivateContext(activeContext);
    activeContext = null;

    menu.notifyListeners(SWT.Show, new Event());
    assertFalse("after deactivation", aci.isVisible());
    menu.notifyListeners(SWT.Hide, new Event());

    menuService.releaseContributions(manager);
    menuService.removeContributionFactory(factory);
    manager.dispose();
  }
  public Object createWidget(final MUIElement element, Object parent) {
    if (!(element instanceof MMenu)) return null;

    final MMenu menuModel = (MMenu) element;

    Menu newMenu = null;
    if (parent instanceof Decorations) {
      MUIElement container = (MUIElement) ((EObject) element).eContainer();
      if (container instanceof MWindow) {
        newMenu = new Menu((Decorations) parent, SWT.BAR);
        newMenu.addDisposeListener(
            new DisposeListener() {
              public void widgetDisposed(DisposeEvent e) {
                cleanUp(menuModel);
              }
            });
      } else {
        newMenu = new Menu((Decorations) parent, SWT.POP_UP);
      }
    } else if (parent instanceof Menu) {
      int addIndex = calcVisibleIndex(menuModel);
      MenuItem newItem = new MenuItem((Menu) parent, SWT.CASCADE, addIndex);
      setItemText(menuModel, newItem);
      newItem.setImage(getImage(menuModel));
      newItem.setEnabled(menuModel.isEnabled());
      return newItem;
    } else if (parent instanceof Control) {
      newMenu = new Menu((Control) parent);
    }

    return newMenu;
  }
  /**
   * Determines if the selection was on the dropdown affordance and, if so, opens the drop down menu
   * (populated using the same id as this item...
   *
   * @param event The <code>SWT.Selection</code> event to be tested
   * @return <code>true</code> iff a drop down menu was opened
   */
  private boolean openDropDownMenu(final Event event) {
    final Widget item = event.widget;
    if (item != null) {
      final int style = item.getStyle();
      if ((style & SWT.DROP_DOWN) != 0) {
        if (event.detail == 4) { // on drop-down button
          final ToolItem ti = (ToolItem) item;

          final MenuManager menuManager = new MenuManager();
          final Menu menu = menuManager.createContextMenu(ti.getParent());
          if (this.workbenchHelpSystem != null) {
            this.workbenchHelpSystem.setHelp(menu, this.helpContextId);
          }
          initDropDownMenu(menuManager);

          // position the menu below the drop down item
          final Point point = ti.getParent().toDisplay(new Point(event.x, event.y));
          menu.setLocation(point.x, point.y); // waiting for SWT
          // 0.42
          menu.setVisible(true);
          return true; // we don't fire the action
        }
      }
    }

    return false;
  }
 private boolean isTopLevelMenu() {
   if (menu != null && !menu.isDisposed() && menuItem != null && !menuItem.isDisposed()) {
     Menu parentMenu = menuItem.getParent();
     return parentMenu != null && ((parentMenu.getStyle() & SWT.BAR) == SWT.BAR);
   }
   return false;
 }
  /**
   * Determines if the selection was on the dropdown affordance and, if so, opens the drop down menu
   * (populated using the same id as this item...
   *
   * @param event The <code>SWT.Selection</code> event to be tested
   * @return <code>true</code> iff a drop down menu was opened
   */
  private boolean openDropDownMenu(Event event) {
    Widget item = event.widget;
    if (item != null) {
      int style = item.getStyle();
      if ((style & SWT.DROP_DOWN) != 0) {
        if (event.detail == 4) { // on drop-down button
          ToolItem ti = (ToolItem) item;

          final MenuManager menuManager = new MenuManager();
          Menu menu = menuManager.createContextMenu(ti.getParent());
          menuManager.addMenuListener(
              new IMenuListener() {
                public void menuAboutToShow(IMenuManager manager) {
                  String id = getId();
                  if (dropDownMenuOverride != null) {
                    id = dropDownMenuOverride;
                  }
                  menuService.populateContributionManager(menuManager, "menu:" + id); // $NON-NLS-1$
                }
              });
          // position the menu below the drop down item
          Rectangle b = ti.getBounds();
          Point p = ti.getParent().toDisplay(new Point(b.x, b.y + b.height));
          menu.setLocation(p.x, p.y); // waiting for SWT
          // 0.42
          menu.setVisible(true);
          return true; // we don't fire the action
        }
      }
    }

    return false;
  }
 /**
  * Sets the image the receiver will display to the argument.
  *
  * <p>Note: This operation is a hint and is not supported on platforms that do not have this
  * concept (for example, Windows NT). Furthermore, some platforms (such as GTK), cannot display
  * both a check box and an image at the same time. Instead, they hide the image and display the
  * check box.
  *
  * @param image the image to display
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public void setImage(Image image) {
   checkWidget();
   if ((style & SWT.SEPARATOR) != 0) return;
   super.setImage(image);
   if (OS.IsWinCE) {
     if ((OS.IsPPC || OS.IsSP) && parent.hwndCB != 0) {
       long /*int*/ hwndCB = parent.hwndCB;
       TBBUTTONINFO info = new TBBUTTONINFO();
       info.cbSize = TBBUTTONINFO.sizeof;
       info.dwMask = OS.TBIF_IMAGE;
       info.iImage = parent.imageIndex(image);
       OS.SendMessage(hwndCB, OS.TB_SETBUTTONINFO, id, info);
     }
     return;
   }
   if (OS.WIN32_VERSION < OS.VERSION(4, 10)) return;
   MENUITEMINFO info = new MENUITEMINFO();
   info.cbSize = MENUITEMINFO.sizeof;
   info.fMask = OS.MIIM_BITMAP;
   if (parent.foreground != -1) {
     info.hbmpItem = OS.HBMMENU_CALLBACK;
   } else {
     if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(6, 0) && OS.IsAppThemed()) {
       if (hBitmap != 0) OS.DeleteObject(hBitmap);
       info.hbmpItem = hBitmap = image != null ? Display.create32bitDIB(image) : 0;
     } else {
       info.hbmpItem = image != null ? OS.HBMMENU_CALLBACK : 0;
     }
   }
   long /*int*/ hMenu = parent.handle;
   OS.SetMenuItemInfo(hMenu, id, false, info);
   parent.redraw();
 }
  private void handleWidgetSelection(Event e, ToolItem item) {

    boolean selection = item.getSelection();

    int style = item.getStyle();
    IAction action = (IAction) actionMap.get(item);

    if ((style & (SWT.TOGGLE | SWT.CHECK)) != 0) {
      if (action.getStyle() == IAction.AS_CHECK_BOX) {
        action.setChecked(selection);
      }
    } else if ((style & SWT.RADIO) != 0) {
      if (action.getStyle() == IAction.AS_RADIO_BUTTON) {
        action.setChecked(selection);
      }
    } else if ((style & SWT.DROP_DOWN) != 0) {
      if (e.detail == 4) { // on drop-down button
        if (action.getStyle() == IAction.AS_DROP_DOWN_MENU) {
          IMenuCreator mc = action.getMenuCreator();
          ToolItem ti = (ToolItem) item;
          if (mc != null) {
            Menu m = mc.getMenu(ti.getParent());
            if (m != null) {
              Point point = ti.getParent().toDisplay(new Point(e.x, e.y));
              m.setLocation(point.x, point.y); // waiting
              m.setVisible(true);
              return; // we don't fire the action
            }
          }
        }
      }
    }

    action.runWithEvent(e);
  }
  /** {@inheritDoc} */
  public Menu getMenu(final Control parent) {
    if (manager == null) {
      manager = new MenuManager();
    }
    Menu menu = manager.getMenu();
    if (menu != null) {
      menu.dispose();
      menu = null;
    }
    manager.removeAll();
    menu = manager.createContextMenu(parent);
    IAction removeAction =
        new Action(
            "Remove Section Set",
            Activator.imageDescriptorFromPlugin(Activator.ID, "/icons/delete.gif")) {

          /** {@inheritDoc} */
          @Override
          public void run() {
            // remove this section descriptor set state from its parent
            sectionSetDescriptorStates.remove(getSectionSetDescriptorState());
            metamodelViewer.refresh();
          }
        };
    manager.add(removeAction);
    manager.add(new Separator(ADD_GROUP));

    return menu;
  }
Beispiel #9
0
 public void forceHide() {
   hiddenSince = System.currentTimeMillis();
   setState(MenuClosedState.getInstance());
   if (!menu.isDisposed()) {
     menu.setVisible(false);
   }
 }
Beispiel #10
0
 /**
  * Returns <code>true</code> if the receiver is enabled and all of the receiver's ancestors are
  * enabled, and <code>false</code> otherwise. A disabled menu is typically not selectable from the
  * user interface and draws with an inactive or "grayed" look.
  *
  * @return the receiver's enabled state
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  *
  * @see #getEnabled
  */
 public boolean isEnabled() {
   checkWidget();
   Menu parentMenu = getParentMenu();
   if (parentMenu == null) {
     return getEnabled() && parent.isEnabled();
   }
   return getEnabled() && parentMenu.isEnabled();
 }
 /** {@inheritDoc} */
 public void dispose() {
   if (manager != null) {
     Menu menu = manager.getMenu();
     if (menu != null) {
       menu.dispose();
       menu = null;
     }
   }
 }
Beispiel #12
0
  @Test
  public void testModelMenuTextSetBeforeViewerSetContentsEqualsSubMenuStructure() {

    createWazaabiMenu(true);

    org.eclipse.swt.widgets.Menu swtMenu2 =
        (org.eclipse.swt.widgets.Menu) SWTUtils.getWidget(viewer, menuBar);
    Assert.assertEquals(swtMenu2.getItemCount(), menuBar.getChildren().size());
  }
Beispiel #13
0
  @Test
  public void testModelMenuTextSetAfterViewerSetContentsEqualsMenuStructure() {

    createWazaabiMenu(false);

    org.eclipse.swt.widgets.Menu swtMenu =
        (org.eclipse.swt.widgets.Menu) SWTUtils.getWidget(viewer, menuComponent);
    Assert.assertEquals(swtMenu.getItemCount(), menuComponent.getChildren().size());
  }
Beispiel #14
0
  protected void doDropDown() {
    Menu menu = new Menu(getShell(), SWT.POP_UP);
    createDropDownMenu(menu);
    if (menu.getItemCount() == 0) return;

    Point loc = UIUtils.calcPopupMenuLocation(this);
    menu.setLocation(loc);
    menu.setVisible(true);
  }
  public void testExecPidMenu() throws Exception {
    ILaunchConfigurationWorkingCopy config =
        createConfiguration(proj.getProject()).getWorkingCopy();
    config.setAttribute(LaunchConfigurationConstants.ATTR_GENERAL_TRACECHILD, true);
    config.doSave();
    doLaunch(config, "testExec"); // $NON-NLS-1$

    ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
    MassifViewPart dynamicView = (MassifViewPart) view.getDynamicView();
    MassifOutput output = dynamicView.getOutput();

    MassifPidMenuAction menuAction = null;
    IToolBarManager manager = view.getViewSite().getActionBars().getToolBarManager();
    for (IContributionItem item : manager.getItems()) {
      if (item instanceof ActionContributionItem
          && ((ActionContributionItem) item).getAction() instanceof MassifPidMenuAction) {
        menuAction = (MassifPidMenuAction) ((ActionContributionItem) item).getAction();
      }
    }

    assertNotNull(menuAction);

    Integer[] pids = dynamicView.getOutput().getPids();
    Shell shell = new Shell(Display.getCurrent());
    Menu pidMenu = menuAction.getMenu(shell);

    assertEquals(2, pidMenu.getItemCount());
    ActionContributionItem firstPid = (ActionContributionItem) pidMenu.getItem(0).getData();
    ActionContributionItem secondPid = (ActionContributionItem) pidMenu.getItem(1).getData();

    // check initial state
    assertTrue(firstPid.getAction().isChecked());
    assertFalse(secondPid.getAction().isChecked());
    assertEquals(output.getSnapshots(pids[0]), dynamicView.getSnapshots());

    // select second pid
    selectItem(pidMenu, 1);

    assertFalse(firstPid.getAction().isChecked());
    assertTrue(secondPid.getAction().isChecked());
    assertEquals(output.getSnapshots(pids[1]), dynamicView.getSnapshots());

    // select second pid again
    selectItem(pidMenu, 1);

    assertFalse(firstPid.getAction().isChecked());
    assertTrue(secondPid.getAction().isChecked());
    assertEquals(output.getSnapshots(pids[1]), dynamicView.getSnapshots());

    // select first pid
    selectItem(pidMenu, 0);

    assertTrue(firstPid.getAction().isChecked());
    assertFalse(secondPid.getAction().isChecked());
    assertEquals(output.getSnapshots(pids[0]), dynamicView.getSnapshots());
  }
  private void hookColumnChooserMenu(final Table table) {
    // we're hooking up a submenu using straight-up swt (as opposed to contribution items)
    // since this is how it will eventually work in swt post-3.2 when table supports
    // attaching a pop-up menu to the column headers.
    final Menu menu = table.getMenu();

    menu.addListener(
        SWT.Show,
        new Listener() {

          private MenuItem columnsCascadeItem;

          public void handleEvent(Event e) {
            if (menu.getItemCount() > 0
                && menu.getItem(menu.getItemCount() - 1)
                    .equals(columnsCascadeItem)) // this menu already has our additions
            return;

            if (menu.getItemCount() != 0) {
              new MenuItem(menu, SWT.SEPARATOR);
            }

            columnsCascadeItem = new MenuItem(menu, SWT.CASCADE);
            columnsCascadeItem.setText(CHOOSE_COLUMNS_LABEL.getText());
            Menu columnsCascadeMenu = new Menu(table.getShell(), SWT.DROP_DOWN);
            columnsCascadeItem.setMenu(columnsCascadeMenu);

            for (final TableColumn column : table.getColumns()) {
              boolean columnIsInitialZeroWidthColumn =
                  isColumnHidden(column)
                      && (column.getText() == null || column.getText().length() == 0);
              if (!columnIsInitialZeroWidthColumn) {
                MenuItem item = new MenuItem(columnsCascadeMenu, SWT.CHECK);
                item.setText(column.getText());
                item.setEnabled(true);
                item.setSelection(!isColumnHidden(column));

                item.addListener(
                    SWT.Selection,
                    new Listener() {
                      public void handleEvent(Event event) {
                        if (isColumnHidden(column)) showColumn(column);
                        else hideColumn(column);
                      }
                    });
              }
            }

            new MenuItem(columnsCascadeMenu, SWT.SEPARATOR);

            MenuItem moreColumnsItem = new MenuItem(columnsCascadeMenu, SWT.PUSH);
            moreColumnsItem.setText(MORE_COLUMNS_LABEL.getText());
            moreColumnsItem.setEnabled(false);
          }
        });
  }
Beispiel #17
0
  @Override
  public void dispose() {
    super.dispose();
    Workspace.getInstance().uninstallResourceListener(m_listener);

    if (fMenu != null && !fMenu.isDisposed()) {
      fMenu.dispose();
      fMenu = null;
    }
  }
Beispiel #18
0
 public void removeListeners(final ToolItem toolItem, final Menu menu) {
   final Listener[] listeners = menu.getListeners(SWT.Hide);
   for (final Listener listener : listeners) {
     if (listener instanceof TypedListener) {
       final TypedListener typedListener = (TypedListener) listener;
       if (typedListener.getEventListener() instanceof TopMenuListener) {
         menu.removeMenuListener((TopMenuListener) typedListener.getEventListener());
       }
     }
   }
 }
  private void addMenuToSimpleResources() {
    if (null != singleResTreeViewer) {
      final Tree resourceTreeHead = singleResTreeViewer.getTree();
      if (null != resourceTreeHead) {
        // Below code creates menu entries and shows them on right
        // clicking a resource
        final Menu menu = new Menu(resourceTreeHead);
        resourceTreeHead.setMenu(menu);
        menu.addMenuListener(
            new MenuAdapter() {
              @Override
              public void menuShown(MenuEvent e) {
                // Clear existing menu items
                MenuItem[] items = menu.getItems();
                for (int index = 0; index < items.length; index++) {
                  items[index].dispose();
                }

                IStructuredSelection selection =
                    ((IStructuredSelection) singleResTreeViewer.getSelection());
                final SingleResource resource = (SingleResource) selection.getFirstElement();
                if (null == resource) {
                  return;
                }

                addAutomationMenu(menu, resource);

                // Menu to remove the resource.
                MenuItem deleteResource = new MenuItem(menu, SWT.NONE);
                deleteResource.setText("Delete");
                deleteResource.addSelectionListener(
                    new SelectionAdapter() {
                      @Override
                      public void widgetSelected(SelectionEvent e) {
                        try {
                          resourceManager.removeResource(resource);
                          singleResTreeViewer.refresh();

                          resourceManager.resourceSelectionChanged(null);
                        } catch (SimulatorException e1) {
                          MessageDialog.openInformation(
                              Display.getDefault().getActiveShell(),
                              "Deletion Failed",
                              "Failed to delete the resource.");
                        }
                        changeDeleteVisibility();
                      }
                    });
              }
            });
      }
    }
  }
Beispiel #20
0
  public static void setVisiable(ActionContext actionContext) throws OgnlException {
    Thing self = (Thing) actionContext.get("self");

    String method = self.getString("method");
    if (method == null || "".equals(method)) {
      method = "enable";
    }

    String controlList = self.getString("controlList");
    if (controlList == null || "".equals(controlList)) {
      return;
    }

    for (String controlName : controlList.split("[,]")) {
      Object c = Ognl.getValue(controlName, actionContext);
      if (c instanceof Control) {
        final Control control = (Control) c;
        if (control != null) {
          final String m = method;
          control
              .getDisplay()
              .asyncExec(
                  new Runnable() {
                    public void run() {
                      if ("true".equals(m)) {
                        control.setVisible(true);
                      } else if ("false".equals(m)) {
                        control.setVisible(false);
                      } else if ("reverse".equals(m)) {
                        control.setVisible(!control.getEnabled());
                      }
                    }
                  });
        }
      } else if (c instanceof Menu) {
        final Menu item = (Menu) c;
        final String m = method;
        item.getDisplay()
            .asyncExec(
                new Runnable() {
                  public void run() {
                    if ("true".equals(m)) {
                      item.setVisible(true);
                    } else if ("false".equals(m)) {
                      item.setVisible(false);
                    } else if ("reverse".equals(m)) {
                      item.setVisible(!item.getEnabled());
                    }
                  }
                });
      }
    }
  }
 protected void disposeMenuItems() {
   if (fMenu == null || fMenu.isDisposed()) {
     return;
   }
   MenuItem[] items = fMenu.getItems();
   for (int i = 0; i < items.length; i++) {
     MenuItem menuItem = items[i];
     if (!menuItem.isDisposed()) {
       menuItem.dispose();
     }
   }
 }
 private void setupPopupMenu() {
   final Menu menuPopup = new Menu(this.getShell(), SWT.POP_UP);
   final MenuItem itemDelete = new MenuItem(menuPopup, SWT.PUSH);
   itemDelete.setText("删除联系人...");
   menuPopup.addListener(
       SWT.Show,
       new Listener() {
         @Override
         public void handleEvent(Event event) {
           TreeItem[] treeItems = tree.getSelection();
           List<ContactInfo> infoList = new ArrayList<ContactInfo>();
           if (treeItems != null) {
             for (TreeItem treeItem : treeItems) {
               ContactInfo info = (ContactInfo) treeItem.getData();
               if (info != null) {
                 infoList.add(info);
               }
             }
           }
           if (infoList.size() > 0) {
             itemDelete.setEnabled(true);
           } else {
             itemDelete.setEnabled(false);
           }
         }
       });
   itemDelete.addSelectionListener(
       new SelectionAdapter() {
         @Override
         public void widgetSelected(SelectionEvent e) {
           TreeItem[] treeItems = tree.getSelection();
           List<ContactInfo> infoList = new ArrayList<ContactInfo>();
           if (treeItems != null) {
             for (TreeItem treeItem : treeItems) {
               ContactInfo info = (ContactInfo) treeItem.getData();
               if (info != null) {
                 infoList.add(info);
               }
             }
           }
           if (infoList.size() > 0) {
             MessageBox mb = new MessageBox(getShell(), SWT.OK | SWT.CANCEL | SWT.ICON_QUESTION);
             mb.setMessage("确定要删除选择的联系人?");
             mb.setText("提示");
             if (mb.open() == SWT.OK) {
               deleteContact(infoList);
             }
           }
         }
       });
   tree.setMenu(menuPopup);
 }
  public void testBasicContribution() throws Exception {

    IAction a =
        new Action() {
          @Override
          public void run() {
            System.out.println("Hello action");
          }
        };
    final MenuManager manager = new MenuManager();
    final ActionContributionItem item = new ActionContributionItem(a);
    final Expression activeContextExpr =
        new ActiveContextExpression(
            MenuContributionHarness.CONTEXT_TEST1_ID, new String[] {ISources.ACTIVE_CONTEXT_NAME});
    AbstractContributionFactory factory =
        new AbstractContributionFactory(LOCATION, TestPlugin.PLUGIN_ID) {
          @Override
          public void createContributionItems(
              IServiceLocator menuService, IContributionRoot additions) {
            additions.addContributionItem(item, activeContextExpr);
          }
        };

    menuService.addContributionFactory(factory);
    menuService.populateContributionManager(manager, LOCATION);

    Shell shell = window.getShell();

    // Test the initial menu creation
    final Menu menuBar = manager.createContextMenu(shell);
    Event e = new Event();
    e.type = SWT.Show;
    e.widget = menuBar;
    menuBar.notifyListeners(SWT.Show, e);

    assertFalse("starting state", item.isVisible());

    activeContext = contextService.activateContext(MenuContributionHarness.CONTEXT_TEST1_ID);
    menuBar.notifyListeners(SWT.Show, e);

    assertTrue("active context", item.isVisible());

    contextService.deactivateContext(activeContext);
    activeContext = null;
    menuBar.notifyListeners(SWT.Show, e);

    assertFalse("after deactivation", item.isVisible());

    menuService.releaseContributions(manager);
    menuService.removeContributionFactory(factory);
    manager.dispose();
  }
 private static MenuItem show(final Menu menu, final Matcher<?> matcher) {
   if (menu != null) {
     menu.notifyListeners(SWT.Show, new Event());
     MenuItem[] items = menu.getItems();
     for (final MenuItem menuItem : items) {
       if (matcher.matches(menuItem)) {
         return menuItem;
       }
     }
     menu.notifyListeners(SWT.Hide, new Event());
   }
   return null;
 }
  private void attachContextMenu(final Table table) {
    MenuManager menuMgr = new MenuManager("#PopupMenu"); // $NON-NLS-1$
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(manager -> showContextMenu(manager));

    final Menu contextMenu = menuMgr.createContextMenu(table.getShell());
    table.setMenu(contextMenu);

    table.addDisposeListener(
        e -> {
          if (contextMenu != null && !contextMenu.isDisposed()) contextMenu.dispose();
        });
  }
 private void styleMenuItems(final Menu menu) {
   MenuItem[] items = menu.getItems();
   if (items != null && items.length > 0) {
     for (int i = 0; i < items.length; i++) {
       items[i].setData(WidgetUtil.CUSTOM_VARIANT, MENU_BAR_VARIANT);
       Menu subMenu = items[i].getMenu();
       if (subMenu != null) {
         subMenu.setData(WidgetUtil.CUSTOM_VARIANT, MENU_BAR_VARIANT);
         styleMenuItems(subMenu);
       }
     }
   }
 }
Beispiel #27
0
 private static MenuDelegateLCA getDelegateLCA(final Widget widget) {
   MenuDelegateLCA result;
   Menu menu = (Menu) widget;
   int style = menu.getStyle();
   if ((style & SWT.BAR) != 0) {
     result = MENU_BAR_LCA;
   } else if ((style & SWT.DROP_DOWN) != 0) {
     result = DROP_DOWN_MENU_LCA;
   } else {
     result = POPUP_MENU_LCA;
   }
   return result;
 }
Beispiel #28
0
  public static void displayMenu(Menu menu, Control control) {
    Menu oldMenu = control.getMenu();
    if (oldMenu != null && oldMenu != menu) {
      oldMenu.setVisible(false);
    }

    // XXX: Stubbing out this line prevents context dialogs from appearing twice
    // on OS X.  Tested on Windows to be sure there is no adverse effect.
    // Unfortunately, I do *not* understand why this works.  I ran it by
    // mcasters and he didn't know for sure either.
    // control.setMenu(menu);
    menu.setVisible(true);
  }
 public Menu getMenu(Menu parent) {
   final Menu menu = new Menu(parent);
   menu.addMenuListener(
       new MenuAdapter() {
         @Override
         public void menuShown(MenuEvent e) {
           for (MenuItem item : menu.getItems()) {
             item.dispose();
           }
           addActions(menu);
         }
       });
   return menu;
 }
    @Override
    public boolean run(final IStructuredSelection selection) {
      if (fMenuManager == null) {
        fMenuManager = new MenuManager();
      } else {
        fMenuManager.removeAll();
      }
      fillMenu(fMenuManager);

      final Menu menu = fMenuManager.createContextMenu(getControl());
      MenuUtil.setPullDownPosition(menu, getControl());
      menu.setVisible(true);
      return false;
    }