1 | /******************************************************************************* |
---|
2 | * Copyright (c) 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 | * Bjorn Freeman-Benson - initial API and implementation |
---|
11 | *******************************************************************************/ |
---|
12 | package org.modelica.mdt.breakpoint; |
---|
13 | |
---|
14 | import org.eclipse.core.resources.IFile; |
---|
15 | import org.eclipse.core.resources.IResource; |
---|
16 | import org.eclipse.core.runtime.CoreException; |
---|
17 | import org.eclipse.core.runtime.IAdaptable; |
---|
18 | import org.eclipse.core.runtime.NullProgressMonitor; |
---|
19 | import org.eclipse.debug.core.model.IBreakpoint; |
---|
20 | import org.eclipse.debug.core.model.IDebugElement; |
---|
21 | import org.eclipse.debug.core.model.IDebugTarget; |
---|
22 | import org.eclipse.debug.core.model.ISuspendResume; |
---|
23 | import org.eclipse.debug.ui.actions.IRunToLineTarget; |
---|
24 | import org.eclipse.debug.ui.actions.RunToLineHandler; |
---|
25 | import org.eclipse.jface.text.ITextSelection; |
---|
26 | import org.eclipse.jface.viewers.ISelection; |
---|
27 | import org.eclipse.ui.IEditorPart; |
---|
28 | import org.eclipse.ui.IWorkbenchPart; |
---|
29 | import org.eclipse.ui.texteditor.ITextEditor; |
---|
30 | import org.modelica.mdt.debug.core.MDTDebugCorePlugin; |
---|
31 | import org.modelica.mdt.debug.core.breakpoints.MDTRunToLineBreakpoint; |
---|
32 | |
---|
33 | /** |
---|
34 | * Run to line target for the MDT debugger |
---|
35 | */ |
---|
36 | public class MDTRunToLineAdapter implements IRunToLineTarget { |
---|
37 | |
---|
38 | /* (non-Javadoc) |
---|
39 | * @see org.eclipse.debug.ui.actions.IRunToLineTarget#runToLine(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection, org.eclipse.debug.core.model.ISuspendResume) |
---|
40 | */ |
---|
41 | public void runToLine(IWorkbenchPart part, ISelection selection, ISuspendResume target) throws CoreException { |
---|
42 | IEditorPart editorPart = (IEditorPart)part; |
---|
43 | ITextEditor textEditor = (ITextEditor)editorPart; |
---|
44 | ITextSelection textSelection = (ITextSelection) selection; |
---|
45 | int lineNumber = textSelection.getStartLine() + 1; |
---|
46 | if (lineNumber > 0) { |
---|
47 | if (target instanceof IAdaptable) { |
---|
48 | IDebugTarget debugTarget = (IDebugTarget) ((IAdaptable)target).getAdapter(IDebugTarget.class); |
---|
49 | if (debugTarget != null) { |
---|
50 | IFile resource = (IFile) textEditor.getEditorInput().getAdapter(IResource.class); |
---|
51 | IBreakpoint breakpoint= new MDTRunToLineBreakpoint(resource, lineNumber); |
---|
52 | RunToLineHandler handler = new RunToLineHandler(debugTarget, target, breakpoint); |
---|
53 | handler.run(new NullProgressMonitor()); |
---|
54 | } |
---|
55 | } |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | /* (non-Javadoc) |
---|
60 | * @see org.eclipse.debug.ui.actions.IRunToLineTarget#canRunToLine(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection, org.eclipse.debug.core.model.ISuspendResume) |
---|
61 | */ |
---|
62 | public boolean canRunToLine(IWorkbenchPart part, ISelection selection, ISuspendResume target) { |
---|
63 | return target instanceof IDebugElement && |
---|
64 | ((IDebugElement)target).getModelIdentifier().equals(MDTDebugCorePlugin.ID_MDT_DEBUG_MODEL); |
---|
65 | } |
---|
66 | } |
---|