コード例 #1
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);
  }
コード例 #2
0
  /**
   * 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;
  }
コード例 #3
0
  /**
   * 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;
  }
コード例 #4
0
 static long /*int*/ MenuItemSelectedProc(long /*int*/ widget, long /*int*/ user_data) {
   Display display = Display.getCurrent();
   ToolItem item = (ToolItem) display.getWidget(user_data);
   if (item != null) {
     return item.getParent().menuItemSelected(widget, item);
   }
   return 0;
 }
コード例 #5
0
 @Override
 public Node getParentNode() {
   ToolItem item = getToolItem();
   ToolBar parent = item.getParent();
   if (parent != null) {
     Element element = getElement(parent);
     return element;
   }
   return null;
 }
コード例 #6
0
  @Override
  public void addItem(int id, ToolItem item) {
    if (item.getParent() != myToolBar) {
      LogUtils.error(this, "Item does nopt have the correct toolbar as parent. Disposed.");
      item.dispose();
      return;
    }
    if (myItems.containsKey(id)) {
      LogUtils.error(this, "item ID " + id + " already used. Item Disposed.");
      item.dispose();
      return;
    }

    myItems.put(id, item);
  }
コード例 #7
0
 public void widgetSelected(SelectionEvent event) {
   if (event.detail == SWT.ARROW && this.subMenuItems != null && this.subMenuItems.length > 0) {
     ToolItem item = (ToolItem) event.widget;
     Rectangle rect = item.getBounds();
     Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y));
     this.menu.setLocation(pt.x, pt.y + rect.height);
     this.menu.setVisible(true);
   } else {
     TGSynchronizer.instance()
         .executeLater(
             new TGSynchronizer.TGRunnable() {
               public void run() throws TGException {
                 TGActionManager.getInstance().execute(InsertChordAction.NAME);
               }
             });
   }
 }
コード例 #8
0
  private void track(MouseEvent e) {
    // Create and track the feedback overlay
    if (dragShell == null) createFeedback();

    // Move the drag shell
    Rectangle b = dragItem.getBounds();
    Point p = new Point(e.x, e.y);
    p = dragShell.getDisplay().map(dragItem.getParent(), null, p);
    dragShell.setLocation(p.x - (b.width / 2), p.y - (b.height / 2));

    // Set the cursor feedback
    ToolBar bar = (ToolBar) e.widget;
    ToolItem curItem = bar.getItem(new Point(e.x, e.y));
    if (curItem != null && curItem.getData() instanceof MPerspective) {
      psTB.setCursor(psTB.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    } else {
      psTB.setCursor(psTB.getDisplay().getSystemCursor(SWT.CURSOR_NO));
    }
  }
コード例 #9
0
  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);
  }