Search in sources :

Example 1 with SubContributionItem

use of org.eclipse.jface.action.SubContributionItem in project netxms by netxms.

the class MenuBarManager method makeEntry.

/**
 * @param item
 */
private void makeEntry(final IContributionItem item) {
    IContributionItem tempItem = null;
    if (item instanceof SubContributionItem) {
        SubContributionItem subItem = (SubContributionItem) item;
        tempItem = subItem.getInnerItem();
    } else if (item instanceof MenuManager) {
        tempItem = item;
    }
    if (tempItem != null && tempItem instanceof MenuManager) {
        final MenuManager manager = (MenuManager) tempItem;
        int style = extractStyle(manager);
        final ToolItem toolItem = new ToolItem(toolbar, style);
        toolItem.setText(manager.getMenuText());
        toolItem.setData(RWT.CUSTOM_VARIANT, MENU_BAR_VARIANT);
        createMenu(manager, toolItem);
        // needed to clear all controls in case of an update
        toolItemList.add(toolItem);
    }
}
Also used : IContributionItem(org.eclipse.jface.action.IContributionItem) SubContributionItem(org.eclipse.jface.action.SubContributionItem) MenuManager(org.eclipse.jface.action.MenuManager) Point(org.eclipse.swt.graphics.Point) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 2 with SubContributionItem

use of org.eclipse.jface.action.SubContributionItem in project netxms-ocilib by stevemqeen.

the class MenuBarManager method makeEntry.

/**
 * @param item
 */
private void makeEntry(final IContributionItem item) {
    IContributionItem tempItem = null;
    if (item instanceof SubContributionItem) {
        SubContributionItem subItem = (SubContributionItem) item;
        tempItem = subItem.getInnerItem();
    } else if (item instanceof MenuManager) {
        tempItem = item;
    }
    if (tempItem != null && tempItem instanceof MenuManager) {
        final MenuManager manager = (MenuManager) tempItem;
        int style = extractStyle(manager);
        final ToolItem toolItem = new ToolItem(toolbar, style);
        toolItem.setText(manager.getMenuText());
        toolItem.setData(RWT.CUSTOM_VARIANT, MENU_BAR_VARIANT);
        createMenu(manager, toolItem);
        // needed to clear all controls in case of an update
        toolItemList.add(toolItem);
    }
}
Also used : IContributionItem(org.eclipse.jface.action.IContributionItem) SubContributionItem(org.eclipse.jface.action.SubContributionItem) MenuManager(org.eclipse.jface.action.MenuManager) Point(org.eclipse.swt.graphics.Point) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 3 with SubContributionItem

use of org.eclipse.jface.action.SubContributionItem in project eclipse.platform.ui by eclipse-platform.

the class CustomizePerspectiveDialog method createMenuEntry.

