2 * Created on 25.11.2004
4 * TODO To change the template for this generated file go to
5 * Window - Preferences - Java - Code Style - Code Templates
7 package net.sourceforge.phpeclipse.xdebug.ui;
9 import org.eclipse.core.resources.IResource;
10 import org.eclipse.core.runtime.CoreException;
11 import org.eclipse.debug.core.DebugPlugin;
12 import org.eclipse.debug.core.model.IBreakpoint;
13 import org.eclipse.debug.core.model.ILineBreakpoint;
14 import net.sourceforge.phpeclipse.xdebug.core.IXDebugConstants;
15 import net.sourceforge.phpeclipse.xdebug.core.XDebugLineBreakpoint;
16 import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
17 import org.eclipse.jface.text.ITextSelection;
18 import org.eclipse.jface.viewers.ISelection;
19 import org.eclipse.ui.IWorkbenchPart;
20 import org.eclipse.ui.texteditor.ITextEditor;
25 * TODO To change the template for this generated type comment go to
26 * Window - Preferences - Java - Code Style - Code Templates
28 public class XDebugLineBreakpointAdapter implements IToggleBreakpointsTarget {
30 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleLineBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
32 public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
33 ITextEditor textEditor = getEditor(part);
34 if (textEditor != null) {
35 IResource resource = (IResource) textEditor.getEditorInput().getAdapter(IResource.class);
36 ITextSelection textSelection = (ITextSelection) selection;
37 int lineNumber = textSelection.getStartLine();
38 IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(IXDebugConstants.ID_XDEBUG_DEBUG_MODEL);
39 for (int i = 0; i < breakpoints.length; i++) {
40 IBreakpoint breakpoint = breakpoints[i];
41 if (resource.equals(breakpoint.getMarker().getResource())) {
42 if (((ILineBreakpoint)breakpoint).getLineNumber() == (lineNumber + 1)) {
49 // create line breakpoint (doc line numbers start at 0)
50 XDebugLineBreakpoint lineBreakpoint = new XDebugLineBreakpoint(resource, lineNumber + 1);
51 DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint);
55 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleLineBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
57 public boolean canToggleLineBreakpoints(IWorkbenchPart part, ISelection selection) {
58 return getEditor(part) != null;
62 * Returns the editor being used to edit a PDA file, associated with the
63 * given part, or <code>null</code> if none.
65 * @param part workbench part
66 * @return the editor being used to edit a PDA file, associated with the
67 * given part, or <code>null</code> if none
69 private ITextEditor getEditor(IWorkbenchPart part) {
70 if (part instanceof ITextEditor) {
71 ITextEditor editorPart = (ITextEditor) part;
72 IResource resource = (IResource) editorPart.getEditorInput().getAdapter(IResource.class);
73 if (resource != null) {
74 String extension = resource.getFileExtension();
75 if (extension != null && extension.equals("pda")) {
84 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
86 public void toggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
89 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
91 public boolean canToggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) {
95 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
97 public void toggleWatchpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
100 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
102 public boolean canToggleWatchpoints(IWorkbenchPart part, ISelection selection) {