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.IViewActionDelegate; 16 import org.eclipse.ui.IViewPart; 17 import org.eclipse.ui.WorkbenchException; 18 19 27 public final class ViewPluginAction extends PartPluginAction { 28 private IViewPart viewPart; 29 30 34 public ViewPluginAction(IConfigurationElement actionElement, 35 IViewPart viewPart, String id, int style) { 36 super(actionElement, id, style); 37 this.viewPart = viewPart; 38 registerSelectionListener(viewPart); 39 } 40 41 44 protected IActionDelegate validateDelegate(Object obj) 45 throws WorkbenchException { 46 if (obj instanceof IViewActionDelegate) { 47 return (IViewActionDelegate) obj; 48 } else { 49 throw new WorkbenchException( 50 "Action must implement IViewActionDelegate"); } 52 } 53 54 57 protected void initDelegate() { 58 super.initDelegate(); 59 ((IViewActionDelegate) getDelegate()).init(viewPart); 60 } 61 62 68 public boolean isOkToCreateDelegate() { 69 return super.isOkToCreateDelegate() && viewPart != null; 70 } 71 72 75 public void dispose() { 76 unregisterSelectionListener(viewPart); 77 super.dispose(); 78 } 79 } 80 | Popular Tags |