KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > text > spelling > WordIgnoreProposal


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
12 package org.eclipse.jdt.internal.ui.text.spelling;
13
14 import org.eclipse.swt.graphics.Image;
15 import org.eclipse.swt.graphics.Point;
16
17 import org.eclipse.jface.text.IDocument;
18 import org.eclipse.jface.text.contentassist.IContextInformation;
19
20 import org.eclipse.ui.IEditorPart;
21 import org.eclipse.ui.IWorkbenchPage;
22 import org.eclipse.ui.texteditor.ITextEditor;
23 import org.eclipse.ui.texteditor.spelling.SpellingProblem;
24
25 import org.eclipse.jdt.internal.corext.util.Messages;
26
27 import org.eclipse.jdt.ui.text.java.IInvocationContext;
28 import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
29
30 import org.eclipse.jdt.internal.ui.JavaPlugin;
31 import org.eclipse.jdt.internal.ui.JavaPluginImages;
32 import org.eclipse.jdt.internal.ui.JavaUIMessages;
33 import org.eclipse.jdt.internal.ui.text.spelling.engine.ISpellCheckEngine;
34 import org.eclipse.jdt.internal.ui.text.spelling.engine.ISpellChecker;
35
36 /**
37  * Proposal to ignore the word during the current editing session.
38  *
39  * @since 3.0
40  */

41 public class WordIgnoreProposal implements IJavaCompletionProposal {
42
43     /** The invocation context */
44     private IInvocationContext fContext;
45
46     /** The word to ignore */
47     private String JavaDoc fWord;
48
49     /**
50      * Creates a new spell ignore proposal.
51      *
52      * @param word
53      * The word to ignore
54      * @param context
55      * The invocation context
56      */

57     public WordIgnoreProposal(final String JavaDoc word, final IInvocationContext context) {
58         fWord= word;
59         fContext= context;
60     }
61
62     /*
63      * @see org.eclipse.jface.text.contentassist.ICompletionProposal#apply(org.eclipse.jface.text.IDocument)
64      */

65     public final void apply(final IDocument document) {
66
67         final ISpellCheckEngine engine= SpellCheckEngine.getInstance();
68         final ISpellChecker checker= engine.getSpellChecker();
69
70         if (checker != null) {
71             checker.ignoreWord(fWord);
72             SpellingProblem.removeAllInActiveEditor(getEditor(), fWord);
73         }
74     }
75
76     private ITextEditor getEditor() {
77         IWorkbenchPage activePage= JavaPlugin.getActivePage();
78         if (activePage == null)
79             return null;
80     
81         IEditorPart editor= activePage.getActiveEditor();
82         if (activePage.getActivePart() != editor || !(editor instanceof ITextEditor))
83             return null;
84         
85         return (ITextEditor)editor;
86         
87     }
88
89     /*
90      * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getAdditionalProposalInfo()
91      */

92     public String JavaDoc getAdditionalProposalInfo() {
93         return Messages.format(JavaUIMessages.Spelling_ignore_info, new String JavaDoc[] { WordCorrectionProposal.getHtmlRepresentation(fWord)});
94     }
95
96     /*
97      * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getContextInformation()
98      */

99     public final IContextInformation getContextInformation() {
100         return null;
101     }
102
103     /*
104      * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getDisplayString()
105      */

106     public String JavaDoc getDisplayString() {
107         return Messages.format(JavaUIMessages.Spelling_ignore_label, new String JavaDoc[] { fWord });
108     }
109
110     /*
111      * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getImage()
112      */

113     public Image getImage() {
114         return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_NLS_NEVER_TRANSLATE);
115     }
116     /*
117      * @see org.eclipse.jdt.ui.text.java.IJavaCompletionProposal#getRelevance()
118      */

119     public final int getRelevance() {
120         return Integer.MIN_VALUE + 1;
121     }
122
123     /*
124      * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getSelection(org.eclipse.jface.text.IDocument)
125      */

126     public final Point getSelection(final IDocument document) {
127         return new Point(fContext.getSelectionOffset(), fContext.getSelectionLength());
128     }
129 }
130
Popular Tags