KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > context > ResumeAction


1 /*******************************************************************************
2  * Copyright (c) 2006 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.context;
12
13 import org.eclipse.core.runtime.IAdaptable;
14 import org.eclipse.debug.core.DebugException;
15 import org.eclipse.debug.core.model.IDebugElement;
16 import org.eclipse.debug.core.model.IThread;
17 import org.eclipse.debug.internal.ui.DebugPluginImages;
18 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
19 import org.eclipse.debug.internal.ui.actions.ActionMessages;
20 import org.eclipse.debug.internal.ui.actions.provisional.IAsynchronousSuspendResumeAdapter;
21 import org.eclipse.debug.internal.ui.actions.provisional.IBooleanRequestMonitor;
22 import org.eclipse.jface.resource.ImageDescriptor;
23
24 public class ResumeAction extends AbstractDebugContextAction {
25
26     /*
27      * (non-Javadoc)
28      * @see org.eclipse.debug.internal.ui.actions.context.AbstractDebugContextAction#doAction(java.lang.Object)
29      */

30     protected void doAction(Object JavaDoc element) {
31         if (element instanceof IAdaptable) {
32             IAdaptable adaptable = (IAdaptable) element;
33             IAsynchronousSuspendResumeAdapter suspendResumer = (IAsynchronousSuspendResumeAdapter) adaptable.getAdapter(IAsynchronousSuspendResumeAdapter.class);
34             if (suspendResumer != null)
35                 suspendResumer.resume(element, new ActionRequestMonitor());
36         }
37     }
38
39     /*
40      * (non-Javadoc)
41      * @see org.eclipse.debug.internal.ui.actions.context.AbstractDebugContextAction#isEnabledFor(java.lang.Object, org.eclipse.debug.internal.ui.actions.provisional.IBooleanRequestMonitor)
42      */

43     protected void isEnabledFor(Object JavaDoc element, IBooleanRequestMonitor monitor) {
44         if (element instanceof IAdaptable) {
45             IAdaptable adaptable = (IAdaptable) element;
46             IAsynchronousSuspendResumeAdapter suspendResumer = (IAsynchronousSuspendResumeAdapter) adaptable.getAdapter(IAsynchronousSuspendResumeAdapter.class);
47             if (suspendResumer != null) {
48                 suspendResumer.canResume(element, monitor);
49             } else {
50                 notSupported(monitor);
51             }
52         }
53     }
54
55
56     /**
57      * Resumes all threads in the target associated with the given element
58      *
59      * @param object
60      * debug element
61      * @throws DebugException
62      * on failure
63      */

64     protected void doActionForAllThreads(Object JavaDoc object) throws DebugException {
65         if (isEnabledForAllThreads(object)) {
66             IDebugElement debugElement = (IDebugElement) object;
67             IThread[] threads = debugElement.getDebugTarget().getThreads();
68             for (int i = 0; i < threads.length; i++) {
69                 IThread thread = threads[i];
70                 if (thread.canResume()) {
71                     thread.resume();
72                 }
73             }
74         }
75     }
76
77     /**
78      * Returns whether 'resume all threads' should be enabled for the given
79      * element.
80      */

81     protected boolean isEnabledForAllThreads(Object JavaDoc element) {
82         if (element instanceof IDebugElement) {
83             IDebugElement debugElement = (IDebugElement) element;
84             try {
85                 IThread[] threads = debugElement.getDebugTarget().getThreads();
86                 for (int i = 0; i < threads.length; i++) {
87                     if (threads[i].canResume()) {
88                         return true;
89                     }
90                 }
91             } catch (DebugException e) {
92             }
93         }
94         return false;
95     }
96
97     /*
98      * (non-Javadoc)
99      * @see org.eclipse.debug.internal.ui.actions.context.AbstractDebugContextAction#getStatusMessage()
100      */

101     protected String JavaDoc getStatusMessage() {
102         return ActionMessages.ResumeActionDelegate_Exceptions_occurred_attempting_to_resume__2;
103     }
104
105     /*
106      * (non-Javadoc)
107      * @see org.eclipse.debug.internal.ui.actions.context.AbstractDebugContextAction#getErrorDialogMessage()
108      */

109     protected String JavaDoc getErrorDialogMessage() {
110         return ActionMessages.ResumeActionDelegate_Resume_failed__1;
111     }
112
113     /*
114      * (non-Javadoc)
115      * @see org.eclipse.debug.internal.ui.actions.context.AbstractDebugContextAction#getText()
116      */

117     public String JavaDoc getText() {
118         return ActionMessages.ResumeAction_0;
119     }
120
121     /*
122      * (non-Javadoc)
123      * @see org.eclipse.debug.internal.ui.actions.context.AbstractDebugContextAction#getHelpContextId()
124      */

125     public String JavaDoc getHelpContextId() {
126         return "resume_action_context"; //$NON-NLS-1$
127
}
128
129     /*
130      * (non-Javadoc)
131      * @see org.eclipse.debug.internal.ui.actions.context.AbstractDebugContextAction#getId()
132      */

133     public String JavaDoc getId() {
134         return "org.eclipse.debug.ui.debugview.toolbar.resume"; //$NON-NLS-1$
135
}
136
137     /*
138      * (non-Javadoc)
139      * @see org.eclipse.debug.internal.ui.actions.context.AbstractDebugContextAction#getToolTipText()
140      */

141     public String JavaDoc getToolTipText() {
142         return ActionMessages.ResumeAction_3;
143     }
144
145     /*
146      * (non-Javadoc)
147      * @see org.eclipse.debug.internal.ui.actions.context.AbstractDebugContextAction#getDisabledImageDescriptor()
148      */

149     public ImageDescriptor getDisabledImageDescriptor() {
150         return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_RESUME);
151     }
152
153     /*
154      * (non-Javadoc)
155      * @see org.eclipse.debug.internal.ui.actions.context.AbstractDebugContextAction#getHoverImageDescriptor()
156      */

157     public ImageDescriptor getHoverImageDescriptor() {
158         return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_RESUME);
159     }
160
161     /*
162      * (non-Javadoc)
163      * @see org.eclipse.debug.internal.ui.actions.context.AbstractDebugContextAction#getImageDescriptor()
164      */

165     public ImageDescriptor getImageDescriptor() {
166         return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_RESUME);
167     }
168 }
169
Popular Tags