1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.core.runtime.IConfigurationElement; 14 import org.eclipse.core.runtime.ISafeRunnable; 15 import org.eclipse.core.runtime.Platform; 16 import org.eclipse.ui.IActionDelegate; 17 import org.eclipse.ui.IObjectActionDelegate; 18 import org.eclipse.ui.IWorkbenchPart; 19 20 27 public class ObjectPluginAction extends PluginAction { 28 32 public static final String ATT_OVERRIDE_ACTION_ID = "overrideActionId"; 34 private String overrideActionId; 35 36 private IWorkbenchPart activePart; 37 38 49 public ObjectPluginAction(IConfigurationElement actionElement, String id, 50 int style) { 51 super(actionElement, id, style); 52 overrideActionId = actionElement.getAttribute(ATT_OVERRIDE_ACTION_ID); 53 } 54 55 58 protected void initDelegate() { 59 super.initDelegate(); 60 final IActionDelegate actionDelegate = getDelegate(); 61 if (actionDelegate instanceof IObjectActionDelegate 62 && activePart != null) { 63 final IObjectActionDelegate objectActionDelegate = (IObjectActionDelegate) actionDelegate; 64 final ISafeRunnable runnable = new ISafeRunnable() { 65 public void run() throws Exception { 66 objectActionDelegate.setActivePart(ObjectPluginAction.this, 67 activePart); 68 } 69 70 public void handleException(Throwable exception) { 71 } 73 }; 74 Platform.run(runnable); 75 } 76 } 77 78 88 public void setActivePart(IWorkbenchPart targetPart) { 89 activePart = targetPart; 90 IActionDelegate delegate = getDelegate(); 91 if (delegate instanceof IObjectActionDelegate && activePart != null) { 92 final IObjectActionDelegate objectActionDelegate = (IObjectActionDelegate) delegate; 93 final ISafeRunnable runnable = new ISafeRunnable() { 94 public void run() throws Exception { 95 objectActionDelegate.setActivePart(ObjectPluginAction.this, 96 activePart); 97 } 98 99 public void handleException(Throwable exception) { 100 } 102 }; 103 Platform.run(runnable); 104 } 105 } 106 107 112 public String getOverrideActionId() { 113 return overrideActionId; 114 } 115 } 116 | Popular Tags |