9910

单飞

   :: 首页 :: 联系 :: 聚合  :: 管理
因为TreeView要增加一个弹出菜单来
Java代码
 1 private void createContextMenu(Composite parent) {
 2         MenuManager mgr = new MenuManager();
 3         mgr.setRemoveAllWhenShown(true);
 4         final EntityTreeView tree = this;
 5         mgr.addMenuListener(new IMenuListener() {
 6             public void menuAboutToShow(IMenuManager manager) {
 7                 // TODO Auto-generated method stub
 8                 ISelection selection = tree.getSelection();
 9                 if(selection instanceof IStructuredSelection){
10                     IStructuredSelection incoming = (IStructuredSelection)selection;
11                     if(incoming.size() >0 && incoming.getFirstElement() instanceof AbstractEntity){    
12                         selectedEntity = (AbstractEntity)incoming.getFirstElement();
13                         fillContextMenu(manager,selectedEntity);        
14                     }
15                 }
16                 
17             }
18 
19         });
20 
21         org.eclipse.swt.widgets.Menu menu = mgr.createContextMenu(this.getControl());
22         this.getControl().setMenu(menu);
23         getViewSite().registerContextMenu(mgr, this);
24     }
25 
26     private void fillContextMenu(IMenuManager manager,AbstractEntity selectedEntity) {
27         org.eclipse.jface.action.IContributionItem items[] = getViewSite().getActionBars().getMenuManager().getItems();
28         for (IContributionItem item : items) {
29             if(item instanceof PluginActionContributionItem){
30                 PluginActionContributionItem pitem = (PluginActionContributionItem)item;
31                 if(selectedEntity instanceof CategoryModel){
32                     if ("com.test.actions.RefreshViewActionDelegate".equals(pitem.getAction().getId())){
33                         manager.add(item);
34                         continue;
35                     }
36                 }                
37     
38             }
39             
40             
41         }
42     }

plugin.xml

<extension
         
point="org.eclipse.ui.viewActions">
      
<viewContribution
            
id="com.test.EntityContribution"
            targetID
="com.test.View">
         
<action
               
class="com.etest.actions.AddActionDelegate"
               icon
="icons/action.gif"
               id
="com.etest.actions.AddActionDelegate"
               label
="Add"
               menubarPath
="category"
               style
="push">
         
</action>
targetID指定那个View会获取到这些action
如果指定一个toolbarPath
就会在NavigatorBar显示这些action
posted on 2008-04-20 10:24 单飞 阅读(762) 评论(0)  编辑  收藏 所属分类: Eclipse Plugin

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


网站导航: