方法一:指定menuContribution:
toolbar:org.eclipse.ui.main.toolbar - the top-level tool bar
toolbar:org.eclipse.ui.trim.command1 - the top left trim
toolbar:org.eclipse.ui.trim.command2 - the top right trim
toolbar:org.eclipse.ui.trim.vertical1 - the left vertical trim
toolbar:org.eclipse.ui.trim.vertical2 - the right vertical trim
toolbar:org.eclipse.ui.trim.status - the status line trim
配合http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fworkbench_cmd_menus.htm 适用
方法二:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
id="application"
point="org.eclipse.core.runtime.applications">
<application>
<run
class="de.vogella.rcp.commands.runtimecommands.Application">
</run>
</application>
</extension>
<extension
point="org.eclipse.ui.perspectives">
<perspective
name="RCP Perspective"
class="de.vogella.rcp.commands.runtimecommands.Perspective"
id="de.vogella.rcp.commands.runtimecommands.perspective">
</perspective>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
class="de.vogella.rcp.commands.runtimecommands.DefineCommands"
locationURI="menu:org.eclipse.ui.main.menu">
</menuContribution>
</extension>
</plugin>
package de.vogella.rcp.commands.runtimecommands;
import org.eclipse.swt.SWT;
import org.eclipse.ui.menus.CommandContributionItem;
import org.eclipse.ui.menus.CommandContributionItemParameter;
import org.eclipse.ui.menus.ExtensionContributionFactory;
import org.eclipse.ui.menus.IContributionRoot;
import org.eclipse.ui.services.IServiceLocator;
public class DefineCommands extends ExtensionContributionFactory {
@Override
public void createContributionItems(IServiceLocator serviceLocator,
IContributionRoot additions) {
CommandContributionItemParameter p = new CommandContributionItemParameter(
serviceLocator, "",
"org.eclipse.ui.file.exit",
SWT.PUSH);
p.label = "Exit the application";
p.icon = Activator.getImageDescriptor("icons/alt_window_16.gif");
CommandContributionItem item = new CommandContributionItem(p);
item.setVisible(true);
additions.addContributionItem(item, null);
}
}
来自:http://www.vogella.com/blog/2009/12/03/commands-menu-runtime/
http://www.imilo.cn