下面列出了怎么用org.eclipse.ui.menus.IContributionRoot的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) {
ITextEditor editor = (ITextEditor)
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
IVerticalRulerInfo rulerInfo = editor.getAdapter(IVerticalRulerInfo.class);
try {
List<IMarker> markers = getMarkers(editor, rulerInfo);
additions.addContributionItem(new ReviewMarkerMenuContribution(editor, markers), null);
if (!markers.isEmpty()) {
additions.addContributionItem(new Separator(), null);
}
} catch (CoreException e) {
AppraiseUiPlugin.logError("Error creating marker context menus", e);
}
}
@Override
public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) {
MenuDataList items = MenuDataStore.instance().getEnabledCommandMenuDataList();
for (MenuData item : items) {
ResourceType resTypeWanted = getWantedResourceType();
ResourceType resTypeSupported;
try {
resTypeSupported = item.getCommandData().getResourceType();
if ((resTypeSupported == ResourceType.resourceTypeFileOrDirectory)
|| (resTypeSupported == resTypeWanted)) {
addItem(serviceLocator, additions, item.getNameExpanded(),
"de.anbos.eclipse.easyshell.plugin.commands.execute",
Utils.getParameterMapFromMenuData(item), item.getImageId(),
true);
}
} catch (UnknownCommandID e) {
e.logInternalError();
}
}
}
@Override
public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) {
ITextEditor editor = (ITextEditor)
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
additions.addContributionItem(new TextEditorContextMenuContribution(editor), null);
}
private void addItem(IServiceLocator serviceLocator, IContributionRoot additions, String commandLabel,
String commandId, Map<String, Object> commandParamametersMap, String commandImageId, boolean visible) {
CommandContributionItemParameter param = new CommandContributionItemParameter(serviceLocator, "", commandId,
SWT.PUSH);
param.label = commandLabel;
param.icon = Activator.getImageDescriptor(commandImageId);
param.parameters = commandParamametersMap;
CommandContributionItem item = new CommandContributionItem(param);
item.setVisible(visible);
additions.addContributionItem(item, null);
}
@Override
public void createContributionItems(IServiceLocator serviceLoc, IContributionRoot additions) {
// Local Declarations
HashMap<String, MenuManager> categoryMenus = new HashMap<String, MenuManager>();
String codeName = "", category = "";
MenuManager codeMenu = null;
// Set the ServiceLocator
serviceLocator = serviceLoc;
// Create the Developer Menu Item
developerMenu = new MenuManager("&Developer", "iceDev");
// Get the registry and the extensions
registry = Platform.getExtensionRegistry();
// Create the category sub-menus
for (CodeCategory c : CodeCategory.values()) {
MenuManager manager = new MenuManager(c.name(), c.name() + "ID");
manager.setVisible(true);
categoryMenus.put(c.name(), manager);
developerMenu.add(manager);
}
// Get the Extension Points
IExtensionPoint extensionPoint = registry.getExtensionPoint("org.eclipse.ice.developer.code");
IExtension[] codeExtensions = extensionPoint.getExtensions();
// Loop over the rest of the Extensions and create
// their sub-menus.
for (IExtension code : codeExtensions) {
// Get the name of the bundle this extension comes from
// so we can instantiate its AbstractHandlers
String contributingPlugin = code.getContributor().getName();
// Get the elements of this extension
IConfigurationElement[] elements = code.getConfigurationElements();
for (IConfigurationElement e : elements) {
// Get the Code Name
codeName = e.getAttribute("codeName");
// Get whether this is the ICE declaration
boolean isICE = "ICE".equals(codeName);
// Get the Code Category - Framework, Physics, etc...
category = isICE ? codeName : e.getAttribute("codeCategory");
// Create a sub menu for the code in the
// correct category, if this is not ICE ( we've already done it for ICE)
codeMenu = isICE ? categoryMenus.get(codeName)
: new MenuManager(codeName, codeName + "ID");
// Generate the IParameters for the Command
generateParameters(e);
// Create a menu item for each extra command they provided
for (IConfigurationElement command : e.getChildren("command")) {
generateParameters(command);
createCommand(contributingPlugin, command.getAttribute("implementation"), codeMenu);
}
// Add it to the correct category menu
if (!"ICE".equals(codeName)) {
categoryMenus.get(category).add(codeMenu);
}
}
parameters.clear();
}
// Add the newly constructed developer menu
additions.addContributionItem(developerMenu, null);
return;
}