Source Code Cross Referenced for SpellingProblem.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, 2007 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 java.util.ArrayList;
013:        import java.util.Iterator;
014:        import java.util.List;
015:
016:        import org.eclipse.core.runtime.Assert;
017:
018:        import org.eclipse.jface.text.BadLocationException;
019:        import org.eclipse.jface.text.IDocument;
020:        import org.eclipse.jface.text.Position;
021:        import org.eclipse.jface.text.contentassist.ICompletionProposal;
022:        import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext;
023:        import org.eclipse.jface.text.source.Annotation;
024:        import org.eclipse.jface.text.source.IAnnotationModel;
025:        import org.eclipse.jface.text.source.IAnnotationModelExtension;
026:        import org.eclipse.jface.text.source.ISourceViewer;
027:
028:        import org.eclipse.ui.IEditorInput;
029:        import org.eclipse.ui.texteditor.IDocumentProvider;
030:        import org.eclipse.ui.texteditor.ITextEditor;
031:
032:        /**
033:         * A spelling problem as reported by the {@link SpellingService} service to the
034:         * {@link ISpellingProblemCollector}.
035:         * <p>
036:         * This class is intended to be subclassed by clients.
037:         * </p>
038:         *
039:         * @see SpellingService
040:         * @see ISpellingProblemCollector
041:         * @since 3.1
042:         */
043:        public abstract class SpellingProblem {
044:
045:            /**
046:             * Removes all spelling problems that are reported
047:             * for the given <code>word</code> in the active editor.
048:             * <p>
049:             * <em>This a workaround to fix bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=134338
050:             * for 3.2 at the time where spelling still resides in JDT Text.
051:             * Once we move the spell check engine along with its quick fixes
052:             * down to Platform Text we need to provide the proposals with
053:             * a way to access the annotation model.</em>
054:             * </p>
055:             * 
056:             * @param editor the text editor, if <code>null</code> this method does nothing
057:             * @param word the word for which to remove the problems or <code>null</code> to remove all
058:             * @since 3.3
059:             * @deprecated As of 3.4, replaced by {@link #removeAll(ISourceViewer, String)}
060:             */
061:            public static void removeAllInActiveEditor(ITextEditor editor,
062:                    String word) {
063:                if (editor == null)
064:                    return;
065:
066:                IDocumentProvider documentProvider = editor
067:                        .getDocumentProvider();
068:                if (documentProvider == null)
069:                    return;
070:
071:                IEditorInput editorInput = editor.getEditorInput();
072:                if (editorInput == null)
073:                    return;
074:
075:                IAnnotationModel model = documentProvider
076:                        .getAnnotationModel(editorInput);
077:                if (model == null)
078:                    return;
079:
080:                IDocument document = documentProvider.getDocument(editorInput);
081:                if (document == null)
082:                    return;
083:
084:                boolean supportsBatchReplace = (model instanceof  IAnnotationModelExtension);
085:                List toBeRemovedAnnotations = new ArrayList();
086:                Iterator iter = model.getAnnotationIterator();
087:                while (iter.hasNext()) {
088:                    Annotation annotation = (Annotation) iter.next();
089:                    if (SpellingAnnotation.TYPE.equals(annotation.getType())) {
090:                        boolean doRemove = word == null;
091:                        if (word == null)
092:                            doRemove = true;
093:                        else {
094:                            String annotationWord = null;
095:                            Position pos = model.getPosition(annotation);
096:                            try {
097:                                annotationWord = document.get(pos.getOffset(),
098:                                        pos.getLength());
099:                            } catch (BadLocationException e) {
100:                                continue;
101:                            }
102:                            doRemove = word.equals(annotationWord);
103:                        }
104:                        if (doRemove) {
105:                            if (supportsBatchReplace)
106:                                toBeRemovedAnnotations.add(annotation);
107:                            else
108:                                model.removeAnnotation(annotation);
109:                        }
110:                    }
111:                }
112:
113:                if (supportsBatchReplace && !toBeRemovedAnnotations.isEmpty()) {
114:                    Annotation[] annotationArray = (Annotation[]) toBeRemovedAnnotations
115:                            .toArray(new Annotation[toBeRemovedAnnotations
116:                                    .size()]);
117:                    ((IAnnotationModelExtension) model).replaceAnnotations(
118:                            annotationArray, null);
119:                }
120:            }
121:
122:            /**
123:             * Removes all spelling problems that are reported
124:             * for the given <code>word</code> in the active editor.
125:             * 
126:             * @param sourceViewer the source viewer
127:             * @param word the word for which to remove the problems or <code>null</code> to remove all
128:             * @since 3.4
129:             */
130:            public static void removeAll(ISourceViewer sourceViewer, String word) {
131:                Assert.isNotNull(sourceViewer);
132:
133:                IAnnotationModel model = sourceViewer.getAnnotationModel();
134:                if (model == null)
135:                    return;
136:
137:                IDocument document = sourceViewer.getDocument();
138:                if (document == null)
139:                    return;
140:
141:                boolean supportsBatchReplace = (model instanceof  IAnnotationModelExtension);
142:                List toBeRemovedAnnotations = new ArrayList();
143:                Iterator iter = model.getAnnotationIterator();
144:                while (iter.hasNext()) {
145:                    Annotation annotation = (Annotation) iter.next();
146:                    if (SpellingAnnotation.TYPE.equals(annotation.getType())) {
147:                        boolean doRemove = word == null;
148:                        if (word == null)
149:                            doRemove = true;
150:                        else {
151:                            String annotationWord = null;
152:                            Position pos = model.getPosition(annotation);
153:                            try {
154:                                annotationWord = document.get(pos.getOffset(),
155:                                        pos.getLength());
156:                            } catch (BadLocationException e) {
157:                                continue;
158:                            }
159:                            doRemove = word.equals(annotationWord);
160:                        }
161:                        if (doRemove) {
162:                            if (supportsBatchReplace)
163:                                toBeRemovedAnnotations.add(annotation);
164:                            else
165:                                model.removeAnnotation(annotation);
166:                        }
167:                    }
168:                }
169:
170:                if (supportsBatchReplace && !toBeRemovedAnnotations.isEmpty()) {
171:                    Annotation[] annotationArray = (Annotation[]) toBeRemovedAnnotations
172:                            .toArray(new Annotation[toBeRemovedAnnotations
173:                                    .size()]);
174:                    ((IAnnotationModelExtension) model).replaceAnnotations(
175:                            annotationArray, null);
176:                }
177:            }
178:
179:            /**
180:             * Returns the offset of the incorrectly spelled region.
181:             *
182:             * @return the offset of the incorrectly spelled region
183:             */
184:            public abstract int getOffset();
185:
186:            /**
187:             * Returns the length of the incorrectly spelled region.
188:             *
189:             * @return the length of the incorrectly spelled region
190:             */
191:            public abstract int getLength();
192:
193:            /**
194:             * Returns a localized, human-readable message string which describes the spelling problem.
195:             *
196:             * @return a localized, human-readable message string which describes the spelling problem
197:             */
198:            public abstract String getMessage();
199:
200:            /**
201:             * Returns the proposals for the incorrectly spelled region.
202:             *
203:             * @return the proposals for the incorrectly spelled region
204:             */
205:            public abstract ICompletionProposal[] getProposals();
206:
207:            /**
208:             * Returns the proposals for the incorrectly spelled region.
209:             * 
210:             * @param context the invocation context or <code>null</code> if none
211:             * @return the proposals for the incorrectly spelled region
212:             * @since 3.4
213:             */
214:            public ICompletionProposal[] getProposals(
215:                    IQuickAssistInvocationContext context) {
216:                return getProposals();
217:            }
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.