RCP关于配置方式在菜单栏创建菜单

Java代码 复制代码
  1. RCP关于配置方式在菜单栏创建菜单  
           RCP关于配置方式在菜单栏创建菜单
Java代码 复制代码
  1. <extension   
  2.          point="org.eclipse.ui.commands">   
  3.       <category   
  4.             id="com.vnvntrip.plugin.dev.commands.category"  
  5.             name="Sample Category">   
  6.       </category>  
<extension
         point="org.eclipse.ui.commands">
      <category
            id="com.vnvntrip.plugin.dev.commands.category"
            name="Sample Category">
      </category>
Java代码 复制代码
  1. <!---创建一个command命令-->   
  2.    <command   
  3.          categoryId="com.vnvntrip.plugin.dev.commands.category"  
  4.          id="com.vnvntrip.plugin.dev.commands.sampleCommand"  
  5.          name="编辑">   
  6.    </command>  
   <!---创建一个command命令-->
      <command
            categoryId="com.vnvntrip.plugin.dev.commands.category"
            id="com.vnvntrip.plugin.dev.commands.sampleCommand"
            name="编辑">
      </command>
Java代码 复制代码
  1.    <command   
  2.          name="Open Mailbox"  
  3.          description="Opens a mailbox"  
  4.          categoryId="com.vnvntrip.plugin.dev.commands.category"  
  5.          id="com.vnvntrip.plugin.dev.commands.category.open">   
  6.    </command>   
  7.    <command   
  8.          name="Open Message Dialog"  
  9.          description="Open a message dialog"  
  10.          categoryId="com.vnvntrip.plugin.dev.commands.category"  
  11.          id="com.vnvntrip.plugin.dev.commands.category.openMessage">   
  12.    </command>   
  13.       
  14.       
  15. </extension>  
      <command
            name="Open Mailbox"
            description="Opens a mailbox"
            categoryId="com.vnvntrip.plugin.dev.commands.category"
            id="com.vnvntrip.plugin.dev.commands.category.open">
      </command>
      <command
            name="Open Message Dialog"
            description="Open a message dialog"
            categoryId="com.vnvntrip.plugin.dev.commands.category"
            id="com.vnvntrip.plugin.dev.commands.category.openMessage">
      </command>
      
      
   </extension>
Java代码 复制代码
  1. <!---使用处理器(Handler)绑定Command--->   
  2.    <extension   
  3.          point="org.eclipse.ui.handlers">   
  4.       <handler   
  5.             class="com.vnvntrip.plugin.dev.handlers.SampleHandler"  
  6.             commandId="com.vnvntrip.plugin.dev.commands.sampleCommand">   
  7.       </handler>   
  8.    </extension>  
<!---使用处理器(Handler)绑定Command--->
   <extension
         point="org.eclipse.ui.handlers">
      <handler
            class="com.vnvntrip.plugin.dev.handlers.SampleHandler"
            commandId="com.vnvntrip.plugin.dev.commands.sampleCommand">
      </handler>
   </extension>
Java代码 复制代码
  1. <extension   
  2.       point="org.eclipse.ui.bindings">  
   <extension
         point="org.eclipse.ui.bindings">
Java代码 复制代码
  1. <!---绑定相应的快捷键-->   
  2.       <key   
  3.             commandId="com.vnvntrip.plugin.dev.commands.sampleCommand"  
  4.             contextId="org.eclipse.ui.contexts.window"  
  5.             schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"  
  6.             sequence="M1+6">   
  7.       </key>   
  8.          
  9.        <key   
  10.             commandId="com.vnvntrip.plugin.dev.commands.category.open"  
  11.             schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"  
  12.             sequence="CTRL+2">   
  13.       </key>   
  14.       <key   
  15.             commandId="com.vnvntrip.plugin.dev.commands.category.openMessage"  
  16.             schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"  
  17.             sequence="CTRL+3">   
  18.       </key>   
  19.       <key   
  20.             commandId="org.eclipse.ui.file.exit"  
  21.             schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"  
  22.             sequence="CTRL+X">   
  23.       </key>   
  24.    </extension>   
  25.       
  26.    <extension   
  27.          point="org.eclipse.ui.menus">   
  28.       <menuContribution   
  29.             locationURI="menu:org.eclipse.ui.main.menu?after=additions">  
