Source Code Cross Referenced for SpellingService.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » texteditor » spelling » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » ui workbench » org.eclipse.ui.texteditor.spelling 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.texteditor.spelling;
011:
012:        import org.eclipse.core.runtime.CoreException;
013:        import org.eclipse.core.runtime.IProgressMonitor;
014:        import org.eclipse.core.runtime.ISafeRunnable;
015:        import org.eclipse.core.runtime.SafeRunner;
016:
017:        import org.eclipse.jface.preference.IPreferenceStore;
018:
019:        import org.eclipse.jface.text.IDocument;
020:        import org.eclipse.jface.text.IRegion;
021:        import org.eclipse.jface.text.Region;
022:
023:        import org.eclipse.ui.internal.texteditor.TextEditorPlugin;
024:        import org.eclipse.ui.internal.texteditor.spelling.SpellingEngineRegistry;
025:
026:        /**
027:         * System wide spelling service.
028:         * <p>
029:         * This class is not intended to be subclassed by clients.
030:         * </p>
031:         *
032:         * @since 3.1
033:         */
034:        public class SpellingService {
035:
036:            /**
037:             * A named preference that controls if spelling is enabled or disabled.
038:             * <p>
039:             * Value is of type <code>Boolean</code>.
040:             * </p>
041:             */
042:            public static final String PREFERENCE_SPELLING_ENABLED = "spellingEnabled"; //$NON-NLS-1$
043:
044:            /**
045:             * A named preference that controls which spelling engine is used.
046:             * The value is the spelling engine's extension id.
047:             * <p>
048:             * Value is of type <code>String</code>.
049:             * </p>
050:             */
051:            public static final String PREFERENCE_SPELLING_ENGINE = "spellingEngine"; //$NON-NLS-1$
052:
053:            /** Preferences */
054:            private IPreferenceStore fPreferences;
055:
056:            /**
057:             * Initializes the spelling service with the given preferences.
058:             *
059:             * @param preferences the preferences
060:             * @see SpellingService#PREFERENCE_SPELLING_ENABLED
061:             * @see SpellingService#PREFERENCE_SPELLING_ENGINE
062:             */
063:            public SpellingService(IPreferenceStore preferences) {
064:                fPreferences = preferences;
065:            }
066:
067:            /**
068:             * Checks the given document. Reports all found spelling problems to the
069:             * collector. The spelling engine is chosen based on the settings
070:             * from the given preferences.
071:             *
072:             * @param document the document to check
073:             * @param context the context
074:             * @param collector the problem collector
075:             * @param monitor the progress monitor, can be <code>null</code>
076:             */
077:            public void check(IDocument document, SpellingContext context,
078:                    ISpellingProblemCollector collector,
079:                    IProgressMonitor monitor) {
080:                check(document, new IRegion[] { new Region(0, document
081:                        .getLength()) }, context, collector, monitor);
082:            }
083:
084:            /**
085:             * Checks the given regions in the given document. Reports all found
086:             * spelling problems to the collector. The spelling engine is chosen
087:             * based on the settings from the given preferences.
088:             *
089:             * @param document the document to check
090:             * @param regions the regions to check
091:             * @param context the context
092:             * @param collector the problem collector
093:             * @param monitor the progress monitor, can be <code>null</code>
094:             */
095:            public void check(final IDocument document,
096:                    final IRegion[] regions, final SpellingContext context,
097:                    final ISpellingProblemCollector collector,
098:                    final IProgressMonitor monitor) {
099:                try {
100:                    collector.beginCollecting();
101:                    if (fPreferences.getBoolean(PREFERENCE_SPELLING_ENABLED))
102:                        try {
103:                            final ISpellingEngine engine = createEngine(fPreferences);
104:                            if (engine != null) {
105:                                ISafeRunnable runnable = new ISafeRunnable() {
106:                                    public void run() throws Exception {
107:                                        engine.check(document, regions,
108:                                                context, collector, monitor);
109:                                    }
110:
111:                                    public void handleException(Throwable x) {
112:                                    }
113:                                };
114:                                SafeRunner.run(runnable);
115:                            }
116:                        } catch (CoreException x) {
117:                            TextEditorPlugin.getDefault().getLog().log(
118:                                    x.getStatus());
119:                        }
120:                } finally {
121:                    collector.endCollecting();
122:                }
123:            }
124:
125:            /**
126:             * Returns all spelling engine descriptors from extensions to the
127:             * spelling engine extension point.
128:             *
129:             * @return all spelling engine descriptors
130:             */
131:            public SpellingEngineDescriptor[] getSpellingEngineDescriptors() {
132:                SpellingEngineRegistry registry = getSpellingEngineRegistry();
133:                if (registry == null)
134:                    return new SpellingEngineDescriptor[0];
135:                return registry.getDescriptors();
136:            }
137:
138:            /**
139:             * Returns the default spelling engine descriptor from extensions to
140:             * the spelling engine extension point.
141:             *
142:             * @return the default spelling engine descriptor or
143:             *         <code>null</code> if none could be found
144:             */
145:            public SpellingEngineDescriptor getDefaultSpellingEngineDescriptor() {
146:                SpellingEngineRegistry registry = getSpellingEngineRegistry();
147:                if (registry == null)
148:                    return null;
149:                return registry.getDefaultDescriptor();
150:            }
151:
152:            /**
153:             * Returns the descriptor of the active spelling engine based on the
154:             * value of the <code>PREFERENCE_SPELLING_ENGINE</code> preference
155:             * in the given preferences.
156:             *
157:             * @param preferences the preferences
158:             * @return the descriptor of the active spelling engine or
159:             *         <code>null</code> if none could be found
160:             * @see SpellingService#PREFERENCE_SPELLING_ENGINE
161:             */
162:            public SpellingEngineDescriptor getActiveSpellingEngineDescriptor(
163:                    IPreferenceStore preferences) {
164:                SpellingEngineRegistry registry = getSpellingEngineRegistry();
165:                if (registry == null)
166:                    return null;
167:
168:                SpellingEngineDescriptor descriptor = null;
169:                if (preferences.contains(PREFERENCE_SPELLING_ENGINE))
170:                    descriptor = registry.getDescriptor(preferences
171:                            .getString(PREFERENCE_SPELLING_ENGINE));
172:                if (descriptor == null)
173:                    descriptor = registry.getDefaultDescriptor();
174:                return descriptor;
175:            }
176:
177:            /**
178:             * Creates a spelling engine based on the value of the
179:             * <code>PREFERENCE_SPELLING_ENGINE</code> preference in the given
180:             * preferences.
181:             *
182:             * @param preferences the preferences
183:             * @return the created spelling engine or <code>null</code> if none
184:             *         could be created
185:             * @throws CoreException if the creation failed
186:             * @see SpellingService#PREFERENCE_SPELLING_ENGINE
187:             */
188:            private ISpellingEngine createEngine(IPreferenceStore preferences)
189:                    throws CoreException {
190:                SpellingEngineDescriptor descriptor = getActiveSpellingEngineDescriptor(preferences);
191:                if (descriptor != null)
192:                    return descriptor.createEngine();
193:                return null;
194:            }
195:
196:            /**
197:             * Returns the spelling engine registry.
198:             *
199:             * @return the spelling engine registry or <code>null</code> if the plug-in has been shutdown
200:             */
201:            private SpellingEngineRegistry getSpellingEngineRegistry() {
202:                return TextEditorPlugin.getDefault()
203:                        .getSpellingEngineRegistry();
204:            }
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.