1 11 package org.eclipse.debug.internal.ui.actions; 12 13 import org.eclipse.core.runtime.IAdaptable; 14 import org.eclipse.debug.core.ILaunch; 15 import org.eclipse.debug.core.model.IDebugElement; 16 import org.eclipse.debug.internal.ui.DebugUIPlugin; 17 import org.eclipse.debug.ui.DebugUITools; 18 import org.eclipse.jface.action.IAction; 19 import org.eclipse.jface.action.IStatusLineManager; 20 import org.eclipse.jface.viewers.ISelection; 21 import org.eclipse.jface.viewers.IStructuredSelection; 22 import org.eclipse.swt.widgets.Display; 23 import org.eclipse.swt.widgets.Event; 24 import org.eclipse.ui.IActionDelegate2; 25 import org.eclipse.ui.IObjectActionDelegate; 26 import org.eclipse.ui.IViewPart; 27 import org.eclipse.ui.IViewSite; 28 import org.eclipse.ui.IWorkbenchPage; 29 import org.eclipse.ui.IWorkbenchPart; 30 31 35 public abstract class WatchExpressionAction implements IObjectActionDelegate, IActionDelegate2 { 36 IWorkbenchPart fPart = null; 37 40 protected IDebugElement getContext() { 41 IAdaptable object = DebugUITools.getDebugContext(); 42 IDebugElement context = null; 43 if (object instanceof IDebugElement) { 44 context = (IDebugElement) object; 45 } else if (object instanceof ILaunch) { 46 context = ((ILaunch) object).getDebugTarget(); 47 } 48 return context; 49 } 50 53 public void setActivePart(IAction action, IWorkbenchPart targetPart) { 54 fPart = targetPart; 55 } 56 57 60 public void selectionChanged(IAction action, ISelection sel) { 61 } 62 63 protected IStructuredSelection getCurrentSelection() { 64 IWorkbenchPage page = DebugUIPlugin.getActiveWorkbenchWindow().getActivePage(); 65 if (page != null) { 66 ISelection selection = page.getSelection(); 67 if (selection instanceof IStructuredSelection) { 68 return (IStructuredSelection) selection; 69 } 70 } 71 return null; 72 } 73 74 79 protected void showErrorMessage(String message) { 80 if (fPart instanceof IViewPart) { 81 IViewSite viewSite = ((IViewPart) fPart).getViewSite(); 82 IStatusLineManager manager = viewSite.getActionBars().getStatusLineManager(); 83 manager.setErrorMessage(message); 84 Display.getCurrent().beep(); 85 } 86 } 87 88 91 public void dispose() { 92 fPart = null; 93 } 94 95 98 public void init(IAction action) { 99 } 100 101 104 public void runWithEvent(IAction action, Event event) { 105 run(action); 106 } 107 } 108 | Popular Tags |