<!---绑定相应的快捷键-->
      <key
            commandId="com.vnvntrip.plugin.dev.commands.sampleCommand"
            contextId="org.eclipse.ui.contexts.window"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
            sequence="M1+6">
      </key>
      
       <key
            commandId="com.vnvntrip.plugin.dev.commands.category.open"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
            sequence="CTRL+2">
      </key>
      <key
            commandId="com.vnvntrip.plugin.dev.commands.category.openMessage"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
            sequence="CTRL+3">
      </key>
      <key
            commandId="org.eclipse.ui.file.exit"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
            sequence="CTRL+X">
      </key>
   </extension>
   
   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="menu:org.eclipse.ui.main.menu?after=additions">
Java代码 复制代码
  1. <!---创建相关的菜单对象-->   
  2.       <menu   
  3.             id="com.vnvntrip.plugin.dev.menus.sampleMenu"  
  4.             label="编辑"  
  5.             mnemonic="M">  
   <!---创建相关的菜单对象-->
         <menu
               id="com.vnvntrip.plugin.dev.menus.sampleMenu"
               label="编辑"
               mnemonic="M">
Java代码 复制代码
  1.   <!---菜单绑定的命令-->   
  2.    <command   
  3.          commandId="com.vnvntrip.plugin.dev.commands.sampleCommand"  
  4.          id="com.vnvntrip.plugin.dev.menus.sampleCommand"  
  5.          mnemonic="S">   
  6.    </command>   
  7. </menu>   
  8. ;/menuContribution>  
           <!---菜单绑定的命令-->
            <command
                  commandId="com.vnvntrip.plugin.dev.commands.sampleCommand"
                  id="com.vnvntrip.plugin.dev.menus.sampleCommand"
                  mnemonic="S">
            </command>
         </menu>
      </menuContribution>
Java代码 复制代码
  1.    <menuContribution   
  2.          locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">   
  3.       <toolbar   
  4.             id="com.vnvntrip.plugin.dev.toolbars.sampleToolbar">   
  5.          <command   
  6.                commandId="com.vnvntrip.plugin.dev.commands.sampleCommand"  
  7.                icon="icons/sample.gif"  
  8.                id="com.vnvntrip.plugin.dev.toolbars.sampleCommand"  
  9.                tooltip="Say hello world">   
  10.          </command>   
  11.       </toolbar>   
  12.    </menuContribution>   
  13. </extension>  
      <menuContribution
            locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
         <toolbar
               id="com.vnvntrip.plugin.dev.toolbars.sampleToolbar">
            <command
                  commandId="com.vnvntrip.plugin.dev.commands.sampleCommand"
                  icon="icons/sample.gif"
                  id="com.vnvntrip.plugin.dev.toolbars.sampleCommand"
                  tooltip="Say hello world">
            </command>
         </toolbar>
      </menuContribution>
   </extension>

 

  在编码是仅仅需要编写Handler中的代码:

 


 

Java代码 复制代码
  1. package com.vnvntrip.plugin.dev.handlers;   
  2.   
  3. import org.eclipse.core.commands.AbstractHandler;   
  4. import org.eclipse.core.commands.ExecutionEvent;   
  5. import org.eclipse.core.commands.ExecutionException;   
  6. import org.eclipse.swt.widgets.Shell;   
  7. import org.eclipse.ui.handlers.HandlerUtil;   
  8. import org.eclipse.ui.internal.dialogs.WorkbenchPreferenceDialog;   
  9.   
  10. /**  
  11.  *   
  12.  * @author longgangbai  
  13.  *  
  14.  */  
  15. public class SampleHandler extends AbstractHandler {   
  16.     private static String CUSTOMPROPERTYPAGE = "com.vnvntrip.plugin.dev.properties.CustomPropertyPage";   
  17.   
  18.     /**  
  19.      * The constructor.  
  20.      */  
  21.     public SampleHandler() {   
  22.     }   
  23.   
  24.     /**  
  25.      * the command has been executed, so extract extract the needed information  
  26.      * from the application context.  
  27.      */  
  28.     public Object execute(ExecutionEvent event) throws ExecutionException {   
  29.     Shell shell = HandlerUtil.getActiveShell(event);   
  30.     // JfaceDialog dialog=new JfaceDialog(shell);   
  31.     // dialog.open();   
  32.     //WorkbenchPreferenceDialog.createDialogOn(shell, preferencePageId)   
  33.     WorkbenchPreferenceDialog dialog = WorkbenchPreferenceDialog   
  34.         .createDialogOn(shell, CUSTOMPROPERTYPAGE);   
  35.     dialog.showOnly(new String[] { CUSTOMPROPERTYPAGE });   
  36.     dialog.open();   
  37.     return null;   
  38.     }   
  39. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值