Java 类org.eclipse.jface.action.ContributionItem 实例源码

项目:gerrit-tools    文件:QuickGpsImportCommandsProvider.java   
@Override
protected IContributionItem[] getContributionItems() {
    File[] files = GpsQuickImportFiles.getGpsFiles();
    if (files.length == 0) {
        return new IContributionItem[] {
                new ContributionItem() {
                    @Override
                    public void fill(Menu menu, int index) {
                        MenuItem item = new MenuItem(menu, 0);
                        item.setText("No files available");
                    }
                }
        };
    }

    IContributionItem[] result = new IContributionItem[files.length];
    for (int i = 0; i < result.length; i++) {
        CommandContributionItemParameter parameter = new CommandContributionItemParameter(
                serviceLocator, "com.genuitec.eclipse.gerrit.tools.quickImportProjects." + i,  //$NON-NLS-1$
                "com.genuitec.eclipse.gerrit.tools.importProjects", SWT.PUSH); //$NON-NLS-1$
        parameter.parameters = Collections.singletonMap("file", files[i].toString()); //$NON-NLS-1$
        parameter.label = files[i].getName();
        result[i] = new CommandContributionItem(parameter);
    }
    return result;
}
项目:google-cloud-eclipse    文件:OpenDropDownMenuHandler.java   
/**
 * Retrieve the menu id to show from the contribution item's ID (following the documented approach
 * for DROP_DOWN items).
 */
private static String getMenuId(ToolItem toolItem)
    throws ExecutionException {
  if (toolItem.getData() instanceof ContributionItem) {
    ContributionItem data = (ContributionItem) toolItem.getData();
    if (!Strings.isNullOrEmpty(data.getId())) {
      return data.getId();
    }
  }
  throw new ExecutionException("Unable to determine menu ID");
}
项目:PDFReporter-Studio    文件:ATopToolBarManager.java   
public void removeAll() {
    for (IContributionItem it : tbManager.getItems()) { 
        if (it instanceof ActionContributionItem && ((ActionContributionItem) it).getAction() instanceof IDisposable)
            ((IDisposable) ((ActionContributionItem) it).getAction()).dispose();
        else if (it instanceof ContributionItem)
            it.dispose();
    }
    tbManager.removeAll();
}
项目:CSIclipse    文件:StackBrowserView.java   
private void addLocalToolBar(IToolBarManager manager, ContributionItem item){
    manager.add(item);
}
项目:mytourbook    文件:ActionSetMarkerLabelPositionMenu.java   
private void fillMenu(final Menu menu) {

        final int currentLabelPosition = _tourMarker.getLabelPosition();

        for (final ContributionItem contribItem : _allActions) {

            if (contribItem instanceof ActionContributionItem) {

                final ActionContributionItem actionItem = (ActionContributionItem) contribItem;
                final IAction action = actionItem.getAction();

                if (action instanceof ActionSetMarkerPosition) {

                    final ActionSetMarkerPosition posAction = (ActionSetMarkerPosition) action;

                    final boolean isCurrentPosition = posAction.labelPosId == currentLabelPosition;

                    posAction.setChecked(isCurrentPosition);
                    posAction.setEnabled(!isCurrentPosition);
                }
            }

            contribItem.fill(_menu, -1);
        }
    }
项目:Eclipse-Postfix-Code-Completion    文件:MultiActionGroup.java   
/**
 * Adds the actions to the given menu manager.
 */
protected void addActions(IMenuManager viewMenu) {

    viewMenu.add(new Separator());
    fItems= new MenuItem[fActions.length];

    for (int i= 0; i < fActions.length; i++) {
        final int j= i;

        viewMenu.add(new ContributionItem() {

            @Override
            public void fill(Menu menu, int index) {

                int style= SWT.CHECK;
                if ((fActions[j].getStyle() & IAction.AS_RADIO_BUTTON) != 0)
                    style= SWT.RADIO;

                MenuItem mi= new MenuItem(menu, style, index);
                ImageDescriptor d= fActions[j].getImageDescriptor();
                mi.setImage(JavaPlugin.getImageDescriptorRegistry().get(d));
                fItems[j]= mi;
                mi.setText(fActions[j].getText());
                mi.setSelection(fCurrentSelection == j);
                mi.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        if (fCurrentSelection == j) {
                            fItems[fCurrentSelection].setSelection(true);
                            return;
                        }
                        fActions[j].run();

                        // Update checked state
                        fItems[fCurrentSelection].setSelection(false);
                        fCurrentSelection= j;
                        fItems[fCurrentSelection].setSelection(true);
                    }

                });
            }
            @Override
            public boolean isDynamic() {
                return false;
            }
        });
    }
}
项目:translationstudio8    文件:WorkingSetRootModeActionGroup.java   
/**
 * Adds the actions to the given menu manager.
 */
