1 11 package org.eclipse.debug.internal.ui.actions; 12 13 14 import java.util.Iterator ; 15 16 import org.eclipse.debug.core.DebugException; 17 import org.eclipse.debug.core.model.IDebugElement; 18 import org.eclipse.debug.core.model.ISuspendResume; 19 import org.eclipse.debug.core.model.IThread; 20 import org.eclipse.jface.viewers.IStructuredSelection; 21 22 public class ResumeActionDelegate extends AbstractListenerActionDelegate { 23 24 27 protected void doAction(Object object) throws DebugException { 28 if (isEnabledFor(object)) { 29 ISuspendResume resume = (ISuspendResume)object; 30 resume.resume(); 31 } else { 32 doActionForAllThreads(object); 33 } 34 } 35 36 42 protected void doActionForAllThreads(Object object) throws DebugException { 43 if (isEnabledForAllThreads(object)) { 44 IDebugElement debugElement = (IDebugElement) object; 45 IThread[] threads = debugElement.getDebugTarget().getThreads(); 46 for (int i = 0; i < threads.length; i++) { 47 IThread thread = threads[i]; 48 if (thread.canResume()) { 49 thread.resume(); 50 } 51 } 52 } 53 } 54 55 58 protected boolean isRunInBackground() { 59 return true; 60 } 61 62 65 protected boolean isEnabledFor(Object element) { 66 return element instanceof ISuspendResume && ((ISuspendResume) element).canResume(); 67 } 68 69 72 protected boolean getEnableStateForSelection(IStructuredSelection selection) { 73 if (selection.isEmpty()) { 74 return false; 75 } 76 for (Iterator i = selection.iterator(); i.hasNext(); ) { 77 Object element = i.next(); 78 if (!(isEnabledFor(element) || isEnabledForAllThreads(element))) { 79 return false; 80 } 81 } 82 return true; 83 } 84 85 88 protected boolean isEnabledForAllThreads(Object element) { 89 if (element instanceof IDebugElement) { 90 IDebugElement debugElement = (IDebugElement) element; 91 try { 92 IThread[] threads = debugElement.getDebugTarget().getThreads(); 93 for (int i = 0; i < threads.length; i++) { 94 if (threads[i].canResume()) { 95 return true; 96 } 97 } 98 } catch (DebugException e) { 99 } 100 } 101 return false; 102 } 103 104 107 protected String getStatusMessage() { 108 return ActionMessages.ResumeActionDelegate_Exceptions_occurred_attempting_to_resume__2; } 110 111 114 protected String getErrorDialogMessage() { 115 return ActionMessages.ResumeActionDelegate_Resume_failed__1; } 117 118 } 119 | Popular Tags |