---
title: "Eclpse_plugin 开发笔记_Action_Enable"
author: "xcc313"
date: "2011-11-09T10:21:47Z"
tags: []
categories: ["开源软件"]
slug: "eclpse-plugin-action-enable"
draft: false
lastmod: "2011-11-09T10:21:47Z"
id: 1245020
url: "https://xcc313.iteye.com/blog/1245020"
---

1.Action ID 获取  
        IViewPart homeworkView =            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.xcc.zzu\_wmp.views.HomeWorkView");  
         IActionBars bars = homeworkView.getViewSite().getActionBars();  
         IToolBarManager actios = bars.getToolBarManager();  
         ActionContributionItem contribut = (ActionContributionItem)

         actios.find(PreferenceConstants.P\_ZZU\_REFRESH);  
         contribut.getAction().setEnabled(true);

 

 

        refresh = new Action( {});

        refresh.setEnabled(false);  
        refresh.setId(PreferenceConstants.P\_ZZU\_REFRESH);

2\. ActionSet ID 获取  
                           
                    IWorkbench wb=PlatformUI.getWorkbench();  
                    List&lt;String&gt; actionIDs= new ArrayList&lt;String&gt;();  
                    actionIDs.add(PreferenceConstants.P\_ZZU\_SAVE);  
                    actionIDs.add(PreferenceConstants.P\_ZZU\_DOWNLOAD);  
                    actionIDs.add(PreferenceConstants.P\_ZZU\_UPLOAD);  
                     
                    ActionPresentation ap = ((WorkbenchWindow) wb.getActiveWorkbenchWindow()) .getActionPresentation();  
                    IActionSet\[] sets = ap.getActionSets();  
                    if (sets != null) {  
                        for (IActionSet set : sets) {  
                            PluginActionSet pas = (PluginActionSet) set;  
                            IAction\[] actions = pas.getPluginActions();  
                            if (actions != null&& pas.getDesc().getId().endsWith(PreferenceConstants.P\_ZZU\_ACTIONSET)) {//ActionSetID  
                                for (IAction action : actions) {  
                                    if (actionIDs.contains(action.getId())) {  
                                        action.setEnabled(store.getBoolean(PreferenceConstants.P\_ZZU\_ISLOGIN));  
                                    }  
                                }  
                            }  
                     }  
                        }