KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17 import org.eclipse.core.runtime.jobs.Job;
18 import org.eclipse.debug.core.DebugException;
19 import org.eclipse.debug.core.model.IStep;
20 import org.eclipse.debug.internal.ui.actions.provisional.IAsynchronousStepAdapter;
21 import org.eclipse.debug.internal.ui.actions.provisional.IBooleanRequestMonitor;
22 import org.eclipse.debug.internal.ui.viewers.provisional.IAsynchronousRequestMonitor;
23 import org.eclipse.debug.ui.IDebugUIConstants;
24
25 /**
26  * Default step adapter for standard debug model.
27  *
28  * @since 3.2
29  */

30 public class StepAdapter extends StandardActionAdapter implements IAsynchronousStepAdapter {
31
32     /* (non-Javadoc)
33      * @see org.eclipse.debug.internal.ui.actions.provisional.IAsynchronousStepAdapter#canStepInto(java.lang.Object, org.eclipse.debug.internal.ui.actions.provisional.IBooleanRequestMonitor)
34      */

35     public void canStepInto(final Object JavaDoc element, final IBooleanRequestMonitor requestMonitor) {
36         Job job = new Job("canStepInto") { //$NON-NLS-1$
37
protected IStatus run(IProgressMonitor monitor) {
38                 IStep step = getTarget(element);
39                 if (step != null)
40                     requestMonitor.setResult(step.canStepInto());
41                 else
42                     requestMonitor.setResult(false);
43                 requestMonitor.done();
44                 return Status.OK_STATUS;
45             }
46         };
47         job.setSystem(true);
48         job.setRule(createUpdateSchedulingRule());
49         job.schedule();
50     }
51
52     /* (non-Javadoc)
53      * @see org.eclipse.debug.internal.ui.actions.provisional.IAsynchronousStepAdapter#canStepOver(java.lang.Object, org.eclipse.debug.internal.ui.actions.provisional.IBooleanRequestMonitor)
54      */

55     public void canStepOver(final Object JavaDoc element, final IBooleanRequestMonitor requestMonitor) {
56         Job job = new Job("canStepOver") { //$NON-NLS-1$
57
protected IStatus run(IProgressMonitor monitor) {
58                 IStep step = getTarget(element);
59                 if (step != null)
60                     requestMonitor.setResult(step.canStepOver());
61                 else
62                     requestMonitor.setResult(false);
63                 requestMonitor.done();
64                 return Status.OK_STATUS;
65             }
66         };
67         job.setSystem(true);
68         job.setRule(createUpdateSchedulingRule());
69         job.schedule();
70     }
71
72     /* (non-Javadoc)
73      * @see org.eclipse.debug.internal.ui.actions.provisional.IAsynchronousStepAdapter#canStepReturn(java.lang.Object, org.eclipse.debug.internal.ui.actions.provisional.IBooleanRequestMonitor)
74      */

75     public void canStepReturn(final Object JavaDoc element, final IBooleanRequestMonitor requestMonitor) {
76         Job job = new Job("canStepReturn") { //$NON-NLS-1$
77
protected IStatus run(IProgressMonitor monitor) {
78                 IStep step = getTarget(element);
79                 if (step != null)
80                     requestMonitor.setResult(step.canStepReturn());
81                 else
82                     requestMonitor.setResult(false);
83                 requestMonitor.done();
84                 return Status.OK_STATUS;
85             }
86         };
87         job.setSystem(true);
88         job.setRule(createUpdateSchedulingRule());
89         job.schedule();
90     }
91
92     /* (non-Javadoc)
93      * @see org.eclipse.debug.internal.ui.actions.provisional.IAsynchronousStepAdapter#isStepping(java.lang.Object, org.eclipse.debug.internal.ui.actions.provisional.IBooleanRequestMonitor)
94      */

95     public void isStepping(final Object JavaDoc element, final IBooleanRequestMonitor requestMonitor) {
96         Job job = new Job("isStepping") { //$NON-NLS-1$
97
protected IStatus run(IProgressMonitor monitor) {
98                 IStep step = getTarget(element);
99                 if (step != null)
100                     requestMonitor.setResult(step.isStepping());
101                 else
102                     requestMonitor.setResult(false);
103                 requestMonitor.done();
104                 return Status.OK_STATUS;
105             }
106         };
107         job.setSystem(true);
108         job.setRule(createUpdateSchedulingRule());
109         job.schedule();
110     }
111
112     /* (non-Javadoc)
113      * @see org.eclipse.debug.internal.ui.actions.provisional.IAsynchronousStepAdapter#stepInto(java.lang.Object, org.eclipse.debug.internal.ui.viewers.provisional.IAsynchronousRequestMonitor)
114      */

115     public void stepInto(final Object JavaDoc element, final IAsynchronousRequestMonitor requestMonitor) {
116         Job job = new Job("stepInto") { //$NON-NLS-1$
117
protected IStatus run(IProgressMonitor monitor) {
118                 IStep step = getTarget(element);
119                 if (step != null) {
120                     try {
121                         step.stepInto();
122                     } catch (DebugException e) {
123                         requestMonitor.setStatus(e.getStatus());
124                     }
125                 } else {
126                     requestMonitor.setStatus(new Status(IStatus.ERROR, IDebugUIConstants.PLUGIN_ID, IDebugUIConstants.INTERNAL_ERROR, "element must be an instance of or adapt to IStep", //$NON-NLS-1$
127
null));
128                 }
129                 requestMonitor.done();
130                 return Status.OK_STATUS;
131             }
132         };
133         job.setSystem(true);
134         job.schedule();
135     }
136
137     /* (non-Javadoc)
138      * @see org.eclipse.debug.internal.ui.actions.provisional.IAsynchronousStepAdapter#stepOver(java.lang.Object, org.eclipse.debug.internal.ui.viewers.provisional.IAsynchronousRequestMonitor)
139      */

140     public void stepOver(final Object JavaDoc element, final IAsynchronousRequestMonitor requestMonitor) {
141         Job job = new Job("stepOver") { //$NON-NLS-1$
142
protected IStatus run(IProgressMonitor monitor) {
143                 IStep step = getTarget(element);
144                 if (step != null) {
145                     try {
146                         step.stepOver();
147                     } catch (DebugException e) {
148                         requestMonitor.setStatus(e.getStatus());
149                     }
150                 } else {
151                     requestMonitor.setStatus(new Status(IStatus.ERROR, IDebugUIConstants.PLUGIN_ID, IDebugUIConstants.INTERNAL_ERROR, "element must be an instance of or adapt to IStep", //$NON-NLS-1$
152
null));
153                 }
154                 requestMonitor.done();
155                 return Status.OK_STATUS;
156             }
157         };
158         job.setSystem(true);
159         job.schedule();
160     }
161
162     /* (non-Javadoc)
163      * @see org.eclipse.debug.internal.ui.actions.provisional.IAsynchronousStepAdapter#stepReturn(java.lang.Object, org.eclipse.debug.internal.ui.viewers.provisional.IAsynchronousRequestMonitor)
164      */

165     public void stepReturn(final Object JavaDoc element, final IAsynchronousRequestMonitor requestMonitor) {
166         Job job = new Job("stepReturn") { //$NON-NLS-1$
167
protected IStatus run(IProgressMonitor monitor) {
168                 IStep step = getTarget(element);
169                 if (step != null) {
170                     try {
171                         step.stepReturn();
172                     } catch (DebugException e) {
173                         requestMonitor.setStatus(e.getStatus());
174                     }
175                 } else {
176                     requestMonitor.setStatus(new Status(IStatus.ERROR, IDebugUIConstants.PLUGIN_ID, IDebugUIConstants.INTERNAL_ERROR, "element must be an instance of or adapt to IStep", //$NON-NLS-1$
177
null));
178                 }
179                 requestMonitor.done();
180                 return Status.OK_STATUS;
181             }
182         };
183         job.setSystem(true);
184         job.schedule();
185
186     }
187     
188     private IStep getTarget(Object JavaDoc element) {
189         if (element instanceof IStep) {
190             return (IStep) element;
191         } else if (element instanceof IAdaptable) {
192             return (IStep) ((IAdaptable) element).getAdapter(IStep.class);
193         }
194         return null;
195     }
196
197 }
198
Popular Tags