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);
}
}
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);
}
}
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;
}
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);
}
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;
}
Aggregations