posts - 31,  comments - 31,  trackbacks - 0

1、编制菜单: 
     每个Plug-In可以包括一个MenuBar(菜单)、CoolBar(工具栏)、PerspectiveBar(面板栏)、FastViewBar(快速视图栏),这些栏目是在Plug-In运行过程中不会改变的,MenuBar(菜单)由ApplicationActionBarAdvisor类的fillMenuBar()方法定义,例:

            MenuManager fileMenu = new MenuManager("&File", IWorkbenchActionConstants.M_FILE);
            fileMenu.add(new Separator());
        fileMenu.add(newViewAction);

CoolBar(工具栏)由ApplicationActionBarAdvisor类的fillCoolBar()方法定义,例:

IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT); 
toolbar.add(newViewAction);


PerspectiveBar由PlugIn.xml文件中关于Perspective的配置自动生成,FastViweBar由PlugIn.xml文件中关于View的配置自动生成,MenuBar和CoolBar中各个功能按钮的action在ApplicationActionBarAdvisor类的makeActions()方法中注册。例:

newViewAction  =   new  OpenNewViewAction(window,  " 打开新视图菜单 " , IEntryID.NEW_VIEW_ID);
        register(newViewAction);


2、编写面板和视图: 
      在Plug-In运行过程中Perspective(面板),View(视图)会被经常切换,其中Perspective由若干个View组成,Perspective要实现IPerspectiveFactory接口,并在Perspective中定义要加载的View。View要继承ViewPart类,View还要有一个唯一的ID。并把Perspective和View在PlugIn.xml作注册。例:

< extension    point ="org.eclipse.ui.views" >
< view
            
name ="新打开的视图"
            allowMultiple
="true"
            icon
="icons/sample3.gif"
            class
="uuu.NewView"
            id
="uuu.NewView" >
      
</ view >
</ extension >
   
< extension     point ="org.eclipse.ui.perspectives" >
      
< perspective
            
name ="New Perspective"
            class
="uuu.NewPerspective"
            id
="uuu.NewPerspective" >
      
</ perspective >
   
</ extension >

3、添加action
编写一个继承了Action的XXXaction类,再此之前先定义一个接口,如下:

public   interface  IEntryID  {

    
public   static   final  String NEW_VIEW_ID  =   " uuu.NewView " ;
    
public   static   final  String CMD_OPEN_NEW_VIEW  =   " uuu.OpenNewView " ;    
}

实现XXXaction的构造函数,如下:

this .window  =  window;
        
this .viewId  =  viewId;
        setText(label);
        
//  The id is used to refer to the action in a menu or toolbar
        setId(IEntryID.CMD_OPEN_NEW_VIEW);
        
//  Associate the action with a pre-defined command, to allow key bindings.
        setActionDefinitionId(ICommandIds.CMD_OPEN);
        setImageDescriptor(uuu.Activator.getImageDescriptor(
" /icons/sample2.gif " ));

在PlugIn.xml中添加相应的配置:

< extension       point ="org.eclipse.ui.commands" >
        
< command
            
name ="打开新视图"
            description
="打开一个新的视图"
            categoryId
="uuu.OpenNewView"
            id
="uuu.OpenNewView" >
      
</ command >
    
</ extension  >

4、显示工具栏:
在ApplicationWorkbenchWindowAdvisor类的preWindowOpen();方法中添加
 

 configurer.setShowCoolBar( true );
 configurer.setShowPerspectiveBar(
true );
 configurer.setShowFastViewBars(
true );
posted on 2007-01-31 14:33 小平 阅读(340) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 
<2007年1月>
31123456
78910111213
14151617181920
21222324252627
28293031123
45678910

常用链接

留言簿(2)

随笔分类

随笔档案

framework

j2me

java

linux

web

其他

友情链接

素材

最新评论

阅读排行榜

评论排行榜