1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpdt.internal.ui.text.spelling;
14 import java.text.MessageFormat;
16 import net.sourceforge.phpdt.internal.ui.PHPUIMessages;
17 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
18 import net.sourceforge.phpdt.internal.ui.text.java.IInvocationContext;
19 import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal;
20 import net.sourceforge.phpdt.internal.ui.text.spelling.engine.ISpellCheckEngine;
21 import net.sourceforge.phpdt.internal.ui.text.spelling.engine.ISpellChecker;
22 import net.sourceforge.phpdt.ui.PreferenceConstants;
24 import org.eclipse.jface.text.IDocument;
25 import org.eclipse.jface.text.contentassist.IContextInformation;
26 import org.eclipse.swt.graphics.Image;
27 import org.eclipse.swt.graphics.Point;
30 * Proposal to add the unknown word to the dictionaries.
34 public class AddWordProposal implements IPHPCompletionProposal {
36 /** The invocation context */
37 private final IInvocationContext fContext;
39 /** The word to add */
40 private final String fWord;
43 * Creates a new add word proposal
48 * The invocation context
50 public AddWordProposal(final String word, final IInvocationContext context) {
56 * @see org.eclipse.jface.text.contentassist.ICompletionProposal#apply(org.eclipse.jface.text.IDocument)
58 public final void apply(final IDocument document) {
60 final ISpellCheckEngine engine = SpellCheckEngine.getInstance();
61 final ISpellChecker checker = engine.createSpellChecker(engine
62 .getLocale(), PreferenceConstants.getPreferenceStore());
65 checker.addWord(fWord);
69 * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getAdditionalProposalInfo()
71 public String getAdditionalProposalInfo() {
74 PHPUIMessages.getString("Spelling.add.info"), new String[] { WordCorrectionProposal.getHtmlRepresentation(fWord) }); //$NON-NLS-1$
78 * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getContextInformation()
80 public final IContextInformation getContextInformation() {
85 * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getDisplayString()
87 public String getDisplayString() {
88 return MessageFormat.format(PHPUIMessages
89 .getString("Spelling.add.label"), new String[] { fWord }); //$NON-NLS-1$
93 * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getImage()
95 public Image getImage() {
96 return PHPUiImages.get(PHPUiImages.IMG_CORRECTION_ADD);
100 * @see net.sourceforge.phpdt.ui.text.java.IJavaCompletionProposal#getRelevance()
102 public int getRelevance() {
103 return Integer.MIN_VALUE;
107 * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getSelection(org.eclipse.jface.text.IDocument)
109 public final Point getSelection(final IDocument document) {
110 return new Point(fContext.getSelectionOffset(), fContext
111 .getSelectionLength());