1 11 package org.eclipse.ui.internal; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.runtime.IConfigurationElement; 16 import org.eclipse.ui.IActionBars; 17 import org.eclipse.ui.IEditorActionBarContributor; 18 import org.eclipse.ui.IEditorDescriptor; 19 import org.eclipse.ui.IEditorPart; 20 import org.eclipse.ui.IWorkbenchPage; 21 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; 22 23 27 public class EditorActionBuilder extends PluginActionBuilder { 28 private static final String TAG_CONTRIBUTION_TYPE = "editorContribution"; 30 33 public EditorActionBuilder() { 34 } 35 36 39 protected ActionDescriptor createActionDescriptor( 40 IConfigurationElement element) { 41 return new ActionDescriptor(element, ActionDescriptor.T_EDITOR); 42 } 43 44 47 protected BasicContribution createContribution() { 48 return new EditorContribution(); 49 } 50 51 55 public IEditorActionBarContributor readActionExtensions( 56 IEditorDescriptor desc) { 57 ExternalContributor ext = null; 58 readContributions(desc.getId(), TAG_CONTRIBUTION_TYPE, 59 IWorkbenchRegistryConstants.PL_EDITOR_ACTIONS); 60 if (cache != null) { 61 ext = new ExternalContributor(cache); 62 cache = null; 63 } 64 return ext; 65 } 66 67 71 private static class EditorContribution extends BasicContribution { 72 public void dispose() { 73 disposeActions(); 74 super.dispose(); 75 } 76 77 public void editorChanged(IEditorPart editor) { 78 if (actions != null) { 79 for (int i = 0; i < actions.size(); i++) { 80 ActionDescriptor ad = (ActionDescriptor) actions.get(i); 81 EditorPluginAction action = (EditorPluginAction) ad 82 .getAction(); 83 action.editorChanged(editor); 84 } 85 } 86 } 87 } 88 89 93 public static class ExternalContributor implements 94 IEditorActionBarContributor { 95 private ArrayList cache; 96 97 public ExternalContributor(ArrayList cache) { 98 this.cache = cache; 99 } 100 101 public void dispose() { 102 for (int i = 0; i < cache.size(); i++) { 103 ((EditorContribution) cache.get(i)).dispose(); 104 } 105 } 106 107 public ActionDescriptor[] getExtendedActions() { 108 ArrayList results = new ArrayList (); 109 for (int i = 0; i < cache.size(); i++) { 110 EditorContribution ec = (EditorContribution) cache.get(i); 111 if (ec.actions != null) { 112 results.addAll(ec.actions); 113 } 114 } 115 return (ActionDescriptor[]) results 116 .toArray(new ActionDescriptor[results.size()]); 117 } 118 119 public void init(IActionBars bars, IWorkbenchPage page) { 120 for (int i = 0; i < cache.size(); i++) { 121 ((EditorContribution) cache.get(i)).contribute(bars 122 .getMenuManager(), false, bars.getToolBarManager(), 123 true); 124 } 125 } 126 127 public void setActiveEditor(IEditorPart editor) { 128 for (int i = 0; i < cache.size(); i++) { 129 ((EditorContribution) cache.get(i)).editorChanged(editor); 130 } 131 } 132 } 133 } 134 | Popular Tags |