1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.core.runtime.IConfigurationElement; 14 import org.eclipse.ui.IActionDelegate; 15 import org.eclipse.ui.IEditorActionDelegate; 16 import org.eclipse.ui.IEditorPart; 17 import org.eclipse.ui.WorkbenchException; 18 19 23 public final class EditorPluginAction extends PartPluginAction { 24 private IEditorPart currentEditor; 25 26 30 public EditorPluginAction(IConfigurationElement actionElement, 31 IEditorPart part, String id, int style) { 32 super(actionElement, id, style); 33 if (part != null) { 34 editorChanged(part); 35 } 36 } 37 38 41 protected IActionDelegate validateDelegate(Object obj) 42 throws WorkbenchException { 43 if (obj instanceof IEditorActionDelegate) { 44 return (IEditorActionDelegate) obj; 45 } else { 46 throw new WorkbenchException( 47 "Action must implement IEditorActionDelegate"); } 49 } 50 51 54 protected void initDelegate() { 55 super.initDelegate(); 56 ((IEditorActionDelegate) getDelegate()).setActiveEditor(this, 57 currentEditor); 58 } 59 60 64 public void editorChanged(IEditorPart part) { 65 if (currentEditor != null) { 66 unregisterSelectionListener(currentEditor); 67 } 68 69 currentEditor = part; 70 71 if (getDelegate() == null && isOkToCreateDelegate()) { 72 createDelegate(); 73 } 74 if (getDelegate() != null) { 75 ((IEditorActionDelegate) getDelegate()).setActiveEditor(this, part); 76 } 77 78 if (part != null) { 79 registerSelectionListener(part); 80 } 81 } 82 83 86 public void dispose() { 87 if (currentEditor != null) { 88 unregisterSelectionListener(currentEditor); 89 currentEditor = null; 90 } 91 super.dispose(); 92 } 93 } 94 | Popular Tags |