private DynamicContributionItem createMenuEntry(DisplayItem parent, DynamicContributionItem dynamicEntry, MMenuElement menuItem, Map<IContributionItem, DisplayItem> processedOpaqueItems) {
    if (!menuItem.isToBeRendered()) {
        return null;
    }
    if (menuItem instanceof MMenu) {
        MenuManager manager = menuMngrRenderer.getManager((MMenu) menuItem);
        ImageDescriptor iconDescriptor;
        DisplayItem menuEntry;
        if (OpaqueElementUtil.isOpaqueMenu(menuItem)) {
            if (processedOpaqueItems.containsKey(manager)) {
                // Manager already processed as wrapped item, which determines the position
                // Still the child entries must be added
                menuEntry = processedOpaqueItems.get(manager);
            } else {
                menuEntry = new DisplayItem(manager.getMenuText(), manager);
                parent.addChild(menuEntry);
            }
            iconDescriptor = manager.getImageDescriptor();
        } else {
            menuEntry = new DisplayItem(menuItem.getLocalizedLabel(), manager);
            iconDescriptor = getIconDescriptor(menuItem);
            parent.addChild(menuEntry);
        }
        if (iconDescriptor != null) {
            menuEntry.setImageDescriptor(iconDescriptor);
        } else if (parent.getParent() == null) {
            menuEntry.setImageDescriptor(menuImageDescriptor);
        } else {
            menuEntry.setImageDescriptor(submenuImageDescriptor);
        }
        menuEntry.setActionSet(idToActionSet.get(getActionSetID(menuItem)));
        // Compatibility sub-menus for some opaque menus
        String managerId = manager != null ? manager.getId() : null;
        if (ActionFactory.NEW.getId().equals(managerId)) {
            initializeNewWizardsMenu(menuEntry);
            wizards = menuEntry;
        } else if (SHORTCUT_CONTRIBUTION_ITEM_ID_OPEN_PERSPECTIVE.equals(managerId)) {
            initializePerspectivesMenu(menuEntry);
            perspectives = menuEntry;
        } else if (SHORTCUT_CONTRIBUTION_ITEM_ID_SHOW_VIEW.equals(managerId)) {
            initializeViewsMenu(menuEntry);
            views = menuEntry;
        } else {
            createMenuEntries((MMenu) menuItem, menuEntry);
        }
        if (menuEntry.getChildren().isEmpty()) {
            menuEntry.setCheckState(getMenuItemIsVisible(menuEntry));
        }
    } else if (RenderedElementUtil.isRenderedMenuItem(menuItem)) {
        IContributionItem contributionItem = menuMngrRenderer.getContribution(menuItem);
        if (dynamicEntry == null || !contributionItem.equals(dynamicEntry.getIContributionItem())) {
            // Only create one dynamic item for multiple (successive) dynamic contribution
            // items
            dynamicEntry = new DynamicContributionItem(contributionItem);
            dynamicEntry.setActionSet(idToActionSet.get(getActionSetID(menuItem)));
            dynamicEntry.setCheckState(getMenuItemIsVisible(dynamicEntry));
            parent.addChild(dynamicEntry);
        }
        if (menuItem.getWidget() != null) {
            // TODO See Bug 558766: add children; widgets are no longer available
            dynamicEntry.addCurrentItem((MenuItem) menuItem.getWidget());
        }
        return dynamicEntry;
    } else if (OpaqueElementUtil.isOpaqueMenuItem(menuItem)) {
        IContributionItem contributionItem = menuMngrRenderer.getContribution(menuItem);
        if (contributionItem instanceof SubContributionItem) {
            // get the wrapped contribution item
            contributionItem = ((SubContributionItem) contributionItem).getInnerItem();
        }
        if (contributionItem instanceof SubMenuManager) {
            // get the wrapped contribution item
            contributionItem = (IMenuManager) ((SubMenuManager) contributionItem).getParent();
        }
        if (processedOpaqueItems.containsKey(contributionItem)) {
            // Only the first occurrence of an item will be shown
            return null;
        }
        if (contributionItem.isDynamic()) {
            if (dynamicEntry == null || !contributionItem.equals(dynamicEntry.getIContributionItem())) {
                // Only create one dynamic item for multiple (successive) dynamic contribution
                // items
                dynamicEntry = new DynamicContributionItem(contributionItem);
                dynamicEntry.setActionSet(idToActionSet.get(getActionSetID(contributionItem)));
                dynamicEntry.setCheckState(getMenuItemIsVisible(dynamicEntry));
                parent.addChild(dynamicEntry);
                processedOpaqueItems.put(contributionItem, dynamicEntry);
            }
            if (menuItem.getWidget() != null) {
                // TODO See Bug 558766: add children; widgets are no longer available
                dynamicEntry.addCurrentItem((MenuItem) menuItem.getWidget());
            }
            return dynamicEntry;
        } else if (contributionItem instanceof CommandContributionItem) {
            CommandContributionItem cci = (CommandContributionItem) contributionItem;
            CommandContributionItemParameter data = cci.getData();
            DisplayItem menuEntry = new DisplayItem(data.label, contributionItem);
            menuEntry.setImageDescriptor(data.icon);
            menuEntry.setActionSet(idToActionSet.get(getActionSetID(contributionItem)));
            menuEntry.setCheckState(getMenuItemIsVisible(menuEntry));
            parent.addChild(menuEntry);
            processedOpaqueItems.put(contributionItem, menuEntry);
        } else if (contributionItem instanceof ActionContributionItem) {
            final IAction action = ((ActionContributionItem) contributionItem).getAction();
            DisplayItem menuEntry = new DisplayItem(action.getText(), contributionItem);
            menuEntry.setImageDescriptor(action.getImageDescriptor());
            menuEntry.setActionSet(idToActionSet.get(getActionSetID(contributionItem)));
            menuEntry.setCheckState(getMenuItemIsVisible(menuEntry));
            parent.addChild(menuEntry);
            processedOpaqueItems.put(contributionItem, menuEntry);
        } else if (contributionItem instanceof MenuManager) {
            MenuManager manager = (MenuManager) contributionItem;
            DisplayItem menuEntry = new DisplayItem(manager.getMenuText(), contributionItem);
            menuEntry.setImageDescriptor(manager.getImageDescriptor());
            menuEntry.setActionSet(idToActionSet.get(getActionSetID(contributionItem)));
            menuEntry.setCheckState(getMenuItemIsVisible(menuEntry));
            parent.addChild(menuEntry);
            // The child entries will be processes when the not-wrapped item is processed,
            // see MMenu case
            processedOpaqueItems.put(contributionItem, menuEntry);
        }
    } else if (menuItem instanceof MDynamicMenuContribution) {
        IContributionItem contributionItem = menuMngrRenderer.getContribution(menuItem);
        dynamicEntry = new DynamicContributionItem(menuItem.getLocalizedLabel(), contributionItem);
        dynamicEntry.setImageDescriptor(getIconDescriptor(menuItem));
        dynamicEntry.setActionSet(idToActionSet.get(getActionSetID(menuItem)));
        dynamicEntry.setCheckState(getMenuItemIsVisible(dynamicEntry));
        // TODO See Bug 558766: add children
        parent.addChild(dynamicEntry);
    } else if (menuItem instanceof MDirectMenuItem) {
        IContributionItem contributionItem = menuMngrRenderer.getContribution(menuItem);
        DisplayItem menuEntry = new DisplayItem(menuItem.getLocalizedLabel(), contributionItem);
        menuEntry.setImageDescriptor(getIconDescriptor(menuItem));
        menuEntry.setActionSet(idToActionSet.get(getActionSetID(menuItem)));
        menuEntry.setCheckState(getMenuItemIsVisible(menuEntry));
        parent.addChild(menuEntry);
    } else if (menuItem instanceof MHandledMenuItem) {
        IContributionItem contributionItem = menuMngrRenderer.getContribution(menuItem);
        MHandledMenuItem hmi = (MHandledMenuItem) menuItem;
        String text = hmi.getLocalizedLabel();
        if (text == null && hmi.getWbCommand() != null) {
            try {
                text = hmi.getWbCommand().getName();
            } catch (NotDefinedException e) {
            // we'll just ignore a failure
            }
        }
        DisplayItem menuEntry = new DisplayItem(text, contributionItem);
        menuEntry.setImageDescriptor(getIconDescriptor(menuItem));
        menuEntry.setActionSet(idToActionSet.get(getActionSetID(menuItem)));
        menuEntry.setCheckState(getMenuItemIsVisible(menuEntry));
        parent.addChild(menuEntry);
    }
    return null;
}
Also used : IAction(org.eclipse.jface.action.IAction) IContributionItem(org.eclipse.jface.action.IContributionItem) MDynamicMenuContribution(org.eclipse.e4.ui.model.application.ui.menu.MDynamicMenuContribution) SubContributionItem(org.eclipse.jface.action.SubContributionItem) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) MDirectMenuItem(org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem) MenuItem(org.eclipse.swt.widgets.MenuItem) MHandledMenuItem(org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu) SubMenuManager(org.eclipse.jface.action.SubMenuManager) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) MDirectMenuItem(org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem) CommandContributionItemParameter(org.eclipse.ui.menus.CommandContributionItemParameter) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) ActionSetMenuManager(org.eclipse.ui.internal.ActionSetMenuManager) SubMenuManager(org.eclipse.jface.action.SubMenuManager) MHandledMenuItem(org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem)

