KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.eclipse.ui.texteditor;
13
14
15 import java.util.ResourceBundle JavaDoc;
16
17 import org.eclipse.jface.text.IFindReplaceTarget;
18 import org.eclipse.jface.text.IFindReplaceTargetExtension;
19 import org.eclipse.ui.IWorkbenchPart;
20 import org.eclipse.ui.IWorkbenchWindow;
21
22
23 /**
24  * An action which enters the incremental find mode like in emacs.
25  * <p>
26  * This class may be instantiated; it is not intended to be subclassed.
27  * </p>
28  * @since 2.0
29  */

30 public class IncrementalFindAction extends ResourceAction implements IUpdate {
31
32     /** The action's target */
33     private IFindReplaceTarget fTarget;
34     /** The part the action is bound to */
35     private IWorkbenchPart fWorkbenchPart;
36     /** The workbench window */
37     private IWorkbenchWindow fWorkbenchWindow;
38     /**
39      * The direction to run the incremental find
40      * @since 2.1
41      */

42     private boolean fForward;
43
44     /**
45      * Creates a new incremental find action for the given workbench part.
46      * The action configures its visual representation from the given
47      * resource bundle.
48      *
49      * @param bundle the resource bundle
50      * @param prefix a prefix to be prepended to the various resource keys
51      * (described in <code>ResourceAction</code> constructor), or
52      * <code>null</code> if none
53      * @param workbenchPart the workbench part
54      * @param forward <code>true</code> if the search direction is forward
55      * @see ResourceAction#ResourceAction(ResourceBundle, String)
56      * @since 2.1
57      */

58     public IncrementalFindAction(ResourceBundle JavaDoc bundle, String JavaDoc prefix, IWorkbenchPart workbenchPart, boolean forward) {
59         super(bundle, prefix);
60         fWorkbenchPart= workbenchPart;
61         fForward= forward;
62         update();
63     }
64
65     /**
66      * Creates a new incremental find action for the given workbench window.
67      * The action configures its visual representation from the given
68      * resource bundle.
69      *
70      * @param bundle the resource bundle
71      * @param prefix a prefix to be prepended to the various resource keys
72      * (described in <code>ResourceAction</code> constructor), or
73      * <code>null</code> if none
74      * @param workbenchWindow the workbench window
75      * @param forward <code>true</code> if the search direction is forward
76      * @see ResourceAction#ResourceAction(ResourceBundle, String)
77      *
78      * @deprecated use FindReplaceAction(ResourceBundle, String, IWorkbenchPart, boolean) instead
79      * @since 2.1
80      */

81     public IncrementalFindAction(ResourceBundle JavaDoc bundle, String JavaDoc prefix, IWorkbenchWindow workbenchWindow, boolean forward) {
82         super(bundle, prefix);
83         fWorkbenchWindow= workbenchWindow;
84         fForward= forward;
85         update();
86     }
87
88     /*
89      * @see IAction#run()
90      */

91     public void run() {
92
93         if (fTarget == null)
94             return;
95
96         if (fTarget instanceof IncrementalFindTarget)
97             ((IncrementalFindTarget) fTarget).setDirection(fForward);
98
99         if (fTarget instanceof IFindReplaceTargetExtension)
100             ((IFindReplaceTargetExtension) fTarget).beginSession();
101     }
102
103     /*
104      * @see IUpdate#update()
105      */

106     public void update() {
107
108         if (fWorkbenchPart == null && fWorkbenchWindow != null)
109             fWorkbenchPart= fWorkbenchWindow.getPartService().getActivePart();
110
111         if (fWorkbenchPart != null)
112             fTarget= (IFindReplaceTarget) fWorkbenchPart.getAdapter(IncrementalFindTarget.class);
113         else
114             fTarget= null;
115
116         setEnabled(fTarget != null && fTarget.canPerformFind());
117     }
118
119 }
120
Popular Tags