1 11 package org.eclipse.debug.ui.actions; 12 13 import java.util.Iterator ; 14 15 import org.eclipse.core.resources.IMarker; 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.jface.action.Action; 20 import org.eclipse.jface.text.BadLocationException; 21 import org.eclipse.jface.text.IDocument; 22 import org.eclipse.jface.text.Position; 23 import org.eclipse.jface.text.source.IAnnotationModel; 24 import org.eclipse.jface.text.source.IVerticalRulerInfo; 25 import org.eclipse.ui.texteditor.ITextEditor; 26 import org.eclipse.ui.texteditor.SimpleMarkerAnnotation; 27 28 35 public abstract class RulerBreakpointAction extends Action { 36 37 private ITextEditor fEditor; 38 private IVerticalRulerInfo fRulerInfo; 39 40 47 public RulerBreakpointAction(ITextEditor editor, IVerticalRulerInfo info) { 48 fEditor = editor; 49 fRulerInfo = info; 50 } 51 52 58 protected IBreakpoint getBreakpoint() { 59 IAnnotationModel annotationModel = fEditor.getDocumentProvider().getAnnotationModel(fEditor.getEditorInput()); 60 IDocument document = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput()); 61 if (annotationModel != null) { 62 Iterator iterator = annotationModel.getAnnotationIterator(); 63 while (iterator.hasNext()) { 64 Object object = iterator.next(); 65 if (object instanceof SimpleMarkerAnnotation) { 66 SimpleMarkerAnnotation markerAnnotation = (SimpleMarkerAnnotation) object; 67 IMarker marker = markerAnnotation.getMarker(); 68 try { 69 if (marker.isSubtypeOf(IBreakpoint.BREAKPOINT_MARKER)) { 70 Position position = annotationModel.getPosition(markerAnnotation); 71 int line = document.getLineOfOffset(position.getOffset()); 72 if (line == fRulerInfo.getLineOfLastMouseButtonActivity()) { 73 IBreakpoint breakpoint = DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(marker); 74 if (breakpoint != null) { 75 return breakpoint; 76 } 77 } 78 } 79 } catch (CoreException e) { 80 } catch (BadLocationException e) { 81 } 82 } 83 } 84 } 85 return null; 86 } 87 88 93 protected ITextEditor getEditor() { 94 return fEditor; 95 } 96 97 102 protected IVerticalRulerInfo getVerticalRulerInfo() { 103 return fRulerInfo; 104 } 105 106 } 107 | Popular Tags |