KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > ResumeActionDelegate


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.actions;
12
13
14 import java.util.Iterator JavaDoc;
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     /**
25      * @see AbstractDebugActionDelegate#doAction(Object)
26      */

27     protected void doAction(Object JavaDoc object) throws DebugException {
28         if (isEnabledFor(object)) {
29             ISuspendResume resume = (ISuspendResume)object;
30             resume.resume();
31         } else {
32             doActionForAllThreads(object);
33         }
34     }
35     
36     /**
37      * Resumes all threads in the target associated with the given element
38      *
39      * @param object debug element
40      * @throws DebugException on failure
41      */

42     protected void doActionForAllThreads(Object JavaDoc 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     /**
56      * @see AbstractDebugActionDelegate#isRunInBackground()
57      */

58     protected boolean isRunInBackground() {
59         return true;
60     }
61
62     /**
63      * @see AbstractDebugActionDelegate#isEnabledFor(Object)
64      */

65     protected boolean isEnabledFor(Object JavaDoc element) {
66         return element instanceof ISuspendResume && ((ISuspendResume) element).canResume();
67     }
68
69     /**
70      * @see AbstractDebugActionDelegate#getEnableStateForSelection(IStructuredSelection)
71      */

72     protected boolean getEnableStateForSelection(IStructuredSelection selection) {
73         if (selection.isEmpty()) {
74             return false;
75         }
76         for (Iterator JavaDoc i = selection.iterator(); i.hasNext(); ) {
77             Object JavaDoc element = i.next();
78             if (!(isEnabledFor(element) || isEnabledForAllThreads(element))) {
79                 return false;
80             }
81         }
82         return true;
83     }
84
85     /**
86      * Returns whether 'resume all threads' should be enabled for the given element.
87      */

88     protected boolean isEnabledForAllThreads(Object JavaDoc 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     /**
105      * @see AbstractDebugActionDelegate#getStatusMessage()
106      */

107     protected String JavaDoc getStatusMessage() {
108         return ActionMessages.ResumeActionDelegate_Exceptions_occurred_attempting_to_resume__2; //$NON-NLS-1$
109
}
110
111     /**
112      * @see AbstractDebugActionDelegate#getErrorDialogMessage()
113      */

114     protected String JavaDoc getErrorDialogMessage() {
115         return ActionMessages.ResumeActionDelegate_Resume_failed__1; //$NON-NLS-1$
116
}
117
118 }
119
Popular Tags