KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > editors > text > EditorsUI


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.editors.text;
12
13 import java.nio.charset.UnmappableCharacterException JavaDoc;
14
15 import org.eclipse.core.runtime.Preferences;
16
17 import org.eclipse.core.resources.IResource;
18
19 import org.eclipse.core.filebuffers.IFileBuffer;
20 import org.eclipse.core.filebuffers.IFileBufferStatusCodes;
21
22 import org.eclipse.jface.preference.IPreferenceStore;
23
24 import org.eclipse.jface.text.source.ISharedTextColors;
25
26 import org.eclipse.ui.PlatformUI;
27 import org.eclipse.ui.internal.editors.text.EditorsPlugin;
28 import org.eclipse.ui.internal.editors.text.NLSUtility;
29 import org.eclipse.ui.keys.IBindingService;
30 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
31 import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
32 import org.eclipse.ui.texteditor.AnnotationTypeLookup;
33 import org.eclipse.ui.texteditor.HyperlinkDetectorRegistry;
34 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
35 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
36 import org.eclipse.ui.texteditor.spelling.SpellingService;
37
38 /**
39  * The central class for access to this plug-in.
40  * This class cannot be instantiated; all functionality is provided by
41  * static methods.
42  *
43  * @since 3.0
44  */

45 public final class EditorsUI {
46
47     /**
48      * TextEditor Plug-in ID (value <code>"org.eclipse.ui.editors"</code>).
49      */

50     public static final String JavaDoc PLUGIN_ID= "org.eclipse.ui.editors"; //$NON-NLS-1$
51

52     /**
53      * The ID of the default text editor.
54      */

55     public static final String JavaDoc DEFAULT_TEXT_EDITOR_ID = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
56

57
58     /**
59      * Returns the annotation type lookup of this plug-in.
60      *
61      * @return the annotation type lookup
62      */

63     public static AnnotationTypeLookup getAnnotationTypeLookup() {
64         return EditorsPlugin.getDefault().getAnnotationTypeLookup();
65     }
66
67     /**
68      * Returns the annotation preference lookup of this plug-in.
69      *
70      * @return the annotation preference lookup
71      */

72     public static AnnotationPreferenceLookup getAnnotationPreferenceLookup() {
73         return EditorsPlugin.getDefault().getAnnotationPreferenceLookup();
74     }
75
76     /**
77      * Returns the preference store of this plug-in.
78      *
79      * @return this plug-in's preference store
80      */

81     public static IPreferenceStore getPreferenceStore() {
82         return EditorsPlugin.getDefault().getPreferenceStore();
83     }
84
85     /**
86      * Removes all preference which are handled by this plug-in's
87      * general preference pages from the given store and prevents
88      * setting the default values in the future.
89      * <p>
90      * To access the
91      * general preference from another plug-in use a
92      * {@link org.eclipse.ui.texteditor.ChainedPreferenceStore}:
93      * <pre>
94      * List stores= new ArrayList(3);
95      * stores.add(YourPlugin.getDefault().getPreferenceStore());
96      * stores.add(EditorsUI.getPreferenceStore());
97      * combinedStore= new ChainedPreferenceStore((IPreferenceStore[]) stores.toArray(new IPreferenceStore[stores.size()]));
98      *
99      * </pre>
100      * </p>
101      * <p>
102      * Note: In order to work this method must be called before
103      * the store's default values are set.
104      * </p>
105      *
106      * @param store the preference store to mark
107      */

108     public static void useAnnotationsPreferencePage(IPreferenceStore store) {
109         MarkerAnnotationPreferences.useAnnotationsPreferencePage(store);
110     }
111
112     /**
113      * Removes all preference which are handled by this plug-in's
114      * Quick Diff preference page from the given store and prevents
115      * setting the default values in the future.
116      * <p>
117      * To access the
118      * general preference from another plug-in use a
119      * {@link org.eclipse.ui.texteditor.ChainedPreferenceStore}:
120      * <pre>
121      * List stores= new ArrayList(3);
122      * stores.add(YourPlugin.getDefault().getPreferenceStore());
123      * stores.add(EditorsUI.getPreferenceStore());
124      * combinedStore= new ChainedPreferenceStore((IPreferenceStore[]) stores.toArray(new IPreferenceStore[stores.size()]));
125      *
126      * </pre>
127      * </p>
128      * <p>
129      * Note: In order to work this method must be called before
130      * the store's default values are set.
131      * </p>
132      *
133      * @param store the preference store to mark
134      */

135     public static void useQuickDiffPreferencePage(IPreferenceStore store) {
136         MarkerAnnotationPreferences.useQuickDiffPreferencePage(store);
137
138         store.setToDefault(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_ALWAYS_ON);
139         store.setToDefault(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_CHARACTER_MODE);
140         store.setToDefault(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_DEFAULT_PROVIDER);
141     }
142
143     private EditorsUI() {
144         // block instantiation
145
}
146
147     /**
148      * Returns the preferences of this plug-in.
149      *
150      * @return the plug-in preferences
151      * @see org.eclipse.core.runtime.Plugin#getPluginPreferences()
152      */

153     public static Preferences getPluginPreferences() {
154         return EditorsPlugin.getDefault().getPluginPreferences();
155     }
156
157     /**
158      * Returns the spelling service.
159      *
160      * @return the spelling service
161      * @since 3.1
162      */

163     public static SpellingService getSpellingService() {
164         return EditorsPlugin.getDefault().getSpellingService();
165     }
166
167     /**
168      * Returns the shared text colors of this plug-in.
169      *
170      * @return the shared text colors
171      * @since 3.3
172      */

173     public static ISharedTextColors getSharedTextColors() {
174         return EditorsPlugin.getDefault().getSharedTextColors();
175     }
176
177     /**
178      * Returns the registry that contains the hyperlink detectors contributed
179      * by the <code>org.eclipse.ui.workbench.texteditor.hyperlinkDetectors</code>
180      * extension point.
181      *
182      * @return the hyperlink detector registry
183      * @since 3.3
184      */

185     public static HyperlinkDetectorRegistry getHyperlinkDetectorRegistry() {
186         return EditorsPlugin.getDefault().getHyperlinkDetectorRegistry();
187     }
188
189     // --------------- Status codes for this plug-in ---------------
190

191     // NOTE: See also IEditorsStatusConstants
192

193     /**
194      * Editor UI plug-in status code indicating that an operation failed
195      * because a character could not be mapped using the given
196      * charset.
197      * <p>
198      * Value: {@value}</p>
199      *
200      * @see UnmappableCharacterException
201      * @since 3.2
202      */

203     public static final int CHARSET_MAPPING_FAILED= 1;
204
205     /**
206      * Editor UI plug-in status code indicating that state
207      * validation failed.
208      * <p>
209      * Value: {@value}</p>
210      *
211      * @see IFileBuffer#validateState(org.eclipse.core.runtime.IProgressMonitor, Object)
212      * @since 3.3
213      */

214     public static final int STATE_VALIDATION_FAILED= IFileBufferStatusCodes.STATE_VALIDATION_FAILED;
215
216     /**
217      * Editor UI plug-in status code indicating that
218      * a resource is marked derived.
219      * <p>
220      * Value: {@value}</p>
221      *
222      * @see IResource#isDerived()
223      * @since 3.3
224      */

225     public static final int DERIVED_FILE= IFileBufferStatusCodes.DERIVED_FILE;
226     
227     /**
228      * Returns the tool tip affordance string.
229      *
230      * @return the affordance string which is empty if the preference is enabled
231      * but the key binding not active or <code>null</code> if the
232      * preference is disabled or the binding service is unavailable
233      * @since 3.3
234      */

235     public static final String JavaDoc getTooltipAffordanceString() {
236         if (!getPreferenceStore().getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_TEXT_HOVER_AFFORDANCE))
237             return null;
238         
239         IBindingService bindingService= (IBindingService)PlatformUI.getWorkbench().getAdapter(IBindingService.class);
240         if (bindingService == null)
241             return null;
242
243         String JavaDoc keySequence= bindingService.getBestActiveBindingFormattedFor(ITextEditorActionDefinitionIds.SHOW_INFORMATION);
244         if (keySequence == null)
245             return ""; //$NON-NLS-1$
246

247         return NLSUtility.format(TextEditorMessages.Editor_toolTip_affordance, keySequence);
248     }
249
250 }
251
Popular Tags