001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.texteditor;
011:
012: import java.util.HashSet;
013: import java.util.Iterator;
014: import java.util.Set;
015:
016: import org.osgi.framework.BundleContext;
017:
018: import org.eclipse.core.runtime.Assert;
019: import org.eclipse.core.runtime.IRegistryChangeEvent;
020: import org.eclipse.core.runtime.IRegistryChangeListener;
021: import org.eclipse.core.runtime.Platform;
022:
023: import org.eclipse.jface.action.IAction;
024:
025: import org.eclipse.ui.internal.texteditor.quickdiff.QuickDiffExtensionsRegistry;
026: import org.eclipse.ui.internal.texteditor.spelling.SpellingEngineRegistry;
027: import org.eclipse.ui.plugin.AbstractUIPlugin;
028:
029: /**
030: * The plug-in runtime class for the text editor UI plug-in (id <code>"org.eclipse.ui.workbench.texteditor"</code>).
031: * This class provides static methods for:
032: * <ul>
033: * <li> getting the last editor position.</li>
034: * </ul>
035: * <p>
036: * This class provides static methods and fields only; it is not intended to be
037: * instantiated or subclassed by clients.
038: * </p>
039: *
040: * @since 2.1
041: */
042: public final class TextEditorPlugin extends AbstractUIPlugin implements
043: IRegistryChangeListener {
044:
045: /** The plug-in instance */
046: private static TextEditorPlugin fgPlugin;
047:
048: /** The last edit position */
049: private EditPosition fLastEditPosition;
050: /** The action which goes to the last edit position */
051: private Set fLastEditPositionDependentActions;
052:
053: /**
054: * The quick diff extension registry.
055: * @since 3.0
056: */
057: private QuickDiffExtensionsRegistry fQuickDiffExtensionRegistry;
058:
059: /**
060: * The spelling engine registry
061: * @since 3.1
062: */
063: private SpellingEngineRegistry fSpellingEngineRegistry;
064:
065: /**
066: * Creates a plug-in instance.
067: */
068: public TextEditorPlugin() {
069: super ();
070: Assert.isTrue(fgPlugin == null);
071: fgPlugin = this ;
072: }
073:
074: /**
075: * Returns the plug-in instance.
076: *
077: * @return the text editor plug-in instance
078: * @since 3.0
079: */
080: public static TextEditorPlugin getDefault() {
081: return fgPlugin;
082: }
083:
084: /**
085: * Text editor UI plug-in Id (value <code>"org.eclipse.ui.workbench.texteditor"</code>).
086: */
087: public static final String PLUGIN_ID = "org.eclipse.ui.workbench.texteditor"; //$NON-NLS-1$
088:
089: /**
090: * Extension Id of quick diff reference provider extension point.
091: * (value <code>"quickDiffReferenceProvider"</code>).
092: * @since 3.0
093: */
094: public static final String REFERENCE_PROVIDER_EXTENSION_POINT = "quickDiffReferenceProvider"; //$NON-NLS-1$
095:
096: /**
097: * Returns the last edit position.
098: *
099: * @return the last edit position or <code>null</code> if there is no last edit position
100: * @see EditPosition
101: */
102: EditPosition getLastEditPosition() {
103: return fLastEditPosition;
104: }
105:
106: /**
107: * Sets the last edit position.
108: *
109: * @param lastEditPosition the last edit position
110: * @see EditPosition
111: */
112: public void setLastEditPosition(EditPosition lastEditPosition) {
113: fLastEditPosition = lastEditPosition;
114: if (fLastEditPosition != null
115: && fLastEditPositionDependentActions != null) {
116: Iterator iter = fLastEditPositionDependentActions
117: .iterator();
118: while (iter.hasNext())
119: ((IAction) iter.next()).setEnabled(true);
120: fLastEditPositionDependentActions = null;
121: }
122: }
123:
124: /**
125: * Adds the given action to the last edit position dependent actions.
126: *
127: * @param action the goto last edit position action
128: */
129: void addLastEditPositionDependentAction(IAction action) {
130: if (fLastEditPosition != null)
131: return;
132: if (fLastEditPositionDependentActions == null)
133: fLastEditPositionDependentActions = new HashSet();
134: fLastEditPositionDependentActions.add(action);
135: }
136:
137: /**
138: * Removes the given action from the last edit position dependent actions.
139: *
140: * @param action the action that depends on the last edit position
141: */
142: void removeLastEditPositionDependentAction(IAction action) {
143: if (fLastEditPosition != null)
144: return;
145: if (fLastEditPositionDependentActions != null)
146: fLastEditPositionDependentActions.remove(action);
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 {
154: super .start(context);
155: fQuickDiffExtensionRegistry = new QuickDiffExtensionsRegistry();
156: fSpellingEngineRegistry = new SpellingEngineRegistry();
157: Platform.getExtensionRegistry().addRegistryChangeListener(this ,
158: PLUGIN_ID);
159: }
160:
161: /*
162: * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
163: * @since 3.0
164: */
165: public void stop(BundleContext context) throws Exception {
166: Platform.getExtensionRegistry().removeRegistryChangeListener(
167: this );
168: fQuickDiffExtensionRegistry = null;
169: fSpellingEngineRegistry = null;
170: super .stop(context);
171: }
172:
173: /*
174: * @see org.eclipse.core.runtime.IRegistryChangeListener#registryChanged(org.eclipse.core.runtime.IRegistryChangeEvent)
175: * @since 3.0
176: */
177: public void registryChanged(IRegistryChangeEvent event) {
178: if (fQuickDiffExtensionRegistry != null
179: && event.getExtensionDeltas(PLUGIN_ID,
180: REFERENCE_PROVIDER_EXTENSION_POINT).length > 0)
181: fQuickDiffExtensionRegistry.reloadExtensions();
182: if (fSpellingEngineRegistry != null
183: && event
184: .getExtensionDeltas(
185: PLUGIN_ID,
186: SpellingEngineRegistry.SPELLING_ENGINE_EXTENSION_POINT).length > 0)
187: fSpellingEngineRegistry.reloadExtensions();
188: }
189:
190: /**
191: * Returns this plug-ins quick diff extension registry.
192: *
193: * @return the quick diff extension registry or <code>null</code> if this plug-in has been shutdown
194: * @since 3.0
195: */
196: public QuickDiffExtensionsRegistry getQuickDiffExtensionRegistry() {
197: return fQuickDiffExtensionRegistry;
198: }
199:
200: /**
201: * Returns this plug-ins spelling engine registry.
202: *
203: * @return the spelling engine registry or <code>null</code> if this plug-in has been shutdown
204: * @since 3.1
205: */
206: public SpellingEngineRegistry getSpellingEngineRegistry() {
207: return fSpellingEngineRegistry;
208: }
209: }
|