Teamcenter进行菜单栏开发

在对Teamcenter进行二次开发的时候经常会对菜单进行扩展,Eclipse 提供了两种扩展点供用户添加菜单项到相应的位置。这两种扩展点为 org.eclipse.ui.commands(简称为 Commands 方式)和 org.eclipse.ui.actionSets(简称为 Actions 方式),我现在只写了用Commands方式实现的,为什么不用Actions可以参考这篇文章Eclipse Action与Command的区别

 菜单分为主菜单,上下文菜单,视图菜单
主菜单扩展:

 <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>

效果如下:

上下文菜单扩展:

<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>

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值