Esempio n. 1
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);
  }
Esempio n. 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();
    }
  }
Esempio n. 4
0
  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);
  }
  /**
   * 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;
  }
  /**
   * 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;
  }
Esempio n. 7
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);
  }
Esempio n. 8
0
  public void showHideShowColumnsMenu(Shell shell) {
    if (contextMenu == null) {
      MenuManager menuMgr = new MenuManager("#PopupMenu"); // $NON-NLS-1$
      menuMgr.setRemoveAllWhenShown(true);
      menuMgr.addMenuListener(this);

      contextMenu = menuMgr.createContextMenu(shell);
    }

    contextMenu.setVisible(true);
  }
    @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;
    }
Esempio n. 10
0
  /** {@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();
    }
  }
  private void showMenu() {
    Menu menu = new Menu(getShell(), POP_UP);
    addMenuItem(menu, TransformComponent.class);
    addSeparator(menu);
    addMenuItem(menu, BulletRigidBodyComponent.class);
    addSeparator(menu);
    addMenuItem(menu, OrtographicCameraComponent.class);
    addMenuItem(menu, PerspectiveCameraComponent.class);
    addSeparator(menu);
    addMenuItem(menu, DirectionalLightComponent.class);
    addMenuItem(menu, PointLightComponent.class);
    addMenuItem(menu, SpotLightComponent.class);
    addSeparator(menu);
    addMenuItem(menu, AudioListenerComponent.class);
    addMenuItem(menu, AudioSourceComponent.class);
    addSeparator(menu);
    addMenuItem(menu, TagComponent.class);
    addSeparator(menu);
    addMenuItem(menu, TextureComponent.class);
    addMenuItem(menu, TextureRegionComponent.class);
    addMenuItem(menu, AtlasRegionComponent.class);
    addMenuItem(menu, SkyboxComponent.class);
    addSeparator(menu);
    addMenuItem(menu, ModelComponent.class);
    addMenuItem(menu, ShapeComponent.class);
    addSeparator(menu);
    addMenuItem(menu, TestPropertyEditorsComponent.class);
    addMenuItem(menu, TestEditorComponent.class);
    addMenuItem(menu, TestInputComponent.class);
    addMenuItem(menu, TestTypeSelectionComponnent.class);
    addMenuItem(menu, TestArrayEditorComponent.class);
    addSeparator(menu);
    addScriptMenuItem(menu);

    Point buttonLocation = menuButton.getLocation();
    Rectangle rect = menuButton.getBounds();
    Point menuLocation = new Point(buttonLocation.x - 1, buttonLocation.y + rect.height);

    menu.setLocation(getDisplay().map(menuButton.getParent(), null, menuLocation));
    menu.setVisible(true);
  }
Esempio n. 12
0
  public void runWithEvent(Event e) {
    if (selectedAction == null) {

      final Control parent =
          e.widget != null && e.widget instanceof ToolItem
              ? ((ToolItem) e.widget).getParent()
              : null;
      Menu m = getMenu(parent);
      if (m != null) {
        // position the menu below the drop down item
        Point point = parent.toDisplay(new Point(e.x, e.y));
        m.setLocation(point.x, point.y); // waiting
        // for SWT
        // 0.42
        m.setVisible(true); // for SWT
      }

    } else {
      run();
    }
  }
  private void openMenuFor(ToolItem item, MPerspective persp) {
    final Menu menu = new Menu(psTB);
    menu.setData(persp);
    if (persp.getParent().getSelectedElement() == persp) {
      addSaveAsItem(menu);
      addResetItem(menu);
    }

    if (persp.isVisible()) {
      addCloseItem(menu);
    }

    new MenuItem(menu, SWT.SEPARATOR);
    // addDockOnSubMenu(menu);
    addShowTextItem(menu);

    Rectangle bounds = item.getBounds();
    Point point = psTB.toDisplay(bounds.x, bounds.y + bounds.height);
    menu.setLocation(point.x, point.y);
    menu.setVisible(true);
    menu.addMenuListener(
        new MenuListener() {

          public void menuHidden(MenuEvent e) {
            psTB.getDisplay()
                .asyncExec(
                    new Runnable() {

                      public void run() {
                        menu.dispose();
                      }
                    });
          }

          public void menuShown(MenuEvent e) {
            // Nothing to do
          }
        });
  }
Esempio n. 14
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();
   }
 }
  static void show(final ConfigurationChooser chooser, ToolItem combo) {
    Configuration configuration = chooser.getConfiguration();
    Device current = configuration.getDevice();
    Menu menu = new Menu(chooser.getShell(), SWT.POP_UP);

    List<Device> deviceList = chooser.getDeviceList();
    Sdk sdk = Sdk.getCurrent();
    if (sdk != null) {
      AvdManager avdManager = sdk.getAvdManager();
      if (avdManager != null) {
        boolean separatorNeeded = false;
        AvdInfo[] avds = avdManager.getValidAvds();
        for (AvdInfo avd : avds) {
          for (Device device : deviceList) {
            if (device.getManufacturer().equals(avd.getDeviceManufacturer())
                && device.getName().equals(avd.getDeviceName())) {
              separatorNeeded = true;
              MenuItem item = new MenuItem(menu, SWT.CHECK);
              item.setText(avd.getName());
              item.setSelection(current == device);

              item.addSelectionListener(new DeviceMenuListener(chooser, device));
            }
          }
        }

        if (separatorNeeded) {
          @SuppressWarnings("unused")
          MenuItem separator = new MenuItem(menu, SWT.SEPARATOR);
        }
      }
    }

    // Group the devices by manufacturer, then put them in the menu.
    // If we don't have anything but Nexus devices, group them together rather than
    // make many manufacturer submenus.
    boolean haveNexus = false;
    boolean haveNonNexus = false;
    if (!deviceList.isEmpty()) {
      Map<String, List<Device>> manufacturers = new TreeMap<String, List<Device>>();
      for (Device device : deviceList) {
        List<Device> devices;
        if (isNexus(device)) {
          haveNexus = true;
        } else if (!isGeneric(device)) {
          haveNonNexus = true;
        }
        if (manufacturers.containsKey(device.getManufacturer())) {
          devices = manufacturers.get(device.getManufacturer());
        } else {
          devices = new ArrayList<Device>();
          manufacturers.put(device.getManufacturer(), devices);
        }
        devices.add(device);
      }
      if (haveNonNexus) {
        for (List<Device> devices : manufacturers.values()) {
          Menu manufacturerMenu = menu;
          if (manufacturers.size() > 1) {
            MenuItem item = new MenuItem(menu, SWT.CASCADE);
            item.setText(devices.get(0).getManufacturer());
            manufacturerMenu = new Menu(menu);
            item.setMenu(manufacturerMenu);
          }
          for (final Device device : devices) {
            MenuItem deviceItem = new MenuItem(manufacturerMenu, SWT.CHECK);
            deviceItem.setText(getGenericLabel(device));
            deviceItem.setSelection(current == device);
            deviceItem.addSelectionListener(new DeviceMenuListener(chooser, device));
          }
        }
      } else {
        List<Device> nexus = new ArrayList<Device>();
        List<Device> generic = new ArrayList<Device>();
        if (haveNexus) {
          // Nexus
          for (List<Device> devices : manufacturers.values()) {
            for (Device device : devices) {
              if (isNexus(device)) {
                if (device.getManufacturer().equals(GENERIC)) {
                  generic.add(device);
                } else {
                  nexus.add(device);
                }
              } else {
                generic.add(device);
              }
            }
          }
        }

        if (!nexus.isEmpty()) {
          sortNexusList(nexus);
          for (final Device device : nexus) {
            MenuItem item = new MenuItem(menu, SWT.CHECK);
            item.setText(getNexusLabel(device));
            item.setSelection(current == device);
            item.addSelectionListener(new DeviceMenuListener(chooser, device));
          }

          @SuppressWarnings("unused")
          MenuItem separator = new MenuItem(menu, SWT.SEPARATOR);
        }

        // Generate the generic menu.
        Collections.reverse(generic);
        for (final Device device : generic) {
          MenuItem item = new MenuItem(menu, SWT.CHECK);
          item.setText(getGenericLabel(device));
          item.setSelection(current == device);
          item.addSelectionListener(new DeviceMenuListener(chooser, device));
        }
      }
    }

    @SuppressWarnings("unused")
    MenuItem separator = new MenuItem(menu, SWT.SEPARATOR);

    ConfigurationMenuListener.addTogglePreviewModeAction(
        menu, "Preview All Screens", chooser, RenderPreviewMode.SCREENS);

    Rectangle bounds = combo.getBounds();
    Point location = new Point(bounds.x, bounds.y + bounds.height);
    location = combo.getParent().toDisplay(location);
    menu.setLocation(location.x, location.y);
    menu.setVisible(true);
  }
Esempio n. 16
0
 public void showBigButtonMenu() {
   Rectangle bBounds = mTabFolder.getBigButtonBounds();
   mBigButtonMenu.setLocation(mShell.toDisplay(bBounds.x, bBounds.height + bBounds.y));
   mBigButtonMenu.setVisible(true);
 }
 /**
  * @param part
  * @param point
  */
 protected void showPaneMenu(IPresentablePart part, Point point) {
   systemMenuManager.update(false);
   Menu aMenu = systemMenuManager.createContextMenu(tabFolder.getParent());
   aMenu.setLocation(point.x, point.y);
   aMenu.setVisible(true);
 }
Esempio n. 18
0
 public void showMenu(final int x, final int y) {
   hiddenSince = 0L;
   menu.setLocation(x, y);
   menu.setVisible(true);
 }