Beispiel #1
0
  /** @see ContributionItem#fill(Menu, int) */
  @Override
  public void fill(final Menu menu, int index) {
    RecentProjectsService rfs =
        (RecentProjectsService) PlatformUI.getWorkbench().getService(RecentProjectsService.class);
    RecentProjectsService.Entry[] entries = rfs.getRecentFiles();
    if (entries == null || entries.length == 0) {
      return;
    }

    // add separator
    new MenuItem(menu, SWT.SEPARATOR, index);

    int i = entries.length;
    for (RecentProjectsService.Entry entry : entries) {
      String file = entry.getFile();
      MenuItem mi = new MenuItem(menu, SWT.PUSH, index);
      String filename = FilenameUtils.getName(file);
      String shortened = shorten(file, MAX_LENGTH, filename.length());
      String nr = String.valueOf(i);
      if (i <= 9) {
        // add mnemonic for the first 9 items
        nr = "&" + nr; // $NON-NLS-1$
      }
      mi.setText(nr + "  " + shortened); // $NON-NLS-1$
      mi.setData(file);
      mi.addSelectionListener(new MenuItemSelectionListener(new File(file)));
      --i;
    }
  }
  @Override
  public void fill(final Menu parent, final int index) {
    if (this.widget != null || parent == null) {
      return;
    }

    // Menus don't support the pulldown style
    int tmpStyle = this.style;
    if (tmpStyle == STYLE_PULLDOWN) {
      tmpStyle = STYLE_PUSH;
    }

    MenuItem item = null;
    if (index >= 0) {
      item = new MenuItem(parent, tmpStyle, index);
    } else {
      item = new MenuItem(parent, tmpStyle);
    }
    item.setData(this);
    if (this.workbenchHelpSystem != null) {
      this.workbenchHelpSystem.setHelp(item, this.helpContextId);
    }
    item.addListener(SWT.Dispose, getItemListener());
    item.addListener(SWT.Selection, getItemListener());
    this.widget = item;

    update(null);
    updateIcons();
  }
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.jface.action.ContributionItem#fill(org.eclipse.swt.widgets.Menu,
   *      int)
   */
  public void fill(Menu parent, int index) {
    if (command == null) {
      return;
    }
    if (widget != null || parent == null) {
      return;
    }

    // Menus don't support the pulldown style
    int tmpStyle = style;
    if (tmpStyle == STYLE_PULLDOWN) tmpStyle = STYLE_PUSH;

    MenuItem item = null;
    if (index >= 0) {
      item = new MenuItem(parent, tmpStyle, index);
    } else {
      item = new MenuItem(parent, tmpStyle);
    }
    item.setData(this);

    item.addListener(SWT.Dispose, getItemListener());
    item.addListener(SWT.Selection, getItemListener());
    widget = item;

    update(null);
  }
    @Override
    protected void fillMenu(final Menu menu) {
      final TexUIResources texResources = TexUIResources.INSTANCE;
      final List<TexCommand> commands = fCategory.getCommands();
      for (final TexCommand command : commands) {
        final MenuItem item = new MenuItem(menu, SWT.PUSH);

        final String imageKey = texResources.getCommandImageId(command);
        if (imageKey != null) {
          item.setImage(texResources.getImage(imageKey));
        }
        item.setText(command.getControlWord());
        item.setData(command);

        item.addSelectionListener(this);
      }
    }
  public void addOperationFilter(final Filter filter) {
    MenuItem[] items = filtersMenu.getItems();
    int pos = 0;
    for (MenuItem item : items) {
      if (item == configureItem) {
        break;
      }
      pos++;
    }
    pos--;
    operationFilters.add(filter);

    final MenuItem item = new MenuItem(filtersMenu, SWT.CHECK, pos);
    item.setText(filter.getName());
    item.setSelection(filter.getEnabled());
    item.setData(filter);
    item.addSelectionListener(this);
  }
