a7e6cb95f22688f3f27375e6c31bd8bac0b3cfc6
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.ui / src / net / sourceforge / phpeclipse / xdebug / ui / php / model / PHPLineBreakpointAdapter.java
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().getAdapter(IResource.class);
24                 ITextSelection textSelection = (ITextSelection) selection;
25                 int lineNumber = textSelection.getStartLine()+1;
26                 IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(IXDebugConstants.ID_PHP_DEBUG_MODEL);
27                 for (int i = 0; i < breakpoints.length; i++) {
28                         IBreakpoint breakpoint = breakpoints[i];
29                         if (resource.equals(breakpoint.getMarker().getResource())) {
30                                 if (((ILineBreakpoint)breakpoint).getLineNumber() == (lineNumber )) {
31                                                 // remove
32                                         breakpoint.delete();
33                                         return;
34                                 }
35                         }
36                 }
37                         // create line breakpoint (doc line numbers start at 0)
38                 XDebugLineBreakpoint lineBreakpoint = new XDebugLineBreakpoint(resource, lineNumber);
39                 DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint);
40                 
41         }
42
43         public boolean canToggleLineBreakpoints(IWorkbenchPart part,
44                         ISelection selection) {
45                 // TODO Auto-generated method stub
46                 return true;
47         }
48
49         public void toggleMethodBreakpoints(IWorkbenchPart part,
50                         ISelection selection) throws CoreException {
51                 // TODO Auto-generated method stub
52
53         }
54
55         public boolean canToggleMethodBreakpoints(IWorkbenchPart part,
56                         ISelection selection) {
57                 // TODO Auto-generated method stub
58                 return false;
59         }
60
61         public void toggleWatchpoints(IWorkbenchPart part, ISelection selection)
62                         throws CoreException {
63                 // TODO Auto-generated method stub
64
65         }
66
67         public boolean canToggleWatchpoints(IWorkbenchPart part,
68                         ISelection selection) {
69                 // TODO Auto-generated method stub
70                 return false;
71         }
72
73 }