1 11 package org.eclipse.ant.internal.ui.editor.actions; 12 13 import org.eclipse.ant.internal.ui.debug.IAntDebugConstants; 14 import org.eclipse.ant.internal.ui.debug.model.AntLineBreakpoint; 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.debug.core.DebugPlugin; 18 import org.eclipse.debug.core.model.IBreakpoint; 19 import org.eclipse.debug.core.model.ILineBreakpoint; 20 import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget; 21 import org.eclipse.jface.text.ITextSelection; 22 import org.eclipse.jface.viewers.ISelection; 23 import org.eclipse.swt.widgets.Display; 24 import org.eclipse.ui.IEditorInput; 25 import org.eclipse.ui.IEditorPart; 26 import org.eclipse.ui.IFileEditorInput; 27 import org.eclipse.ui.IWorkbenchPart; 28 29 public class ToggleLineBreakpointAction implements IToggleBreakpointsTarget { 30 31 34 public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException { 35 IEditorPart editorPart = (IEditorPart)part; 36 IEditorInput editorInput = editorPart.getEditorInput(); 37 IResource resource= null; 38 if (editorInput instanceof IFileEditorInput) { 39 resource= ((IFileEditorInput)editorInput).getFile(); 40 } 41 if (resource == null) { 42 Display.getCurrent().beep(); 43 return; 44 } 45 46 ITextSelection textSelection = (ITextSelection) selection; 47 int lineNumber = textSelection.getStartLine(); 48 IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(IAntDebugConstants.ID_ANT_DEBUG_MODEL); 49 for (int i = 0; i < breakpoints.length; i++) { 50 IBreakpoint breakpoint = breakpoints[i]; 51 if (resource.equals(breakpoint.getMarker().getResource())) { 52 if (((ILineBreakpoint)breakpoint).getLineNumber() == (lineNumber + 1)) { 53 breakpoint.delete(); 55 return; 56 } 57 } 58 } 59 new AntLineBreakpoint(resource, lineNumber + 1); 61 } 62 63 66 public boolean canToggleLineBreakpoints(IWorkbenchPart part, ISelection selection) { 67 return selection instanceof ITextSelection; 68 } 69 70 73 public void toggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException { 74 } 75 76 79 public boolean canToggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) { 80 return false; 81 } 82 83 86 public void toggleWatchpoints(IWorkbenchPart part, ISelection selection) throws CoreException { 87 } 88 89 92 public boolean canToggleWatchpoints(IWorkbenchPart part, ISelection selection) { 93 return false; 94 } 95 } 96 | Popular Tags |