Example 4 with SubContributionItem

use of org.eclipse.jface.action.SubContributionItem in project eclipse.platform.ui by eclipse-platform.

the class ActionUtil method runActionWithLabel.

/**
 * Runs the first action found in a menu manager with a
 * particular label.
 *
 * @param test the current test case
 * @param mgr the containing menu manager
 * @param label the action label
 */
public static void runActionWithLabel(TestCase test, IMenuManager mgr, String label) {
    IContributionItem[] items = mgr.getItems();
    for (IContributionItem item : items) {
        if (item instanceof SubContributionItem)
            item = ((SubContributionItem) item).getInnerItem();
        if (item instanceof ActionContributionItem) {
            IAction action = ((ActionContributionItem) item).getAction();
            if (label.equals(action.getText())) {
                action.run();
                return;
            }
        }
    }
    Assert.fail("Unable to find action: " + label);
}
Also used : ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) IAction(org.eclipse.jface.action.IAction) IContributionItem(org.eclipse.jface.action.IContributionItem) SubContributionItem(org.eclipse.jface.action.SubContributionItem)

Example 5 with SubContributionItem

use of org.eclipse.jface.action.SubContributionItem in project eclipse.platform.ui by eclipse-platform.

the class TextSelectionActionExpressionTest method getActionMenuManager.

