菜单分为主菜单,上下文菜单,视图菜单
主菜单扩展:
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu label="测试菜单" id="ceshi">
<command
icon="icon/alignmiddle.png"
commandId="com.service.handlers.handleone">
</command>
</menu>
</menuContribution>
<menuContribution locationURI="menu:ceshi">
<menu label="菜单一">
icon="icon/alignmiddle.png"
commandId="com.service.handlers.handleone">
</command>
icon="icon/alignmiddle.png"
commandId="com.service.handlers.handleone">
</command>
</menu>
</menuContribution>
<menuContribution locationURI="menu:ceshi">
<menu label="菜单二">
<command
icon="icon/alignmiddle.png"
commandId="com.service.handlers.handleone">
</command>
<command
icon="icon/alignmiddle.png"
commandId="com.service.handlers.handleone">
</command>
</menu>
</menuContribution>
</extension>
上下文菜单扩展:
<extension
point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<menu label="上下文菜单" id="shang">
<command
icon="icon/alignmiddle.png"
commandId="com.service.handlers.handleone">
</command>
<command
icon="icon/alignmiddle.png"
commandId="com.service.handlers.handleone">
</command>
<command
icon="icon/alignmiddle.png"
commandId="com.service.handlers.handleone">
</command>
</menu>
</menuContribution>
</extension>
效果如下:
整个的plugin.xml文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.commands">
<command
icon="icon/alignmiddle.png"
id="com.service.handlers.handleone"
name="子菜单一"/>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="com.service.handlers.handleone"
commandId="com.service.handlers.handleone">
</handler>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<menu label="上下文菜单" id="shang">
<command
icon="icon/alignmiddle.png"
commandId="com.service.handlers.handleone">
</command>
<command
icon="icon/alignmiddle.png"
commandId="com.service.handlers.handleone">
</command>
<command
icon="icon/alignmiddle.png"
commandId="com.service.handlers.handleone">
</command>
</menu>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu label="测试菜单" id="ceshi">
<command
icon="icon/alignmiddle.png"
commandId="com.service.handlers.handleone">
</command>
</menu>
</menuContribution>
<menuContribution locationURI="menu:ceshi">
<menu label="菜单一">
<command
icon="icon/alignmiddle.png"
commandId="com.service.handlers.handleone">
</command>
<command
icon="icon/alignmiddle.png"
commandId="com.service.handlers.handleone">
</command>
</menu>
</menuContribution>
<menuContribution locationURI="menu:ceshi">
<menu label="菜单二">
<command
icon="icon/alignmiddle.png"
commandId="com.service.handlers.handleone">
</command>
<command
icon="icon/alignmiddle.png"
commandId="com.service.handlers.handleone">
</command>
</menu>
</menuContribution>
</extension>
</plugin>