source: trunk/org.modelica.mdt.breakpoint/src/org/modelica/mdt/breakpoint/MDTRunToLineAdapter.java @ 791

Last change on this file since 791 was 791, checked in by adeas31, 13 years ago
  • Added new bundle org.modelica.mdt.breakpoint to avoid cycles.
  • Added GDB Debugger support.
  • New GDB Specific launch configuration.
File size: 3.0 KB
Line 
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 *******************************************************************************/
12package org.modelica.mdt.breakpoint;
13
14import org.eclipse.core.resources.IFile;
15import org.eclipse.core.resources.IResource;
16import org.eclipse.core.runtime.CoreException;
17import org.eclipse.core.runtime.IAdaptable;
18import org.eclipse.core.runtime.NullProgressMonitor;
19import org.eclipse.debug.core.model.IBreakpoint;
20import org.eclipse.debug.core.model.IDebugElement;
21import org.eclipse.debug.core.model.IDebugTarget;
22import org.eclipse.debug.core.model.ISuspendResume;
23import org.eclipse.debug.ui.actions.IRunToLineTarget;
24import org.eclipse.debug.ui.actions.RunToLineHandler;
25import org.eclipse.jface.text.ITextSelection;
26import org.eclipse.jface.viewers.ISelection;
27import org.eclipse.ui.IEditorPart;
28import org.eclipse.ui.IWorkbenchPart;
29import org.eclipse.ui.texteditor.ITextEditor;
30import org.modelica.mdt.debug.core.MDTDebugCorePlugin;
31import org.modelica.mdt.debug.core.breakpoints.MDTRunToLineBreakpoint;
32
33/**
34 * Run to line target for the MDT debugger
35 */
36public 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}
Note: See TracBrowser for help on using the repository browser.