From 6d49b0f7ae9ac9ec8310fdbd33eb956fbb12ecd5 Mon Sep 17 00:00:00 2001 From: Robert Blum Date: Tue, 5 Aug 2014 10:03:40 -0500 Subject: [PATCH] Omaha #3453 Refreshing the viewer on every spell check job to correctly update underlining. Change-Id: I5e037a7b3e85fd794966bd351ae37777abb0d193 Former-commit-id: f27b34bc0aa50d13415dde6153676d3a9484c9ab --- .../text/SpellCheckTextViewer.java | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) 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 e3f5f869e9..ec3882bab0 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 @@ -34,6 +34,8 @@ import org.eclipse.jface.text.TextViewer; import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyleRange; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.MenuAdapter; import org.eclipse.swt.events.MenuEvent; import org.eclipse.swt.events.MouseAdapter; @@ -66,6 +68,8 @@ import com.raytheon.uf.viz.spellchecker.jobs.EnhancedSpellCheckJob; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Jun 18, 2014 3453 rblum Initial creation + * Aug 06, 2014 3453 rblum Refreshing all viewers on enable/ + * disable of spell checking. * * * @@ -82,6 +86,8 @@ public class SpellCheckTextViewer extends TextViewer implements private volatile boolean checkingSpelling = false; + private static List textViewers = new ArrayList(); + private Map, SpellingProblem> ranges; /** @@ -94,11 +100,12 @@ public class SpellCheckTextViewer extends TextViewer implements ranges = new HashMap, SpellingProblem>(); store = EditorsUI.getPreferenceStore(); setDocument(new Document()); + textViewers.add(this); ITextListener listener = new ITextListener() { @Override public void textChanged(TextEvent event) { if (checkingSpelling == false) { - scheduleSpellJob(false); + scheduleSpellJob(true); } } }; @@ -126,7 +133,7 @@ public class SpellCheckTextViewer extends TextViewer implements store.setValue( SpellingService.PREFERENCE_SPELLING_ENABLED, true); - scheduleSpellJob(true); + refreshAllTextViewers(true); } }); } else if (problem != null) { @@ -150,6 +157,15 @@ public class SpellCheckTextViewer extends TextViewer implements } } }); + getTextWidget().addDisposeListener(new DisposeListener() { + + @Override + public void widgetDisposed(DisposeEvent e) { + if (textViewers.contains(SpellCheckTextViewer.this)) { + textViewers.remove(SpellCheckTextViewer.this); + } + } + }); } /* @@ -229,12 +245,38 @@ public class SpellCheckTextViewer extends TextViewer implements public void widgetSelected(SelectionEvent e) { ICompletionProposal prop = (ICompletionProposal) item.getData(); prop.apply(getDocument()); - refresh(); scheduleSpellJob(true); + refreshAllTextViewers(false); } }); } + /** + * Cycles through all the SpellCheckTextViewers and issues a refresh or + * schedules a EnhancedSpellCheckJob for each one. + * + * @param issueSpellCheck + * Determines to schedule a spell check or to refresh. + */ + private void refreshAllTextViewers(boolean issueSpellCheck) { + for (SpellCheckTextViewer viewer : textViewers) { + if (viewer.getDocument() != null) { + if (issueSpellCheck) { + viewer.scheduleSpellJob(true); + } else { + viewer.refresh(); + } + } + } + } + + /** + * Schedules a EnhancedSpellCheckJob for the SpellCheckTextViewer if spell + * checking is enabled. + * + * @param entireDocument + * Spell check the entire document or the current line. + */ private void scheduleSpellJob(boolean entireDocument) { if (store.getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED)) { EnhancedSpellCheckJob job = new EnhancedSpellCheckJob( @@ -254,6 +296,7 @@ public class SpellCheckTextViewer extends TextViewer implements job.setCollector(SpellCheckTextViewer.this); checkingSpelling = true; job.schedule(); + refresh(); } } }