`
longgangbai
  • 浏览: 7259079 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

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

阅读更多
           RCP关于配置方式在菜单栏创建菜单
<extension
         point="org.eclipse.ui.commands">
      <category
            id="com.vnvntrip.plugin.dev.commands.category"
            name="Sample Category">
      </category>
   <!---创建一个command命令-->
      <command
            categoryId="com.vnvntrip.plugin.dev.commands.category"
            id="com.vnvntrip.plugin.dev.commands.sampleCommand"
            name="编辑">
      </command>
      <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>
<!---使用处理器(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>
   <extension
         point="org.eclipse.ui.bindings">
<!---绑定相应的快捷键-->
      <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">
   <!---创建相关的菜单对象-->
         <menu
               id="com.vnvntrip.plugin.dev.menus.sampleMenu"
               label="编辑"
               mnemonic="M">
           <!---菜单绑定的命令-->
            <command
                  commandId="com.vnvntrip.plugin.dev.commands.sampleCommand"
                  id="com.vnvntrip.plugin.dev.menus.sampleCommand"
                  mnemonic="S">
            </command>
         </menu>
      </menuContribution>
      <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中的代码:

 


 

package com.vnvntrip.plugin.dev.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.internal.dialogs.WorkbenchPreferenceDialog;

/**
 * 
 * @author longgangbai
 *
 */
public class SampleHandler extends AbstractHandler {
    private static String CUSTOMPROPERTYPAGE = "com.vnvntrip.plugin.dev.properties.CustomPropertyPage";

    /**
     * The constructor.
     */
    public SampleHandler() {
    }

    /**
     * the command has been executed, so extract extract the needed information
     * from the application context.
     */
    public Object execute(ExecutionEvent event) throws ExecutionException {
	Shell shell = HandlerUtil.getActiveShell(event);
	// JfaceDialog dialog=new JfaceDialog(shell);
	// dialog.open();
	//WorkbenchPreferenceDialog.createDialogOn(shell, preferencePageId)
	WorkbenchPreferenceDialog dialog = WorkbenchPreferenceDialog
		.createDialogOn(shell, CUSTOMPROPERTYPAGE);
	dialog.showOnly(new String[] { CUSTOMPROPERTYPAGE });
	dialog.open();
	return null;
    }
}

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics