KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > ui > actions > RulerBreakpointAction


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.ui.actions;
12
13 import java.util.Iterator JavaDoc;
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 /**
29  * Abstract action that works on breakpoints in the vertical ruler.
30  * <p>
31  * This class may be subclassed.
32  * </p>
33  * @since 3.2
34  */

35 public abstract class RulerBreakpointAction extends Action {
36     
37     private ITextEditor fEditor;
38     private IVerticalRulerInfo fRulerInfo;
39     
40     /**
41      * Constructs an action to work on breakpoints in the specified
42      * text editor with the specified vertical ruler information.
43      *
44      * @param editor text editor
45      * @param info vertical ruler information
46      */

47     public RulerBreakpointAction(ITextEditor editor, IVerticalRulerInfo info) {
48         fEditor = editor;
49         fRulerInfo = info;
50     }
51
52     /**
53      * Returns the breakpoint at the last line of mouse activity in the ruler
54      * or <code>null</code> if none.
55      *
56      * @return breakpoint associated with activity in the ruler or <code>null</code>
57      */

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 JavaDoc iterator = annotationModel.getAnnotationIterator();
63             while (iterator.hasNext()) {
64                 Object JavaDoc 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     /**
89      * Returns the editor this action was created for.
90      *
91      * @return editor
92      */

93     protected ITextEditor getEditor() {
94         return fEditor;
95     }
96     
97     /**
98      * Returns the vertical ruler information this action was created for.
99      *
100      * @return vertical ruler information
101      */

102     protected IVerticalRulerInfo getVerticalRulerInfo() {
103         return fRulerInfo;
104     }
105
106 }
107
Popular Tags