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;
 }
Beispiel #2
0
 public void forceHide() {
   hiddenSince = System.currentTimeMillis();
   setState(MenuClosedState.getInstance());
   if (!menu.isDisposed()) {
     menu.setVisible(false);
   }
 }
  private void showStandaloneViewMenu(
      ExecutionEvent event, MPart model, MMenu menuModel, Composite partContainer) {
    Shell shell = partContainer.getShell();
    Menu menu = (Menu) menuModel.getWidget();
    if (menu == null) {
      IPresentationEngine engine =
          (IPresentationEngine) HandlerUtil.getVariable(event, IPresentationEngine.class.getName());
      menu = (Menu) engine.createGui(menuModel, shell, model.getContext());
      if (menu != null) {
        final Menu tmpMenu = menu;
        partContainer.addDisposeListener(
            new DisposeListener() {
              public void widgetDisposed(DisposeEvent e) {
                tmpMenu.dispose();
              }
            });
      }
    }

    Display display = menu.getDisplay();
    Point location = display.map(partContainer, null, partContainer.getLocation());
    Point size = partContainer.getSize();
    menu.setLocation(location.x + size.x, location.y);
    menu.setVisible(true);

    while (!menu.isDisposed() && menu.isVisible()) {
      if (!display.readAndDispatch()) display.sleep();
    }

    if (!(menu.getData() instanceof MenuManager)) {
      menu.dispose();
    }
  }
  @Override
  public void dispose() {
    super.dispose();
    Workspace.getInstance().uninstallResourceListener(m_listener);

    if (fMenu != null && !fMenu.isDisposed()) {
      fMenu.dispose();
      fMenu = null;
    }
  }
  /** {@inheritDoc} */
  public void run() {
    Display display = Display.getCurrent();
    if (display == null) return;
    Control focus = display.getFocusControl();
    if (focus == null || focus.isDisposed()) return;

    MenuManager menu = new MenuManager();
    fillMenu(menu);
    final Menu widget = menu.createContextMenu(focus.getShell());
    Point location = computeMenuLocation(focus, widget);
    if (location == null) return;
    widget.setLocation(location);
    widget.setVisible(true);
    while (!widget.isDisposed() && widget.isVisible()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    if (!widget.isDisposed()) {
      widget.dispose();
    }
  }
 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 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 disposeToolItems() {
   for (int i = 0; i < toolItemList.size(); i++) {
     ToolItem item = (ToolItem) toolItemList.get(i);
     if (!item.isDisposed()) {
       Object data = item.getData();
       if (data != null && data instanceof Menu) {
         Menu menu = (Menu) data;
         if (!menu.isDisposed()) {
           menu.dispose();
         }
       }
       item.dispose();
     }
   }
 }
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.jface.action.IMenuCreator#dispose()
  */
 public void dispose() {
   if (dropDownMenuMgr != null) {
     dropDownMenuMgr.dispose();
     dropDownMenuMgr = null;
   }
   if (menus.size() > 0) {
     for (Iterator i = menus.iterator(); i.hasNext(); ) {
       Menu m = (Menu) i.next();
       if (!m.isDisposed()) {
         m.dispose();
       }
     }
     menus.clear();
   }
 }
  /* (non-Javadoc)
   * @see org.eclipse.jface.action.IContributionItem#update(java.lang.String)
   */
  public void update(String property) {
    IContributionItem items[] = getItems();

    for (int i = 0; i < items.length; i++) {
      items[i].update(property);
    }

    if (menu != null && !menu.isDisposed() && menu.getParentItem() != null) {
      if (IAction.TEXT.equals(property)) {
        String text = getOverrides().getText(this);

        if (text == null) {
          text = getMenuText();
        }

        if (text != null) {
          ExternalActionManager.ICallback callback =
              ExternalActionManager.getInstance().getCallback();

          if (callback != null) {
            int index = text.indexOf('&');

            if (index >= 0 && index < text.length() - 1) {
              char character = Character.toUpperCase(text.charAt(index + 1));

              if (callback.isAcceleratorInUse(SWT.ALT | character) && isTopLevelMenu()) {
                if (index == 0) {
                  text = text.substring(1);
                } else {
                  text = text.substring(0, index) + text.substring(index + 1);
                }
              }
            }
          }

          menu.getParentItem().setText(text);
        }
      } else if (IAction.IMAGE.equals(property) && image != null) {
        LocalResourceManager localManager = new LocalResourceManager(JFaceResources.getResources());
        menu.getParentItem().setImage(localManager.createImage(image));
        disposeOldImages();
        imageManager = localManager;
      }
    }
  }
  /**
   * Sets the receiver's pull down menu to the argument. Only <code>CASCADE</code> menu items can
   * have a pull down menu. The sequence of key strokes, button presses and/or button releases that
   * are used to request a pull down menu is platform specific.
   *
   * <p>Note: Disposing of a menu item that has a pull down menu will dispose of the menu. To avoid
   * this behavior, set the menu to null before the menu item is disposed.
   *
   * @param menu the new pull down menu
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_MENU_NOT_DROP_DOWN - if the menu is not a drop down menu
   *       <li>ERROR_MENUITEM_NOT_CASCADE - if the menu item is not a <code>CASCADE</code>
   *       <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed
   *       <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree
   *     </ul>
   *
   * @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 setMenu(Menu menu) {
    checkWidget();

    /* Check to make sure the new menu is valid */
    if ((style & SWT.CASCADE) == 0) {
      error(SWT.ERROR_MENUITEM_NOT_CASCADE);
    }
    if (menu != null) {
      if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
      if ((menu.style & SWT.DROP_DOWN) == 0) {
        error(SWT.ERROR_MENU_NOT_DROP_DOWN);
      }
      if (menu.parent != parent.parent) {
        error(SWT.ERROR_INVALID_PARENT);
      }
    }
    setMenu(menu, false);
  }
  /** Populate the dynamic menu */
  protected void fillMenu(Menu parent, List<Concern> concerns) {
    assert parent != null;
    assert !parent.isDisposed();

    //	if (!selectedJavaElements.isEmpty())
    // {
    parent.setEnabled(true);

    fillMenuRecursive(parent, concerns, selectedJavaElements, concernModelProvider.getLinkType());

    String linkAllLabel = getNewConcernMenuItemText();

    for (MenuItem menuItem : parent.getItems()) {
      String text = menuItem.getText();

      if (text.isEmpty()) {
        menuItem.dispose();
      } else if (text.equals(linkAllLabel)) {
        menuItem.dispose();
        break;
      }
    }

    // If there were concerns in the model, add a separator before
    // the New Concern item

    boolean hasItemsToLink = parent.getItemCount() > 0;

    /*if (hasItemsToLink)
    {
    	new MenuItem(parent, SWT.SEPARATOR);
    }*/

    // Add the "New concern..." item
    /*MenuItem lNewConcernItem = new MenuItem(parent, SWT.PUSH);
    lNewConcernItem.addSelectionListener(clickListener);
    lNewConcernItem.setText(linkAllLabel);*/
    /*	}
    else
    {
    	parent.setEnabled(false);
    }*/
  }
  /**
   * Create the popoup menu about all the exporters. If the menu is already build this method do
   * nothing.
   */
  private void createPopupMenu() {

    if (popupMenu != null && !popupMenu.isDisposed()) popupMenu.dispose();

    manager = new MenuManager();
    ActionRegistry registry = new ActionRegistry();
    // Create the PDF decorator
    PDF508ElementDecorator pdfDecorator = new PDF508ElementDecorator();
    IWorkbenchPart activePart = getWorkbenchPart();
    pdfDecorator.registerActions(registry, new ArrayList<String>(), activePart);
    pdfDecorator.fillContextMenu(registry, manager);
    // Create the XLS decorator
    XLSElementDecorator xlsDecorator = new XLSElementDecorator();
    xlsDecorator.registerActions(registry, new ArrayList<String>(), activePart);
    xlsDecorator.fillContextMenu(registry, manager);
    // Create the CSV action
    CSVElementDecorator csvDecorator = new CSVElementDecorator();
    csvDecorator.registerActions(registry, new ArrayList<String>(), activePart);
    ISelection actualSelection = getLastRawSelection();
    csvDecorator.fillContextMenu(registry, manager, (IStructuredSelection) actualSelection);
    popupMenu = new Menu(Display.getCurrent().getActiveShell());
    createMenu(popupMenu, manager.getItems());
  }
  @Override
  public void dispose() {
    if (composite != null && !composite.isDisposed()) {
      composite.dispose();
    }
    composite = null;

    if (menuManager != null) {
      menuManager.removeAll();
      menuManager.dispose();
    }
    menuManager = null;

    if (menu != null && !menu.isDisposed()) {
      menu.dispose();
    }
    menu = null;

    actionGroup.setSelectionProvider(null);

    TasksUi.getTaskActivityManager().removeActivationListener(taskActivationListener);
    TasksUiPlugin.getTaskList().removeChangeListener(taskListListener);
  }
