From 5f56a1291e9beba07d8307b127c4cbeabc8ce832 Mon Sep 17 00:00:00 2001 From: Robert Blum Date: Mon, 18 Aug 2014 15:09:30 -0500 Subject: [PATCH] Omaha #3453 Added the spell check dictionary to site level localization. Former-commit-id: d0020759853fc298c2c34833e472ccfd6dcef188 [formerly 2ae87df58ac820a10fddbb4cb55971be6a1f8587] [formerly 9d754dc57aa01275f56ea9e0348b600c6bf7f7e4] [formerly d0020759853fc298c2c34833e472ccfd6dcef188 [formerly 2ae87df58ac820a10fddbb4cb55971be6a1f8587] [formerly 9d754dc57aa01275f56ea9e0348b600c6bf7f7e4] [formerly 5ddadc20159df44e696ac065f5c47bcc0eb529d3 [formerly 9d754dc57aa01275f56ea9e0348b600c6bf7f7e4 [formerly f561e979ad047319c6c7f12cf13633868ed9edea]]]] Former-commit-id: 5ddadc20159df44e696ac065f5c47bcc0eb529d3 Former-commit-id: 641b713bc43b29756216d41802df27242a597600 [formerly f9cafb2d514d045427ce3b6422a662c2613e58db] [formerly 6c0ec0e604926d50ebdc4cce4cac9d69b2cada60 [formerly bf4fc92db1c79b57f29b331daec0218403b739cf]] Former-commit-id: 57addafd72b434d5035291d6ef5291f88b6e219d [formerly fe5666a5029ee777c35212e2b381ecc41164e8b7] Former-commit-id: bf291978f011b89edcdd470010318bd0f5368bde --- .../META-INF/MANIFEST.MF | 3 +- .../jobs/EnhancedSpellCheckJob.java | 14 +++-- .../text/SpellCheckTextViewer.java | 55 ++++++++++++++++++- 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/cave/com.raytheon.uf.viz.spellchecker/META-INF/MANIFEST.MF b/cave/com.raytheon.uf.viz.spellchecker/META-INF/MANIFEST.MF index df8b199dfb..8ec8a93939 100644 --- a/cave/com.raytheon.uf.viz.spellchecker/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.uf.viz.spellchecker/META-INF/MANIFEST.MF @@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.ui, com.google.guava;bundle-version="11.0.2" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy -Import-Package: org.eclipse.jdt.ui, +Import-Package: org.eclipse.jdt.internal.ui.text.spelling, + org.eclipse.jdt.ui, org.eclipse.jface.text, org.eclipse.jface.text.contentassist, org.eclipse.jface.text.source, diff --git a/cave/com.raytheon.uf.viz.spellchecker/src/com/raytheon/uf/viz/spellchecker/jobs/EnhancedSpellCheckJob.java b/cave/com.raytheon.uf.viz.spellchecker/src/com/raytheon/uf/viz/spellchecker/jobs/EnhancedSpellCheckJob.java index 87c026bd99..a4c020efc4 100644 --- a/cave/com.raytheon.uf.viz.spellchecker/src/com/raytheon/uf/viz/spellchecker/jobs/EnhancedSpellCheckJob.java +++ b/cave/com.raytheon.uf.viz.spellchecker/src/com/raytheon/uf/viz/spellchecker/jobs/EnhancedSpellCheckJob.java @@ -25,10 +25,10 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.content.IContentTypeManager; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jdt.ui.PreferenceConstants; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.editors.text.EditorsUI; import org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector; import org.eclipse.ui.texteditor.spelling.SpellingContext; import org.eclipse.ui.texteditor.spelling.SpellingService; @@ -44,6 +44,8 @@ import org.eclipse.ui.texteditor.spelling.SpellingService; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Jun 17, 2014 3453 rblum Initial creation + * Aug 18, 2014 3453 rblum Added the spell check dictionary + * to site level localization. * * * @@ -54,7 +56,7 @@ import org.eclipse.ui.texteditor.spelling.SpellingService; public class EnhancedSpellCheckJob extends Job { private IDocument document; - + private IRegion[] region = new IRegion[1]; private ISpellingProblemCollector collector; @@ -69,7 +71,7 @@ public class EnhancedSpellCheckJob extends Job { public void setDocument(IDocument document) { this.document = document; } - + public void setRegion(IRegion region) { this.region[0] = region; } @@ -83,9 +85,11 @@ public class EnhancedSpellCheckJob extends Job { SpellingService service = (SpellingService) PlatformUI.getWorkbench() .getService(SpellingService.class); if (service == null) { - EditorsUI.getPreferenceStore().setValue(SpellingService.PREFERENCE_SPELLING_ENGINE, + PreferenceConstants.getPreferenceStore().setValue( + SpellingService.PREFERENCE_SPELLING_ENGINE, "spellingEngine"); - service = new SpellingService(EditorsUI.getPreferenceStore()); + service = new SpellingService( + PreferenceConstants.getPreferenceStore()); } SpellingContext context = new SpellingContext(); diff --git a/cave/com.raytheon.uf.viz.spellchecker/src/com/raytheon/uf/viz/spellchecker/text/SpellCheckTextViewer.java b/cave/com.raytheon.uf.viz.spellchecker/src/com/raytheon/uf/viz/spellchecker/text/SpellCheckTextViewer.java index ec3882bab0..12ac128fad 100644 --- a/cave/com.raytheon.uf.viz.spellchecker/src/com/raytheon/uf/viz/spellchecker/text/SpellCheckTextViewer.java +++ b/cave/com.raytheon.uf.viz.spellchecker/src/com/raytheon/uf/viz/spellchecker/text/SpellCheckTextViewer.java @@ -19,11 +19,15 @@ **/ package com.raytheon.uf.viz.spellchecker.text; +import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.eclipse.jdt.internal.ui.text.spelling.AddWordProposal; +import org.eclipse.jdt.internal.ui.text.spelling.DisableSpellCheckingProposal; +import org.eclipse.jdt.ui.PreferenceConstants; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.ITextListener; @@ -47,7 +51,6 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.ui.editors.text.EditorsUI; import org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector; import org.eclipse.ui.texteditor.spelling.SpellingProblem; import org.eclipse.ui.texteditor.spelling.SpellingService; @@ -55,6 +58,14 @@ import org.eclipse.ui.texteditor.spelling.SpellingService; import com.google.common.collect.BoundType; import com.google.common.collect.Range; import com.google.common.collect.Ranges; +import com.raytheon.uf.common.localization.IPathManager; +import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; +import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; +import com.raytheon.uf.common.localization.LocalizationFile; +import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.localization.exception.LocalizationOpFailedException; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.viz.core.VizApp; import com.raytheon.uf.viz.spellchecker.jobs.EnhancedSpellCheckJob; @@ -70,6 +81,8 @@ import com.raytheon.uf.viz.spellchecker.jobs.EnhancedSpellCheckJob; * Jun 18, 2014 3453 rblum Initial creation * Aug 06, 2014 3453 rblum Refreshing all viewers on enable/ * disable of spell checking. + * Aug 18, 2014 3453 rblum Added the spell check dictionary + * to site level localization. * * * @@ -77,9 +90,13 @@ import com.raytheon.uf.viz.spellchecker.jobs.EnhancedSpellCheckJob; * @version 1.0 */ +@SuppressWarnings("restriction") public class SpellCheckTextViewer extends TextViewer implements ISpellingProblemCollector { + private static final IUFStatusHandler statusHandler = UFStatus + .getHandler(SpellCheckTextViewer.class); + private List problems; private IPreferenceStore store; @@ -90,6 +107,10 @@ public class SpellCheckTextViewer extends TextViewer implements private Map, SpellingProblem> ranges; + private final String siteDictionary = "spellcheck/dictionary.txt"; + + private LocalizationFile lf; + /** * @param parent * @param styles @@ -98,7 +119,18 @@ public class SpellCheckTextViewer extends TextViewer implements super(parent, styles); problems = new ArrayList(); ranges = new HashMap, SpellingProblem>(); - store = EditorsUI.getPreferenceStore(); + store = PreferenceConstants.getPreferenceStore(); + + IPathManager mgr = PathManagerFactory.getPathManager(); + lf = mgr.getLocalizationFile(mgr.getContext( + LocalizationType.CAVE_STATIC, LocalizationLevel.SITE), + siteDictionary); + + // Get the localized dictionary and store it in the Preference store + File dictionary = lf.getFile(); + String filePath = dictionary.getPath(); + store.setValue(PreferenceConstants.SPELLING_USER_DICTIONARY, filePath); + setDocument(new Document()); textViewers.add(this); ITextListener listener = new ITextListener() { @@ -244,7 +276,24 @@ public class SpellCheckTextViewer extends TextViewer implements @Override public void widgetSelected(SelectionEvent e) { ICompletionProposal prop = (ICompletionProposal) item.getData(); - prop.apply(getDocument()); + if (prop instanceof DisableSpellCheckingProposal) { + store.setValue(SpellingService.PREFERENCE_SPELLING_ENABLED, + false); + } else { + prop.apply(getDocument()); + + if (prop instanceof AddWordProposal) { + try { + if (lf != null) { + lf.save(); + } + } catch (LocalizationOpFailedException exception) { + statusHandler + .error("Unable to save dictionary into localization", + exception); + } + } + } scheduleSpellJob(true); refreshAllTextViewers(false); }