1 11 package org.eclipse.ui.internal; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.ui.IActionBars; 16 import org.eclipse.ui.IViewPart; 17 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; 18 19 23 public class ViewActionBuilder extends PluginActionBuilder { 24 public static final String TAG_CONTRIBUTION_TYPE = "viewContribution"; 26 private IViewPart targetPart; 27 28 31 public ViewActionBuilder() { 32 } 33 34 37 private void contributeToPart(IViewPart part) { 38 IActionBars bars = part.getViewSite().getActionBars(); 39 contribute(bars.getMenuManager(), bars.getToolBarManager(), true); 40 } 41 42 45 protected ActionDescriptor createActionDescriptor( 46 org.eclipse.core.runtime.IConfigurationElement element) { 47 return new ActionDescriptor(element, ActionDescriptor.T_VIEW, 48 targetPart); 49 } 50 51 54 public ActionDescriptor[] getExtendedActions() { 55 if (cache == null) { 56 return new ActionDescriptor[0]; 57 } 58 59 ArrayList results = new ArrayList (); 60 for (int i = 0; i < cache.size(); i++) { 61 BasicContribution bc = (BasicContribution) cache.get(i); 62 if (bc.actions != null) { 63 results.addAll(bc.actions); 64 } 65 } 66 return (ActionDescriptor[]) results 67 .toArray(new ActionDescriptor[results.size()]); 68 } 69 70 74 public void readActionExtensions(IViewPart viewPart) { 75 targetPart = viewPart; 76 readContributions(viewPart.getSite().getId(), TAG_CONTRIBUTION_TYPE, 77 IWorkbenchRegistryConstants.PL_VIEW_ACTIONS); 78 contributeToPart(targetPart); 79 } 80 81 public void dispose() { 82 if (cache != null) { 83 for (int i = 0; i < cache.size(); i++) { 84 ((BasicContribution) cache.get(i)).disposeActions(); 85 } 86 } 87 } 88 } 89 | Popular Tags |