Very ugly start of a first wizard page. Needs a lot of cleanup!
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.ui / src / net / sourceforge / phpeclipse / xdebug / ui / XDebugLineBreakpointAdapter.java
1 /*
2  * Created on 25.11.2004
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */
7 package net.sourceforge.phpeclipse.xdebug.ui;
8
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;
21
22 /**
23  * @author Axel
24  *
25  * TODO To change the template for this generated type comment go to
26  * Window - Preferences - Java - Code Style - Code Templates
27  */
28 public class XDebugLineBreakpointAdapter  implements IToggleBreakpointsTarget {
29         /* (non-Javadoc)
30          * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleLineBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
31          */
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)) {
43                                                 // remove
44                                                 breakpoint.delete();
45                                                 return;
46                                         }
47                                 }
48                         }
49                         // create line breakpoint (doc line numbers start at 0)
50                         XDebugLineBreakpoint lineBreakpoint = new XDebugLineBreakpoint(resource, lineNumber + 1);
51                         DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint);
52                 }
53         }
54         /* (non-Javadoc)
55          * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleLineBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
56          */
57         public boolean canToggleLineBreakpoints(IWorkbenchPart part, ISelection selection) {
58                 return getEditor(part) != null;
59         }
60         
61         /**
62          * Returns the editor being used to edit a PDA file, associated with the
63          * given part, or <code>null</code> if none.
64          *  
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
68          */
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")) {
76                                         return editorPart;
77                                 }
78                         }
79                 }
80                 return null;            
81         }
82         
83         /* (non-Javadoc)
84          * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
85          */
86         public void toggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
87         }
88         /* (non-Javadoc)
89          * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
90          */
91         public boolean canToggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) {
92                 return false;
93         }
94         /* (non-Javadoc)
95          * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
96          */
97         public void toggleWatchpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
98         }
99         /* (non-Javadoc)
100          * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
101          */
102         public boolean canToggleWatchpoints(IWorkbenchPart part, ISelection selection) {
103                 return false;
104         }
105 }