1 11 package org.eclipse.jdt.internal.debug.ui.actions; 12 13 14 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 15 import org.eclipse.jface.action.IAction; 16 import org.eclipse.jface.action.IStatusLineManager; 17 import org.eclipse.jface.viewers.ISelection; 18 import org.eclipse.jface.viewers.IStructuredSelection; 19 import org.eclipse.swt.widgets.Display; 20 import org.eclipse.swt.widgets.Event; 21 import org.eclipse.ui.IActionDelegate2; 22 import org.eclipse.ui.IObjectActionDelegate; 23 import org.eclipse.ui.IViewPart; 24 import org.eclipse.ui.IViewSite; 25 import org.eclipse.ui.IWorkbenchPage; 26 import org.eclipse.ui.IWorkbenchPart; 27 import org.eclipse.ui.IWorkbenchWindow; 28 29 public abstract class ObjectActionDelegate implements IObjectActionDelegate, IActionDelegate2 { 30 31 IWorkbenchPart fPart = null; 32 33 36 public void setActivePart(IAction action, IWorkbenchPart targetPart) { 37 fPart = targetPart; 38 } 39 40 protected IWorkbenchPart getPart() { 41 return fPart; 42 } 43 44 47 public void selectionChanged(IAction action, ISelection sel) { 48 } 49 50 55 protected IStructuredSelection getCurrentSelection() { 56 IWorkbenchPage page = JDIDebugUIPlugin.getActivePage(); 57 if (page != null) { 58 ISelection selection= page.getSelection(); 59 if (selection instanceof IStructuredSelection) { 60 return (IStructuredSelection)selection; 61 } 62 } 63 return null; 64 } 65 66 71 protected void showErrorMessage(String message) { 72 if (fPart instanceof IViewPart) { 73 IViewSite viewSite = ((IViewPart)fPart).getViewSite(); 74 IStatusLineManager manager = viewSite.getActionBars().getStatusLineManager(); 75 manager.setErrorMessage(message); 76 Display.getCurrent().beep(); 77 } 78 } 79 80 83 public void dispose() { 84 fPart = null; 85 } 86 87 90 public void init(IAction action) { 91 } 92 93 96 public void runWithEvent(IAction action, Event event) { 97 run(action); 98 } 99 100 103 protected IWorkbenchWindow getWorkbenchWindow() { 104 if (fPart != null) { 105 return fPart.getSite().getWorkbenchWindow(); 106 } 107 return null; 108 } 109 } 110 | Popular Tags |