Search in sources :

Example 1 with ContributionItem

use of org.eclipse.jface.action.ContributionItem in project translationstudio8 by heartsome.

the class WorkingSetRootModeActionGroup method addActions.

/**
	 * 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;
            }
        });
    }
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ContributionItem(org.eclipse.jface.action.ContributionItem) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) Separator(org.eclipse.jface.action.Separator)

Example 2 with ContributionItem

use of org.eclipse.jface.action.ContributionItem in project n4js by eclipse.

the class SelectTopLevelElementActionGroup method addActions.

private void addActions(final IMenuManager menuManager) {
    menuManager.add(new Separator());
    // Projects menu item
    menuManager.add(new ContributionItem() {

        @Override
        public void fill(final Menu menu, final int index) {
            projectsItem = new MenuItem(menu, SWT.CHECK);
            projectsItem.setText("Projects");
            projectsItem.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(final SelectionEvent e) {
                    projectsItem.setSelection(true);
                    workingSetsItem.setSelection(false);
                    workingSetManagerBroker.setWorkingSetTopLevel(false);
                }
            });
            if (!workingSetManagerBroker.isWorkingSetTopLevel()) {
                projectsItem.setSelection(true);
            }
        }
    });
    menuManager.add(new ContributionItem() {

        @Override
        public void fill(final Menu menu, final int index) {
            workingSetsItem = new MenuItem(menu, SWT.CHECK);
            workingSetsItem.setText("Working Sets");
            workingSetsItem.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(final SelectionEvent e) {
                    workingSetsItem.setSelection(true);
                    projectsItem.setSelection(false);
                    workingSetManagerBroker.setWorkingSetTopLevel(true);
                }
            });
            if (workingSetManagerBroker.isWorkingSetTopLevel()) {
                workingSetsItem.setSelection(true);
            }
        }
    });
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ContributionItem(org.eclipse.jface.action.ContributionItem) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) Separator(org.eclipse.jface.action.Separator)

Example 3 with ContributionItem

use of org.eclipse.jface.action.ContributionItem in project dsl-devkit by dsldevkit.

the class DynamicViewMenu method getMenuItemsInternal.

/**
 * Gets the menu items. This is expected to be called from within the UI thread. If not it will throw exceptions
 * based on invalid thread access.
 *
 * @param items
 *          the menu items to search through
 * @param menuPath
 *          the menu path without the menu item to find.
 * @param recursive
 *          if set to <code>true</code>, will find sub-menus as well.
 * @return The list of SWTBotMenu items which match the menu path.
 */
@SuppressWarnings("PMD.CyclomaticComplexity")
private static List<SWTBotMenu> getMenuItemsInternal(final IContributionItem[] items, final List<String> menuPath, final boolean recursive) {
    final List<SWTBotMenu> l = new ArrayList<SWTBotMenu>();
    final boolean findAnything = (menuPath == null) || menuPath.isEmpty();
    for (final IContributionItem item : items) {
        try {
            if ((item instanceof MenuManager) && recursive) {
                // Sub menus
                final MenuManager menuManager = (MenuManager) item;
                if (findAnything || menuManager.getMenuText().equals(menuPath.get(0))) {
                    List<String> subList = null;
                    if (menuPath.size() > 1) {
                        subList = menuPath.subList(1, menuPath.size());
                    }
                    l.addAll(getMenuItemsInternal(menuManager.getItems(), subList, recursive));
                }
            } else if (item instanceof ContributionItem) {
                final ContributionItem dynItem = (ContributionItem) item;
                dynItem.fill(originalMenu, 0);
                final MenuItem[] items2 = originalMenu.getItems();
                for (final MenuItem item2 : items2) {
                    l.add(new SWTBotMenu(item2));
                }
            }
        } catch (final WidgetNotFoundException widgetNotFoundException) {
            // Do nothing
            continue;
        }
    }
    return l;
}
Also used : WidgetNotFoundException(org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException) SWTBotMenu(org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu) IContributionItem(org.eclipse.jface.action.IContributionItem) ArrayList(java.util.ArrayList) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) ContributionItem(org.eclipse.jface.action.ContributionItem) IContributionItem(org.eclipse.jface.action.IContributionItem) MenuItem(org.eclipse.swt.widgets.MenuItem)

Aggregations

ContributionItem (org.eclipse.jface.action.ContributionItem)3 MenuItem (org.eclipse.swt.widgets.MenuItem)3 Separator (org.eclipse.jface.action.Separator)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Menu (org.eclipse.swt.widgets.Menu)2 ArrayList (java.util.ArrayList)1 IContributionItem (org.eclipse.jface.action.IContributionItem)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 MenuManager (org.eclipse.jface.action.MenuManager)1 WidgetNotFoundException (org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException)1 SWTBotMenu (org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu)1