1 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 41 public class WordIgnoreProposal implements IJavaCompletionProposal { 42 43 44 private IInvocationContext fContext; 45 46 47 private String fWord; 48 49 57 public WordIgnoreProposal(final String word, final IInvocationContext context) { 58 fWord= word; 59 fContext= context; 60 } 61 62 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 92 public String getAdditionalProposalInfo() { 93 return Messages.format(JavaUIMessages.Spelling_ignore_info, new String [] { WordCorrectionProposal.getHtmlRepresentation(fWord)}); 94 } 95 96 99 public final IContextInformation getContextInformation() { 100 return null; 101 } 102 103 106 public String getDisplayString() { 107 return Messages.format(JavaUIMessages.Spelling_ignore_label, new String [] { fWord }); 108 } 109 110 113 public Image getImage() { 114 return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_NLS_NEVER_TRANSLATE); 115 } 116 119 public final int getRelevance() { 120 return Integer.MIN_VALUE + 1; 121 } 122 123 126 public final Point getSelection(final IDocument document) { 127 return new Point(fContext.getSelectionOffset(), fContext.getSelectionLength()); 128 } 129 } 130 | Popular Tags |