/**
 * Returns the menu manager containing the actions.
 */
private MenuManager getActionMenuManager(ExtendedTextEditor editor) throws Throwable {
    fPage.showActionSet("org.eclipse.ui.tests.internal.TextSelectionActions");
    WorkbenchWindow win = (WorkbenchWindow) fWindow;
    IContributionItem item = win.getMenuBarManager().find("org.eclipse.ui.tests.internal.TextSelectionMenu");
    while (item instanceof SubContributionItem) {
        item = ((SubContributionItem) item).getInnerItem();
        if (item instanceof MenuManager) {
            return (MenuManager) item;
        }
    }
    fail("Unable to find menu manager");
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) WorkbenchWindow(org.eclipse.ui.internal.WorkbenchWindow) IContributionItem(org.eclipse.jface.action.IContributionItem) SubContributionItem(org.eclipse.jface.action.SubContributionItem) MenuManager(org.eclipse.jface.action.MenuManager)

Aggregations

IContributionItem (org.eclipse.jface.action.IContributionItem)11 SubContributionItem (org.eclipse.jface.action.SubContributionItem)11 MenuManager (org.eclipse.jface.action.MenuManager)7 ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)3 IMenuManager (org.eclipse.jface.action.IMenuManager)3 WorkbenchWindow (org.eclipse.ui.internal.WorkbenchWindow)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 MMenu (org.eclipse.e4.ui.model.application.ui.menu.MMenu)2 IAction (org.eclipse.jface.action.IAction)2 SubMenuManager (org.eclipse.jface.action.SubMenuManager)2 Point (org.eclipse.swt.graphics.Point)2 MenuItem (org.eclipse.swt.widgets.MenuItem)2 ToolItem (org.eclipse.swt.widgets.ToolItem)2 IViewPart (org.eclipse.ui.IViewPart)2 LinkedHashSet (java.util.LinkedHashSet)1 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 MDirectMenuItem (org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem)1 MDynamicMenuContribution (org.eclipse.e4.ui.model.application.ui.menu.MDynamicMenuContribution)1