9910

          單飛

             :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
          因?yàn)門reeView要增加一個(gè)彈出菜單來
          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指定那個(gè)View會(huì)獲取到這些action
          如果指定一個(gè)toolbarPath
          就會(huì)在NavigatorBar顯示這些action
          posted on 2008-04-20 10:24 單飛 閱讀(770) 評(píng)論(0)  編輯  收藏 所屬分類: Eclipse Plugin
          主站蜘蛛池模板: 临沭县| 化州市| 承德市| 德庆县| 依安县| 黄陵县| 内江市| 海兴县| 湖州市| 治县。| 安乡县| 临洮县| 朝阳县| 大同市| 彭山县| 石门县| 马鞍山市| 和顺县| 凉山| 蒙山县| 高邮市| 望江县| 社会| 乐东| 沙洋县| 阿荣旗| 湘乡市| 龙井市| 黄陵县| 应城市| 江孜县| 鸡东县| 巫山县| 彩票| 微山县| 内江市| 兴义市| 高雄县| 青铜峡市| 凭祥市| 天门市|