0138aeefc48baaad57a5886114da92163d765332
[phpeclipse.git] /
1 package net.sourceforge.phpeclipse.xdebug.ui.php.model;
2
3 import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants;
4 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugLineBreakpoint;
5
6 import org.eclipse.core.resources.IResource;
7 import org.eclipse.core.runtime.CoreException;
8 import org.eclipse.debug.core.DebugPlugin;
9 import org.eclipse.debug.core.model.IBreakpoint;
10 import org.eclipse.debug.core.model.ILineBreakpoint;
11 import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
12 import org.eclipse.jface.text.ITextSelection;
13 import org.eclipse.jface.viewers.ISelection;
14 import org.eclipse.ui.IEditorPart;
15 import org.eclipse.ui.IWorkbenchPart;
16
17 public class PHPLineBreakpointAdapter implements IToggleBreakpointsTarget {
18
19         public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection)
20                         throws CoreException {
21                 IEditorPart editorPart = (IEditorPart) part;
22
23                 IResource resource = (IResource) editorPart.getEditorInput()
24                                 .getAdapter(IResource.class);
25                 ITextSelection textSelection = (ITextSelection) selection;
26                 int lineNumber = textSelection.getStartLine() + 1;
27                 IBreakpoint[] breakpoints = DebugPlugin.getDefault()
28                                 .getBreakpointManager().getBreakpoints(
29                                                 IXDebugConstants.ID_PHP_DEBUG_MODEL);
30                 for (int i = 0; i < breakpoints.length; i++) {
31                         IBreakpoint breakpoint = breakpoints[i];
32                         if (resource.equals(breakpoint.getMarker().getResource())) {
33                                 if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber)) {
34                                         // remove
35                                         breakpoint.delete();
36                                         return;
37                                 }
38                         }
39                 }
40                 // create line breakpoint (doc line numbers start at 0)
41                 XDebugLineBreakpoint lineBreakpoint = new XDebugLineBreakpoint(
42                                 resource, lineNumber);
43                 // DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint);
44
45         }
46
47         public boolean canToggleLineBreakpoints(IWorkbenchPart part,
48                         ISelection selection) {
49                 // TODO Auto-generated method stub
50                 return true;
51         }
52
53         public void toggleMethodBreakpoints(IWorkbenchPart part,
54                         ISelection selection) throws CoreException {
55                 // TODO Auto-generated method stub
56
57         }
58
59         public boolean canToggleMethodBreakpoints(IWorkbenchPart part,
60                         ISelection selection) {
61                 // TODO Auto-generated method stub
62                 return false;
63         }
64
65         public void toggleWatchpoints(IWorkbenchPart part, ISelection selection)
66                         throws CoreException {
67                 // TODO Auto-generated method stub
68
69         }
70
71         public boolean canToggleWatchpoints(IWorkbenchPart part,
72                         ISelection selection) {
73                 // TODO Auto-generated method stub
74                 return false;
75         }
76
77 }