Omaha #3453 Added the spell check dictionary to site level localization.

Former-commit-id: 2ae87df58a [formerly 9d754dc57a] [formerly 5ddadc2015 [formerly f561e979ad047319c6c7f12cf13633868ed9edea]]
Former-commit-id: 5ddadc2015
Former-commit-id: bf4fc92db1
This commit is contained in:
Robert Blum 2014-08-18 15:09:30 -05:00
parent 5f4129f3b6
commit f9cafb2d51
3 changed files with 63 additions and 9 deletions

View file

@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.ui,
com.google.guava;bundle-version="11.0.2" com.google.guava;bundle-version="11.0.2"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy 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,
org.eclipse.jface.text.contentassist, org.eclipse.jface.text.contentassist,
org.eclipse.jface.text.source, org.eclipse.jface.text.source,

View file

@ -25,10 +25,10 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.content.IContentTypeManager; import org.eclipse.core.runtime.content.IContentTypeManager;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.IRegion;
import org.eclipse.ui.PlatformUI; 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.ISpellingProblemCollector;
import org.eclipse.ui.texteditor.spelling.SpellingContext; import org.eclipse.ui.texteditor.spelling.SpellingContext;
import org.eclipse.ui.texteditor.spelling.SpellingService; import org.eclipse.ui.texteditor.spelling.SpellingService;
@ -44,6 +44,8 @@ import org.eclipse.ui.texteditor.spelling.SpellingService;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Jun 17, 2014 3453 rblum Initial creation * Jun 17, 2014 3453 rblum Initial creation
* Aug 18, 2014 3453 rblum Added the spell check dictionary
* to site level localization.
* *
* </pre> * </pre>
* *
@ -54,7 +56,7 @@ import org.eclipse.ui.texteditor.spelling.SpellingService;
public class EnhancedSpellCheckJob extends Job { public class EnhancedSpellCheckJob extends Job {
private IDocument document; private IDocument document;
private IRegion[] region = new IRegion[1]; private IRegion[] region = new IRegion[1];
private ISpellingProblemCollector collector; private ISpellingProblemCollector collector;
@ -69,7 +71,7 @@ public class EnhancedSpellCheckJob extends Job {
public void setDocument(IDocument document) { public void setDocument(IDocument document) {
this.document = document; this.document = document;
} }
public void setRegion(IRegion region) { public void setRegion(IRegion region) {
this.region[0] = region; this.region[0] = region;
} }
@ -83,9 +85,11 @@ public class EnhancedSpellCheckJob extends Job {
SpellingService service = (SpellingService) PlatformUI.getWorkbench() SpellingService service = (SpellingService) PlatformUI.getWorkbench()
.getService(SpellingService.class); .getService(SpellingService.class);
if (service == null) { if (service == null) {
EditorsUI.getPreferenceStore().setValue(SpellingService.PREFERENCE_SPELLING_ENGINE, PreferenceConstants.getPreferenceStore().setValue(
SpellingService.PREFERENCE_SPELLING_ENGINE,
"spellingEngine"); "spellingEngine");
service = new SpellingService(EditorsUI.getPreferenceStore()); service = new SpellingService(
PreferenceConstants.getPreferenceStore());
} }
SpellingContext context = new SpellingContext(); SpellingContext context = new SpellingContext();

View file

@ -19,11 +19,15 @@
**/ **/
package com.raytheon.uf.viz.spellchecker.text; package com.raytheon.uf.viz.spellchecker.text;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; 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.preference.IPreferenceStore;
import org.eclipse.jface.text.Document; import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.ITextListener; 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.Display;
import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem; 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.ISpellingProblemCollector;
import org.eclipse.ui.texteditor.spelling.SpellingProblem; import org.eclipse.ui.texteditor.spelling.SpellingProblem;
import org.eclipse.ui.texteditor.spelling.SpellingService; 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.BoundType;
import com.google.common.collect.Range; import com.google.common.collect.Range;
import com.google.common.collect.Ranges; 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.core.VizApp;
import com.raytheon.uf.viz.spellchecker.jobs.EnhancedSpellCheckJob; 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 * Jun 18, 2014 3453 rblum Initial creation
* Aug 06, 2014 3453 rblum Refreshing all viewers on enable/ * Aug 06, 2014 3453 rblum Refreshing all viewers on enable/
* disable of spell checking. * disable of spell checking.
* Aug 18, 2014 3453 rblum Added the spell check dictionary
* to site level localization.
* *
* </pre> * </pre>
* *
@ -77,9 +90,13 @@ import com.raytheon.uf.viz.spellchecker.jobs.EnhancedSpellCheckJob;
* @version 1.0 * @version 1.0
*/ */
@SuppressWarnings("restriction")
public class SpellCheckTextViewer extends TextViewer implements public class SpellCheckTextViewer extends TextViewer implements
ISpellingProblemCollector { ISpellingProblemCollector {
private static final IUFStatusHandler statusHandler = UFStatus
.getHandler(SpellCheckTextViewer.class);
private List<SpellingProblem> problems; private List<SpellingProblem> problems;
private IPreferenceStore store; private IPreferenceStore store;
@ -90,6 +107,10 @@ public class SpellCheckTextViewer extends TextViewer implements
private Map<Range<Integer>, SpellingProblem> ranges; private Map<Range<Integer>, SpellingProblem> ranges;
private final String siteDictionary = "spellcheck/dictionary.txt";
private LocalizationFile lf;
/** /**
* @param parent * @param parent
* @param styles * @param styles
@ -98,7 +119,18 @@ public class SpellCheckTextViewer extends TextViewer implements
super(parent, styles); super(parent, styles);
problems = new ArrayList<SpellingProblem>(); problems = new ArrayList<SpellingProblem>();
ranges = new HashMap<Range<Integer>, SpellingProblem>(); ranges = new HashMap<Range<Integer>, 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()); setDocument(new Document());
textViewers.add(this); textViewers.add(this);
ITextListener listener = new ITextListener() { ITextListener listener = new ITextListener() {
@ -244,7 +276,24 @@ public class SpellCheckTextViewer extends TextViewer implements
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
ICompletionProposal prop = (ICompletionProposal) item.getData(); 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); scheduleSpellJob(true);
refreshAllTextViewers(false); refreshAllTextViewers(false);
} }