KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > texteditor > TextEditorPlugin


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.internal.texteditor;
12
13 import java.util.HashSet JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.Set JavaDoc;
16
17 import org.osgi.framework.BundleContext;
18
19 import org.eclipse.core.runtime.Assert;
20 import org.eclipse.core.runtime.IRegistryChangeEvent;
21 import org.eclipse.core.runtime.IRegistryChangeListener;
22 import org.eclipse.core.runtime.Platform;
23
24 import org.eclipse.jface.action.IAction;
25
26
27 import org.eclipse.ui.internal.texteditor.quickdiff.QuickDiffExtensionsRegistry;
28 import org.eclipse.ui.internal.texteditor.spelling.SpellingEngineRegistry;
29 import org.eclipse.ui.plugin.AbstractUIPlugin;
30
31 /**
32  * The plug-in runtime class for the text editor UI plug-in (id <code>"org.eclipse.ui.workbench.texteditor"</code>).
33  * This class provides static methods for:
34  * <ul>
35  * <li> getting the last editor position.</li>
36  * </ul>
37  * <p>
38  * This class provides static methods and fields only; it is not intended to be
39  * instantiated or subclassed by clients.
40  * </p>
41  *
42  * @since 2.1
43  */

44 public final class TextEditorPlugin extends AbstractUIPlugin implements IRegistryChangeListener {
45
46     /** The plug-in instance */
47     private static TextEditorPlugin fgPlugin;
48
49     /** The last edit position */
50     private EditPosition fLastEditPosition;
51     /** The action which goes to the last edit position */
52     private Set JavaDoc fLastEditPositionDependentActions;
53
54     /**
55      * The quick diff extension registry.
56      * @since 3.0
57      */

58     private QuickDiffExtensionsRegistry fQuickDiffExtensionRegistry;
59
60     /**
61      * The spelling engine registry
62      * @since 3.1
63      */

64     private SpellingEngineRegistry fSpellingEngineRegistry;
65
66     /**
67      * Creates a plug-in instance.
68      */

69     public TextEditorPlugin() {
70         super();
71         Assert.isTrue(fgPlugin == null);
72         fgPlugin= this;
73     }
74
75     /**
76      * Returns the plug-in instance.
77      *
78      * @return the text editor plug-in instance
79      * @since 3.0
80      */

81     public static TextEditorPlugin getDefault() {
82         return fgPlugin;
83     }
84
85     /**
86      * Text editor UI plug-in Id (value <code>"org.eclipse.ui.workbench.texteditor"</code>).
87      */

88     public static final String JavaDoc PLUGIN_ID= "org.eclipse.ui.workbench.texteditor"; //$NON-NLS-1$
89

90     /**
91      * Extension Id of quick diff reference provider extension point.
92      * (value <code>"quickDiffReferenceProvider"</code>).
93      * @since 3.0
94      */

95     public static final String JavaDoc REFERENCE_PROVIDER_EXTENSION_POINT= "quickDiffReferenceProvider"; //$NON-NLS-1$
96

97     /**
98      * Returns the last edit position.
99      *
100      * @return the last edit position or <code>null</code> if there is no last edit position
101      * @see EditPosition
102      */

103     EditPosition getLastEditPosition() {
104         return fLastEditPosition;
105     }
106
107     /**
108      * Sets the last edit position.
109      *
110      * @param lastEditPosition the last edit position
111      * @see EditPosition
112      */

113     public void setLastEditPosition(EditPosition lastEditPosition) {
114         fLastEditPosition= lastEditPosition;
115         if (fLastEditPosition != null && fLastEditPositionDependentActions != null) {
116             Iterator JavaDoc iter= fLastEditPositionDependentActions.iterator();
117             while (iter.hasNext())
118                 ((IAction)iter.next()).setEnabled(true);
119             fLastEditPositionDependentActions= null;
120         }
121     }
122
123     /**
124      * Adds the given action to the last edit position dependent actions.
125      *
126      * @param action the goto last edit position action
127      */

128     void addLastEditPositionDependentAction(IAction action) {
129         if (fLastEditPosition != null)
130             return;
131         if (fLastEditPositionDependentActions == null)
132             fLastEditPositionDependentActions= new HashSet JavaDoc();
133         fLastEditPositionDependentActions.add(action);
134     }
135
136     /**
137      * Removes the given action from the last edit position dependent actions.
138      *
139      * @param action the action that depends on the last edit position
140      */

141     void removeLastEditPositionDependentAction(IAction action) {
142         if (fLastEditPosition != null)
143             return;
144         if (fLastEditPositionDependentActions != null)
145             fLastEditPositionDependentActions.remove(action);
146     }
147
148
149     /*
150      * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
151      * @since 3.0
152      */

153     public void start(BundleContext context) throws Exception JavaDoc {
154         super.start(context);
155         fQuickDiffExtensionRegistry= new QuickDiffExtensionsRegistry();
156         fSpellingEngineRegistry= new SpellingEngineRegistry();
157         Platform.getExtensionRegistry().addRegistryChangeListener(this, PLUGIN_ID);
158     }
159
160     /*
161      * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
162      * @since 3.0
163      */

164     public void stop(BundleContext context) throws Exception JavaDoc {
165         Platform.getExtensionRegistry().removeRegistryChangeListener(this);
166         fQuickDiffExtensionRegistry= null;
167         fSpellingEngineRegistry= null;
168         super.stop(context);
169     }
170
171     /*
172      * @see org.eclipse.core.runtime.IRegistryChangeListener#registryChanged(org.eclipse.core.runtime.IRegistryChangeEvent)
173      * @since 3.0
174      */

175     public void registryChanged(IRegistryChangeEvent event) {
176         if (fQuickDiffExtensionRegistry != null && event.getExtensionDeltas(PLUGIN_ID, REFERENCE_PROVIDER_EXTENSION_POINT).length > 0)
177             fQuickDiffExtensionRegistry.reloadExtensions();
178         if (fSpellingEngineRegistry != null && event.getExtensionDeltas(PLUGIN_ID, SpellingEngineRegistry.SPELLING_ENGINE_EXTENSION_POINT).length > 0)
179             fSpellingEngineRegistry.reloadExtensions();
180     }
181
182     /**
183      * Returns this plug-ins quick diff extension registry.
184      *
185      * @return the quick diff extension registry or <code>null</code> if this plug-in has been shutdown
186      * @since 3.0
187      */

188     public QuickDiffExtensionsRegistry getQuickDiffExtensionRegistry() {
189         return fQuickDiffExtensionRegistry;
190     }
191
192     /**
193      * Returns this plug-ins spelling engine registry.
194      *
195      * @return the spelling engine registry or <code>null</code> if this plug-in has been shutdown
196      * @since 3.1
197      */

198     public SpellingEngineRegistry getSpellingEngineRegistry() {
199         return fSpellingEngineRegistry;
200     }
201 }
202
Popular Tags