Beispiel #6
0
  /**
   * Add an item to the recently opened list in the simulation menu.
   *
   * @param parent the parent menu
   */
  private void addRecent(final Menu parent) {
    String[] recent = siafuConfig.getStringArray("ui.recentsimulation");
    if (recent != null && recent.length != 0) {
      new MenuItem(parent, SWT.SEPARATOR);

      for (int i = 0; i < recent.length; i++) {
        MenuItem m = new MenuItem(parent, SWT.PUSH);
        String name = recent[i].substring(recent[i].lastIndexOf(File.separator) + 1);
        int length = recent[i].length();
        if (length > MAXIMUM_RECENT_ENTRY_LENGTH) {
          length = MAXIMUM_RECENT_ENTRY_LENGTH;
        }
        String path = "[" + recent[i].substring(0, length) + "]";
        m.setText("&" + (i + 1) + " " + name + " " + path);
        m.setData(recent[i]);
        m.addSelectionListener(
            new SelectionAdapter() {
              public void widgetSelected(final SelectionEvent e) {
                openSimulation((String) e.widget.getData());
              }
            });
      }
    }
  }
  /** Builds the cascading 'Link' menu */
  private void fillMenuRecursive(
      Menu parent,
      List<Concern> concerns,
      List<IJavaElement> selectedJavaElements,
      EdgeKind concernComponentRelation) {
    Set<Character> mnemonicsUsed = new HashSet<Character>();

    for (Concern concern : concerns) {
      // See if any of the selected elements are already
      // linked to the concern
      getSelectedJavaElements(
          aJavaEditor, FLATTT.tableView.getViewer().getSelection(), selectedJavaElements);
      boolean isLinked = isLinked(concern, selectedJavaElements, concernComponentRelation);

      // For the 'Unlink' menu, only show linked concerns

      if (isLinked) {
        MenuItem lMenuItem = new MenuItem(parent, SWT.PUSH);
        lMenuItem.setData(concern);
        lMenuItem.setText(getConcernNameWithMnemonic(concern, mnemonicsUsed));
        lMenuItem.addSelectionListener(clickListener);
      }

      List<Concern> children = concern.getChildren();

      if (!children.isEmpty()) {
        // The 'Unlink' menu is flat, so we pass in the same
        // parent menu

        fillMenuRecursive(parent, children, selectedJavaElements, concernComponentRelation);
      }

      children = null; // Helps GC
      /*
      List<Concern> children = concern.getChildren();

      MenuItem lMenuItem = null;
      Menu childMenu = null;

      // For the 'Link' menu, create menu items for all concerns,
      // regardless of whether they are linked.

      // See if we already created the item
      for(MenuItem menuItem : parent.getItems())
      {
      	Object data = menuItem.getData();
      	if (data != null &&
      		data.equals(concern))
      	{
      		lMenuItem = menuItem;
      		childMenu = lMenuItem.getMenu();
      		break;
      	}
      }

      // Lazily create the concern menu item
      if (lMenuItem == null)
      {
      	if (!children.isEmpty())
      	{
      		lMenuItem = new MenuItem(parent, SWT.CASCADE);
      	}
      	else
      	{
      		lMenuItem = new MenuItem(parent, SWT.PUSH);

      		// Can't click on cascading menu
      		lMenuItem.addSelectionListener(clickListener);
      	}

      	lMenuItem.setData(concern);
      	lMenuItem.setText(getConcernNameWithMnemonic(concern, mnemonicsUsed));
      }

      lMenuItem.setEnabled(!children.isEmpty() || isLinked);

      if (!children.isEmpty())
      {
      	// The 'Link' menu is hierarchical, so we create
      	// a cascading menu for the children

      	assert lMenuItem != null;

      	if (childMenu == null)
      	{
      		childMenu = new Menu(lMenuItem);
      	}

      	fillMenuRecursive(childMenu, children, selectedJavaElements,
      			concernComponentRelation);

      	lMenuItem.setMenu(childMenu);
      }

      children = null; // Helps GC*/
    }

    mnemonicsUsed = null; // Helps GC
  }