protected void addActions(IMenuManager viewMenu) {
    if (actions == null)
        actions = createActions();

    viewMenu.add(new Separator());
    items = new MenuItem[actions.length];

    for (int i = 0; i < actions.length; i++) {
        final int j = i;

        viewMenu.add(new ContributionItem() {

            public void fill(Menu menu, int index) {

                int style = SWT.CHECK;
                if ((actions[j].getStyle() & IAction.AS_RADIO_BUTTON) != 0)
                    style = SWT.RADIO;

                final MenuItem mi = new MenuItem(menu, style, index);
                items[j] = mi;
                mi.setText(actions[j].getText());
                mi.setSelection(currentSelection == j);
                mi.addSelectionListener(new SelectionAdapter() {

                    public void widgetSelected(SelectionEvent e) {
                        if (currentSelection == j) {
                            items[currentSelection].setSelection(true);
                            return;
                        }
                        actions[j].run();

                        // Update checked state
                        items[currentSelection].setSelection(false);
                        currentSelection = j;
                        items[currentSelection].setSelection(true);
                    }

                });

            }

            public boolean isDynamic() {
                return false;
            }
        });
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:MultiActionGroup.java   
/**
 * Adds the actions to the given menu manager.
 */
protected void addActions(IMenuManager viewMenu) {

    viewMenu.add(new Separator());
    fItems= new MenuItem[fActions.length];

    for (int i= 0; i < fActions.length; i++) {
        final int j= i;

        viewMenu.add(new ContributionItem() {

            @Override
            public void fill(Menu menu, int index) {

                int style= SWT.CHECK;
                if ((fActions[j].getStyle() & IAction.AS_RADIO_BUTTON) != 0)
                    style= SWT.RADIO;

                MenuItem mi= new MenuItem(menu, style, index);
                ImageDescriptor d= fActions[j].getImageDescriptor();
                mi.setImage(JavaPlugin.getImageDescriptorRegistry().get(d));
                fItems[j]= mi;
                mi.setText(fActions[j].getText());
                mi.setSelection(fCurrentSelection == j);
                mi.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        if (fCurrentSelection == j) {
                            fItems[fCurrentSelection].setSelection(true);
                            return;
                        }
                        fActions[j].run();

                        // Update checked state
                        fItems[fCurrentSelection].setSelection(false);
                        fCurrentSelection= j;
                        fItems[fCurrentSelection].setSelection(true);
                    }

                });
            }
            @Override
            public boolean isDynamic() {
                return false;
            }
        });
    }
}
项目:Rel    文件:Designer.java   
protected void init() {
    dataProvider = new DataProvider();
    headingProvider = new HeadingProvider();

    gridLayer = new DefaultGridLayer(dataProvider, headingProvider);

    // CellLabelAccumulator determines how cells will be displayed
    class CellLabelAccumulator implements IConfigLabelAccumulator {
        @Override
        public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
            configLabels.addLabel("column" + columnPosition);
            if (dataProvider.isEditableNonscalarDefinition(rowPosition) && columnPosition == Attr.HEADING_COLUMN)
                configLabels.addLabel("nonscalareditor");
        }
    }

    DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    CellLabelAccumulator cellLabelAccumulator = new CellLabelAccumulator();
    bodyDataLayer.setConfigLabelAccumulator(cellLabelAccumulator);

    table = new NatTable(parent, gridLayer, false);

    editorConfiguration = new EditorConfiguration();

    DefaultNatTableStyleConfiguration defaultStyle = new DefaultNatTableStyleConfiguration();
    table.addConfiguration(defaultStyle);
    table.addConfiguration(editorConfiguration);

    ContributionItem rowMenuItems = new ContributionItem() {
        @Override
        public void fill(Menu menu, int index) {
            MenuItem doesDelete = new MenuItem(menu, SWT.PUSH);
            doesDelete.setText("Delete");
            doesDelete.setImage(IconLoader.loadIcon("table_row_delete"));
            doesDelete.addListener(SWT.Selection, e -> askDeleteSelected());
        }
    };
    table.addConfiguration(new MenuConfiguration(GridRegion.ROW_HEADER,
            new PopupMenuBuilder(table).withContributionItem(rowMenuItems)));

    // Tabbing wraps and moves up/down
    gridLayer.registerCommandHandler(new MoveCellSelectionCommandHandler(
            gridLayer.getBodyLayer().getSelectionLayer(), ITraversalStrategy.TABLE_CYCLE_TRAVERSAL_STRATEGY));

    table.configure();

    // Tooltip for row/column headings
    new NatTableContentTooltip(table, GridRegion.ROW_HEADER) {
        protected String getText(Event event) {
            return "Right-click for options.";
        }
    };
}
项目:tmxeditor8    文件:WorkingSetRootModeActionGroup.java   
/**
 * Adds the actions to the given menu manager.
 */
protected void addActions(IMenuManager viewMenu) {
    if (actions == null)
        actions = createActions();

    viewMenu.add(new Separator());
    items = new MenuItem[actions.length];

    for (int i = 0; i < actions.length; i++) {
        final int j = i;

        viewMenu.add(new ContributionItem() {

            public void fill(Menu menu, int index) {

                int style = SWT.CHECK;
                if ((actions[j].getStyle() & IAction.AS_RADIO_BUTTON) != 0)
                    style = SWT.RADIO;

                final MenuItem mi = new MenuItem(menu, style, index);
                items[j] = mi;
                mi.setText(actions[j].getText());
                mi.setSelection(currentSelection == j);
                mi.addSelectionListener(new SelectionAdapter() {

                    public void widgetSelected(SelectionEvent e) {
                        if (currentSelection == j) {
                            items[currentSelection].setSelection(true);
                            return;
                        }
                        actions[j].run();

                        // Update checked state
                        items[currentSelection].setSelection(false);
                        currentSelection = j;
                        items[currentSelection].setSelection(true);
                    }

                });

            }

            public boolean isDynamic() {
                return false;
            }
        });
    }
}