KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > texteditor > SelectAnnotationRulerAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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
12
13 package org.eclipse.ui.texteditor;
14
15
16 import java.util.ResourceBundle JavaDoc;
17
18 import org.eclipse.swt.widgets.Menu;
19
20 import org.eclipse.jface.text.Position;
21 import org.eclipse.jface.text.source.Annotation;
22 import org.eclipse.jface.text.source.IVerticalRulerListener;
23 import org.eclipse.jface.text.source.IAnnotationModel;
24 import org.eclipse.jface.text.source.IVerticalRulerInfo;
25 import org.eclipse.jface.text.source.IVerticalRulerInfoExtension;
26 import org.eclipse.jface.text.source.VerticalRulerEvent;
27
28 /**
29  * A ruler action which can select the textual range of an annotation that has a
30  * visual representation in a vertical ruler.
31  *
32  * @since 3.0
33  */

34 public class SelectAnnotationRulerAction extends TextEditorAction implements IVerticalRulerListener {
35
36     /**
37      * Creates a new action for the given ruler and editor. The action configures
38      * its visual representation from the given resource bundle.
39      *
40      * @param bundle the resource bundle
41      * @param prefix a prefix to be prepended to the various resource keys
42      * (described in <code>ResourceAction</code> constructor), or <code>null</code> if none
43      * @param editor the editor
44      *
45      * @see ResourceAction#ResourceAction(ResourceBundle, String)
46      */

47     public SelectAnnotationRulerAction(ResourceBundle JavaDoc bundle, String JavaDoc prefix, ITextEditor editor) {
48         super(bundle, prefix, editor);
49     }
50
51     /*
52      * @see org.eclipse.ui.texteditor.TextEditorAction#setEditor(org.eclipse.ui.texteditor.ITextEditor)
53      */

54     public void setEditor(ITextEditor editor) {
55         if (getTextEditor() != null) {
56             IVerticalRulerInfo service= (IVerticalRulerInfo) getTextEditor().getAdapter(IVerticalRulerInfo.class);
57             if (service instanceof IVerticalRulerInfoExtension)
58                 ((IVerticalRulerInfoExtension) service).removeVerticalRulerListener(this);
59         }
60         super.setEditor(editor);
61         if (getTextEditor() != null) {
62             IVerticalRulerInfo service= (IVerticalRulerInfo) getTextEditor().getAdapter(IVerticalRulerInfo.class);
63             if (service instanceof IVerticalRulerInfoExtension)
64                 ((IVerticalRulerInfoExtension) service).addVerticalRulerListener(this);
65         }
66     }
67
68     /**
69      * Returns the <code>AbstractMarkerAnnotationModel</code> of the editor's input.
70      *
71      * @return the marker annotation model or <code>null</code> if there's none
72      */

73     protected IAnnotationModel getAnnotationModel() {
74         IDocumentProvider provider= getTextEditor().getDocumentProvider();
75         return provider.getAnnotationModel(getTextEditor().getEditorInput());
76     }
77
78     /*
79      * @see org.eclipse.ui.texteditor.IVerticalRulerListener#annotationSelected(org.eclipse.ui.texteditor.VerticalRulerEvent)
80      */

81     public void annotationSelected(VerticalRulerEvent event) {
82     }
83
84     /*
85      * @see org.eclipse.ui.texteditor.IVerticalRulerListener#annotationDefaultSelected(org.eclipse.ui.texteditor.VerticalRulerEvent)
86      */

87     public void annotationDefaultSelected(VerticalRulerEvent event) {
88         Annotation a= event.getSelectedAnnotation();
89         IAnnotationModel model= getAnnotationModel();
90         Position position= model.getPosition(a);
91         if (position == null)
92             return;
93
94         getTextEditor().selectAndReveal(position.offset, position.length);
95     }
96
97     /*
98      * @see org.eclipse.ui.texteditor.IVerticalRulerListener#annotationContextMenuAboutToShow(org.eclipse.ui.texteditor.VerticalRulerEvent, org.eclipse.swt.widgets.Menu)
99      */

100     public void annotationContextMenuAboutToShow(VerticalRulerEvent event, Menu menu) {
101     }
102 }
103
Popular Tags