KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.ui.texteditor;
12
13 import java.util.ResourceBundle JavaDoc;
14
15 import org.eclipse.jface.text.source.IAnnotationModel;
16
17 /**
18  * Action for jumping to a particular annotation in the editor's text viewer.
19  * <p>
20  * This action only runs if <code>getTextEditor()</code>
21  * implements {@link org.eclipse.ui.texteditor.ITextEditorExtension4}.</p>
22  * <p>
23  * This class may be instantiated; it is not intended to be subclassed.
24  * </p>
25  *
26  * @since 3.2
27  */

28 public class GotoAnnotationAction extends TextEditorAction {
29
30     /**
31      * The navigation direction.
32      * <code>true</code> to go to next and <code>false</code> to go to previous annotation.
33      */

34     private boolean fForward;
35
36     /**
37      * Creates a new action for the given text editor. The action configures its
38      * 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
43      * <code>null</code> if none
44      * @param editor the text editor
45      * @param forward <code>true</code> to go to next and <code>false</code> to go to previous annotation
46      * @see TextEditorAction#TextEditorAction(ResourceBundle, String, ITextEditor)
47      */

48     public GotoAnnotationAction(ResourceBundle JavaDoc bundle, String JavaDoc prefix, ITextEditor editor, boolean forward) {
49         super(bundle, prefix, editor);
50         fForward= forward;
51         setHelpContextId(fForward ? IAbstractTextEditorHelpContextIds.GOTO_NEXT_ANNOTATION_ACTION : IAbstractTextEditorHelpContextIds.GOTO_PREVIOUS_ANNOTATION_ACTION);
52     }
53     
54     /**
55      * Creates a new action for the given text editor. The action configures its
56      * visual representation from the given resource bundle.
57      *
58      * @param editor the text editor
59      * @param forward <code>true</code> to go to next and <code>false</code> to go to previous annotation
60      * @see TextEditorAction#TextEditorAction(ResourceBundle, String, ITextEditor)
61      */

62     public GotoAnnotationAction(ITextEditor editor, boolean forward) {
63         this(EditorMessages.getBundleForConstructedKeys(), forward ? "Editor.GotoNextAnnotation." : "Editor.GotoPreviousAnnotation.", editor, forward); //$NON-NLS-1$ //$NON-NLS-2$
64
}
65
66     /*
67      * @see org.eclipse.jface.action.IAction#run()
68      * @since 3.2
69      */

70     public void run() {
71         ITextEditor editor= getTextEditor();
72         if (editor instanceof ITextEditorExtension4)
73             ((ITextEditorExtension4)editor).gotoAnnotation(fForward);
74     }
75     
76     /*
77      * @see org.eclipse.ui.texteditor.TextEditorAction#setEditor(org.eclipse.ui.texteditor.ITextEditor)
78      * @since 3.2
79      */

80     public void setEditor(ITextEditor editor) {
81         super.setEditor(editor);
82         update();
83     }
84
85     /*
86      * @see org.eclipse.ui.texteditor.IUpdate#update()
87      * @since 3.2
88      */

89     public void update() {
90         ITextEditor editor= getTextEditor();
91         if (!(editor instanceof AbstractTextEditor)) {
92             setEnabled(false);
93             return;
94         }
95         
96         IAnnotationModel model= editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
97         setEnabled(model != null);
98     }
99 }
100
Popular Tags