コード例 #1
0
  private void addRadio(RuleAction.Choices choices) {
    List<URL> icons = choices.getIconUrls();
    List<String> titles = choices.getTitles();
    List<String> ids = choices.getIds();
    String current = choices.getCurrent() != null ? choices.getCurrent() : ""; // $NON-NLS-1$

    assert icons != null;
    assert icons.size() == titles.size();

    for (int i = 0; i < icons.size(); i++) {
      URL iconUrl = icons.get(i);
      String title = titles.get(i);
      final String id = ids.get(i);
      final ToolItem item = new ToolItem(mLayoutToolBar, SWT.RADIO);
      item.setToolTipText(title);
      item.setImage(IconFactory.getInstance().getIcon(iconUrl));
      item.setData(choices);
      item.setData(ATTR_ID, id);
      item.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              if (item.getSelection()) {
                RuleAction.Choices choices = (Choices) item.getData();
                choices.getCallback().action(choices, getSelectedNodes(), id, null);
                updateSelection();
              }
            }
          });
      boolean selected = current.equals(id);
      if (selected) {
        item.setSelection(true);
      }
    }
  }
コード例 #2
0
  private void addDropdown(RuleAction.Choices choices) {
    final ToolItem combo = new ToolItem(mLayoutToolBar, SWT.DROP_DOWN);
    URL iconUrl = choices.getIconUrl();
    if (iconUrl != null) {
      combo.setImage(IconFactory.getInstance().getIcon(iconUrl));
      combo.setToolTipText(choices.getTitle());
    } else {
      combo.setText(choices.getTitle());
    }
    combo.setData(choices);

    Listener menuListener =
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            Menu menu = new Menu(mLayoutToolBar.getShell(), SWT.POP_UP);
            RuleAction.Choices choices = (Choices) combo.getData();
            List<URL> icons = choices.getIconUrls();
            List<String> titles = choices.getTitles();
            List<String> ids = choices.getIds();
            String current =
                choices.getCurrent() != null ? choices.getCurrent() : ""; // $NON-NLS-1$

            for (int i = 0; i < titles.size(); i++) {
              String title = titles.get(i);
              final String id = ids.get(i);
              URL itemIconUrl = icons != null && icons.size() > 0 ? icons.get(i) : null;
              MenuItem item = new MenuItem(menu, SWT.CHECK);
              item.setText(title);
              if (itemIconUrl != null) {
                Image itemIcon = IconFactory.getInstance().getIcon(itemIconUrl);
                item.setImage(itemIcon);
              }

              boolean selected = id.equals(current);
              if (selected) {
                item.setSelection(true);
              }

              item.addSelectionListener(
                  new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                      RuleAction.Choices choices = (Choices) combo.getData();
                      choices.getCallback().action(choices, getSelectedNodes(), id, null);
                      updateSelection();
                    }
                  });
            }

            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);
          }
        };
    combo.addListener(SWT.Selection, menuListener);
  }
コード例 #3
0
  private void addActions(List<RuleAction> actions, int labelIndex, String label) {
    if (actions.size() > 0) {
      // Flag used to indicate that if there are any actions -after- this, it
      // should be separated from this current action (we don't unconditionally
      // add a separator at the end of these groups in case there are no more
      // actions at the end so that we don't have a trailing separator)
      boolean needSeparator = false;

      int index = 0;
      for (RuleAction action : actions) {
        if (index == labelIndex) {
          final ToolItem button = new ToolItem(mLayoutToolBar, SWT.PUSH);
          button.setText(label);
          needSeparator = false;
        }
        index++;

        if (action instanceof Separator) {
          addSeparator(mLayoutToolBar);
          needSeparator = false;
          continue;
        } else if (needSeparator) {
          addSeparator(mLayoutToolBar);
          needSeparator = false;
        }

        if (action instanceof RuleAction.Choices) {
          RuleAction.Choices choices = (Choices) action;
          if (!choices.isRadio()) {
            addDropdown(choices);
          } else {
            addSeparator(mLayoutToolBar);
            addRadio(choices);
            needSeparator = true;
          }
        } else if (action instanceof RuleAction.Toggle) {
          addToggle((Toggle) action);
        } else {
          addPlainAction(action);
        }
      }
    }
  }