Beispiel #15
0
 private void createContextMenu(MouseEvent me) throws TermInstantiationException {
   System.out.println("Right button click");
   Display display = context.getCanvas().getDisplay();
   Menu menu = new Menu(context.getCanvas().getShell(), SWT.POP_UP);
   try {
     Variable varAction = new Variable("Action");
     Iterator<Map<Variable, Object>> results =
         PrologProxy.instance()
             .getSolutions(Compound.createCompound("cpi#contextMenuEntry", descriptor, varAction));
     int count = 0;
     while (results.hasNext()) {
       Map<Variable, Object> result = (Map<Variable, Object>) results.next();
       Compound action = (Compound) result.get(varAction);
       TermInstantiator.instance().instantiate(action, menu, context);
       if (count++ > MAX_MENU_ENTRIES) {
         MenuItem errItem = new MenuItem(menu, SWT.NONE);
         errItem.setText("<too many results>");
         break;
       }
     }
   } catch (PrologException e1) {
     e1.printStackTrace();
   }
   Point absLocation = me.getLocation().getCopy();
   translateToAbsolute(absLocation);
   org.eclipse.swt.graphics.Point point =
       display.map(
           context.getCanvas(),
           null,
           new org.eclipse.swt.graphics.Point(absLocation.x, absLocation.y));
   menu.setLocation(point);
   menu.setVisible(true);
   while (!menu.isDisposed() && menu.isVisible()) {
     if (!display.readAndDispatch()) display.sleep();
   }
 }
 public void dispose() {
   if (menu != null && !menu.isDisposed()) {
     menu.dispose();
     menu = null;
   }
 }
 /**
  * Returns whether the menu control is created and not disposed.
  *
  * @return <code>true</code> if the control is created and not disposed, <code>false</code>
  *     otherwise
  * @since 3.4 protected, was added in 3.1 as private method
  */
 protected boolean menuExist() {
   return menu != null && !menu.isDisposed();
 }