Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Enabling spell check for my editor created(How to enable spell check)
Enabling spell check for my editor created [message #1151320] Wed, 23 October 2013 09:06 Go to next message
Karthik Natarajan is currently offline Karthik NatarajanFriend
Messages: 43
Registered: July 2009
Location: Bangalore
Member

Hi,

Thanks in advance...

I stuggling to enable spell check in editor created *.psql, *.proc and more...

Can any one tell me how to bring eclipse provided default spell check feature (Ex: Text Editor) to bring down to my editor


Thanks & Regards
Karthik Natarajan


Regards
Karthik Natarajan
Re: Enabling spell check for my editor created [message #1187563 is a reply to message #1151320] Fri, 15 November 2013 06:59 Go to previous message
Karthik Natarajan is currently offline Karthik NatarajanFriend
Messages: 43
Registered: July 2009
Location: Bangalore
Member

Hi All,

Happy to share my findings... Below the simple steps to create spell checker for your custom editor

1. Create Editor
import org.eclipse.ui.editors.text.TextEditor;
public class DodoEditor extends TextEditor {
public DodoEditor() {
// TODO Auto-generated constructor stub
setSourceViewerConfiguration(new MySourceViewerConfig(getPreferenceStore()));
}
}

2. Create 'MySourceViewerConfig' as below --> Run and see
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.DefaultInformationControl;
import org.eclipse.jface.text.DefaultTextHover;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.ITextHoverExtension;
import org.eclipse.jface.text.quickassist.IQuickAssistAssistant;
import org.eclipse.jface.text.quickassist.QuickAssistAssistant;
import org.eclipse.jface.text.reconciler.IReconciler;
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
import org.eclipse.jface.text.reconciler.MonoReconciler;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.internal.editors.text.EditorsPlugin;
import org.eclipse.ui.texteditor.spelling.SpellingCorrectionProcessor;
import org.eclipse.ui.texteditor.spelling.SpellingReconcileStrategy;
import org.eclipse.ui.texteditor.spelling.SpellingService;


public class MySourceViewerConfig extends SourceViewerConfiguration {

private IPreferenceStore fpreferenceStore;

public MySourceViewerConfig(IPreferenceStore preferenceStore) {
// TODO Auto-generated constructor stub
fpreferenceStore = preferenceStore;
}
public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
return new TextHover(sourceViewer);
}
private final class TextHover extends DefaultTextHover implements ITextHoverExtension {
public TextHover(ISourceViewer sourceViewer) {
super(sourceViewer);
}
/*
* @see org.eclipse.jface.text.ITextHoverExtension#getHoverControlCreator()
*/
public IInformationControlCreator getHoverControlCreator() {
return new IInformationControlCreator() {
public IInformationControl createInformationControl(Shell parent) {
return new DefaultInformationControl(parent, EditorsUI.getTooltipAffordanceString());
}
};
}
}
public IReconciler getReconciler(ISourceViewer sourceViewer) {
if (fpreferenceStore == null || !fpreferenceStore.getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED))
return null;

SpellingService spellingService= EditorsUI.getSpellingService();
if (spellingService.getActiveSpellingEngineDescriptor(fpreferenceStore) == null)
return null;

IReconcilingStrategy strategy= new SpellingReconcileStrategy(sourceViewer, spellingService);
MonoReconciler reconciler= new MonoReconciler(strategy, false);
reconciler.setDelay(500);
return reconciler;
}
public IQuickAssistAssistant getQuickAssistAssistant(ISourceViewer sourceViewer) {
if (fpreferenceStore == null || !fpreferenceStore.getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED))
return null;

QuickAssistAssistant assistant= new QuickAssistAssistant();
assistant.setQuickAssistProcessor(new SpellingCorrectionProcessor());
assistant.setRestoreCompletionProposalSize(EditorsPlugin.getDefault().getDialogSettingsSection("quick_assist_proposal_size")); //$NON-NLS-1$
assistant.setInformationControlCreator(getQuickAssistAssistantInformationControlCreator());

return assistant;
}
private IInformationControlCreator getQuickAssistAssistantInformationControlCreator() {
return new IInformationControlCreator() {
public IInformationControl createInformationControl(Shell parent) {
return new DefaultInformationControl(parent, EditorsPlugin.getAdditionalInfoAffordanceString());
}
};
}
}


Regards
Karthik Natarajan
Previous Topic:EJB Project create window is not found in Juno Version: 4.2.2
Next Topic:The project: xxxxx which is referenced by the classpath, does not exist
Goto Forum:
  


Current Time: Thu Mar 28 21:57:56 GMT 2024

Powered by FUDForum. Page generated in 0.02868 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top