zoukankan      html  css  js  c++  java
  • RCP表单编辑器---》二、添加编辑器的菜单和工具

    对于编辑器,也可以设置编辑器所对应的菜单、工具栏和上下文菜单。实现这些功能需要实现IEditorActionBarContributor接口,EditorActionBarContributor类实现了该接口。代码如下:

    1、添加JsEditorContributor.java

    package com.testrcp.myrcp.editors;
    import org.eclipse.jface.action.Action;
    import org.eclipse.jface.action.IMenuManager;
    import org.eclipse.jface.action.IToolBarManager;
    import org.eclipse.jface.action.MenuManager;
    import org.eclipse.ui.ISharedImages;
    import org.eclipse.ui.PlatformUI;
    import org.eclipse.ui.part.EditorActionBarContributor;
    
    public class JsEditorContributor extends EditorActionBarContributor {
    	private Action action1 ;
    	private Action action2 ;
    	public JsEditorContributor() {
    		super();
    		makeActions();
    	}
    	
    	public void makeActions() {
    		action1 = new Action() {
    			public void run() {
    				
    			}
    		};
    		action1.setText("Action 1");
    		action1.setToolTipText("Action 1 tooltip");
    		action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
    				getImageDescriptor(ISharedImages.IMG_DEF_VIEW));
    		
    		action2 = new Action() {
    			public void run() {
    				
    			}
    		};
    		action2.setText("Action 2");
    		action2.setToolTipText("Action 2 tooltip");
    		action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
    				getImageDescriptor(ISharedImages.IMG_OBJS_WARN_TSK));
    		
    	}
    	
    	//覆盖父类中的方法,创建菜单
    	public void contributeToMenu(IMenuManager menuManager) {
    		MenuManager editMenu = new MenuManager("编辑器菜单");
    		editMenu.add( action1 );
    		editMenu.add( action2 );
    		menuManager.add( editMenu );
    	}
    	
    	//覆盖父类的方法,创建工具栏
    	public void contributeToToolBar(IToolBarManager toolBarManager) {
    		toolBarManager.add( action1 );
    		toolBarManager.add( action2 );
    	}
    }
    

    其中,创建菜单栏和工具栏的方法分别是覆盖父类中的contributeToMenu和contributeToToolBar方法。

    2、在Perspective类的createInitialLayout方法中只留下下面两行代码:

       String editorArea = layout.getEditorArea();
       layout.addStandaloneView(OpenEditorView.ID,true,IPageLayout.RIGHT,.3f,editorArea);
    

    3、在plugin.xml中添加如下代码

    <extension
             point="org.eclipse.ui.editors">
          <editor
                class="com.testrcp.myrcp.editors.JsEditor"
                contributorClass="com.testrcp.myrcp.editors.JsEditorContributor"
                default="false"
                icon="icons/alt_about.gif"
                id="com.testrcp.myrcp.editors.JsEditor"
                name="JsEditor">
          </editor>
       </extension>

    4、运行后的显示效果如下:

    a、多次点击“Editor”行,显示效果如下:出现多个Editor

    b、显示出来了“编辑器菜单”的菜单项

     

     5、获取源码

    链接:https://pan.baidu.com/s/1GjtxKitstcsdX2HvBSfJAg
    提取码:oeah

  • 相关阅读:
    忍者x3,SDCMS2.0发布模块,使用说明
    多一度评论 发布模块,如何使用?
    端口站群,泛站,批量,垃圾站,还是x3的营销插件,如何选择?
    忍者X3,今天又更新了很多内容
    准备做淘宝客相关的生成工具。
    怎么样可以方便的获取到网站的ico图标呢?
    ECShop网店系统273发布模块 如何使用?
    站群还是非常火爆的,你看这力度。
    如果对文章的质量进一步把关,发布之前的批量过一遍
    有人做过FLASH验证码识别吗?
  • 原文地址:https://www.cnblogs.com/wwssgg/p/14869682.html
Copyright © 2011-2022 走看看