1 11 package org.eclipse.debug.internal.ui.actions; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.debug.core.model.ISuspendResume; 15 import org.eclipse.debug.ui.DebugUITools; 16 import org.eclipse.debug.ui.actions.IRunToLineTarget; 17 import org.eclipse.debug.ui.contexts.DebugContextEvent; 18 import org.eclipse.debug.ui.contexts.IDebugContextListener; 19 import org.eclipse.debug.ui.contexts.IDebugContextService; 20 import org.eclipse.jface.action.IAction; 21 import org.eclipse.jface.viewers.ISelection; 22 import org.eclipse.jface.viewers.IStructuredSelection; 23 import org.eclipse.ui.IWorkbenchPart; 24 import org.eclipse.ui.IWorkbenchWindow; 25 26 31 public class RetargetRunToLineAction extends RetargetAction { 32 33 private DebugContextListener fContextListener = new DebugContextListener(); 34 private ISuspendResume fTargetElement = null; 35 36 class DebugContextListener implements IDebugContextListener { 37 38 protected void contextActivated(ISelection selection) { 39 fTargetElement = null; 40 if (selection instanceof IStructuredSelection) { 41 IStructuredSelection ss = (IStructuredSelection) selection; 42 if (ss.size() == 1) { 43 Object object = ss.getFirstElement(); 44 if (object instanceof ISuspendResume) { 45 fTargetElement = (ISuspendResume) object; 46 } 47 } 48 } 49 IAction action = getAction(); 50 if (action != null) { 51 action.setEnabled(fTargetElement != null && hasTargetAdapter()); 52 } 53 } 54 55 public void debugContextChanged(DebugContextEvent event) { 56 contextActivated(event.getContext()); 57 } 58 59 60 } 61 62 65 public void dispose() { 66 DebugUITools.getDebugContextManager().getContextService(fWindow).removeDebugContextListener(fContextListener); 67 super.dispose(); 68 } 69 72 public void init(IWorkbenchWindow window) { 73 super.init(window); 74 IDebugContextService service = DebugUITools.getDebugContextManager().getContextService(window); 75 service.addDebugContextListener(fContextListener); 76 ISelection activeContext = service.getActiveContext(); 77 fContextListener.contextActivated(activeContext); 78 } 79 80 83 protected boolean canPerformAction(Object target, ISelection selection, IWorkbenchPart part) { 84 return fTargetElement != null && 85 ((IRunToLineTarget)target).canRunToLine(part, selection, fTargetElement); 86 } 87 88 91 protected Class getAdapterClass() { 92 return IRunToLineTarget.class; 93 } 94 97 protected void performAction(Object target, ISelection selection, IWorkbenchPart part) throws CoreException { 98 ((IRunToLineTarget)target).runToLine(part, selection, fTargetElement); 99 } 100 101 104 protected String getOperationUnavailableMessage() { 105 return ActionMessages.RetargetRunToLineAction_0; 106 } 107 108 111 public void selectionChanged(IAction action, ISelection selection) { 112 if (fTargetElement == null) { 113 action.setEnabled(false); 114 } else { 115 super.selectionChanged(action, selection); 116 } 117 } 118 } 119 | Popular Tags |