/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*/
package org.sintef.thingml.resource.thingml.ui;
/**
* This class provides the configuration for the generated editor. It registers
* content assistance and syntax highlighting.
*/
public class ThingmlSourceViewerConfiguration extends org.eclipse.ui.editors.text.TextSourceViewerConfiguration {
private org.sintef.thingml.resource.thingml.ui.ThingmlColorManager colorManager;
private org.sintef.thingml.resource.thingml.IThingmlResourceProvider resourceProvider;
private org.sintef.thingml.resource.thingml.ui.IThingmlAnnotationModelProvider annotationModelProvider;
private org.sintef.thingml.resource.thingml.ui.IThingmlBracketHandlerProvider bracketHandlerProvider;
private org.sintef.thingml.resource.thingml.ui.ThingmlQuickAssistAssistant quickAssistAssistant;
/**
* Creates a new editor configuration.
*
* @param resourceProvider the provider for the resource (usually this is the
* editor)
* @param colorManager the color manager to use
*/
public ThingmlSourceViewerConfiguration(org.sintef.thingml.resource.thingml.IThingmlResourceProvider resourceProvider, org.sintef.thingml.resource.thingml.ui.IThingmlAnnotationModelProvider annotationModelProvider, org.sintef.thingml.resource.thingml.ui.IThingmlBracketHandlerProvider bracketHandlerProvider, org.sintef.thingml.resource.thingml.ui.ThingmlColorManager colorManager) {
super(org.sintef.thingml.resource.thingml.ui.ThingmlUIPlugin.getDefault().getPreferenceStore());
this.fPreferenceStore.setDefault(org.eclipse.ui.texteditor.spelling.SpellingService.PREFERENCE_SPELLING_ENABLED, true);
this.fPreferenceStore.setDefault(org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH, 4);
this.fPreferenceStore.setDefault(org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINK_KEY_MODIFIER, org.eclipse.jface.action.Action.findModifierString(org.eclipse.swt.SWT.MOD1));
this.resourceProvider = resourceProvider;
this.annotationModelProvider = annotationModelProvider;
this.bracketHandlerProvider = bracketHandlerProvider;
this.colorManager = colorManager;
}
public org.eclipse.jface.text.contentassist.IContentAssistant getContentAssistant(org.eclipse.jface.text.source.ISourceViewer sourceViewer) {
org.eclipse.jface.text.contentassist.ContentAssistant assistant = new org.eclipse.jface.text.contentassist.ContentAssistant();
assistant.setContentAssistProcessor(new org.sintef.thingml.resource.thingml.ui.ThingmlCompletionProcessor(resourceProvider, bracketHandlerProvider), org.eclipse.jface.text.IDocument.DEFAULT_CONTENT_TYPE);
assistant.enableAutoActivation(true);
assistant.setAutoActivationDelay(500);
assistant.setProposalPopupOrientation(org.eclipse.jface.text.contentassist.IContentAssistant.PROPOSAL_OVERLAY);
assistant.setContextInformationPopupOrientation(org.eclipse.jface.text.contentassist.IContentAssistant.CONTEXT_INFO_ABOVE);
return assistant;
}
public String[] getConfiguredContentTypes(org.eclipse.jface.text.source.ISourceViewer sourceViewer) {
return new String[] {
org.eclipse.jface.text.IDocument.DEFAULT_CONTENT_TYPE,
};
}
protected org.eclipse.jface.text.rules.ITokenScanner getScanner() {
return new org.sintef.thingml.resource.thingml.ui.ThingmlTokenScanner(resourceProvider.getResource(), colorManager);
}
public org.eclipse.jface.text.presentation.IPresentationReconciler getPresentationReconciler(org.eclipse.jface.text.source.ISourceViewer sourceViewer) {
org.eclipse.jface.text.presentation.PresentationReconciler reconciler = new org.eclipse.jface.text.presentation.PresentationReconciler();
org.eclipse.jface.text.rules.DefaultDamagerRepairer repairer = new org.eclipse.jface.text.rules.DefaultDamagerRepairer(getScanner());
reconciler.setDamager(repairer, org.eclipse.jface.text.IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setRepairer(repairer, org.eclipse.jface.text.IDocument.DEFAULT_CONTENT_TYPE);
return reconciler;
}
public org.eclipse.jface.text.source.IAnnotationHover getAnnotationHover(org.eclipse.jface.text.source.ISourceViewer sourceViewer) {
return new org.eclipse.jface.text.source.DefaultAnnotationHover();
}
public org.eclipse.jface.text.ITextHover getTextHover(org.eclipse.jface.text.source.ISourceViewer sourceViewer, String contentType) {
return new org.sintef.thingml.resource.thingml.ui.ThingmlTextHover(resourceProvider);
}
public org.eclipse.jface.text.hyperlink.IHyperlinkDetector[] getHyperlinkDetectors(org.eclipse.jface.text.source.ISourceViewer sourceViewer) {
if (sourceViewer == null) {
return null;
}
return new org.eclipse.jface.text.hyperlink.IHyperlinkDetector[] { new org.sintef.thingml.resource.thingml.ui.ThingmlHyperlinkDetector(resourceProvider.getResource()) };
}
public org.eclipse.jface.text.quickassist.IQuickAssistAssistant getQuickAssistAssistant(org.eclipse.jface.text.source.ISourceViewer sourceViewer) {
if (quickAssistAssistant == null) {
quickAssistAssistant = new org.sintef.thingml.resource.thingml.ui.ThingmlQuickAssistAssistant(resourceProvider, annotationModelProvider);
}
return quickAssistAssistant;
}
public org.eclipse.jface.text.reconciler.IReconciler getReconciler(final org.eclipse.jface.text.source.ISourceViewer sourceViewer) {
if (fPreferenceStore == null || !fPreferenceStore.getBoolean(org.eclipse.ui.texteditor.spelling.SpellingService.PREFERENCE_SPELLING_ENABLED)) {
return null;
}
org.eclipse.ui.texteditor.spelling.SpellingService spellingService = org.eclipse.ui.editors.text.EditorsUI.getSpellingService();
if (spellingService.getActiveSpellingEngineDescriptor(fPreferenceStore) == null) {
return null;
}
org.eclipse.jface.text.reconciler.IReconcilingStrategy strategy = new org.eclipse.ui.texteditor.spelling.SpellingReconcileStrategy(sourceViewer, spellingService) {
@Override
protected org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector createSpellingProblemCollector() {
final org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector collector = super.createSpellingProblemCollector();
return new org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector() {
public void accept(org.eclipse.ui.texteditor.spelling.SpellingProblem problem) {
int offset = problem.getOffset();
int length = problem.getLength();
if (sourceViewer == null) {
return;
}
org.eclipse.jface.text.IDocument document = sourceViewer.getDocument();
if (document == null) {
return;
}
String text;
try {
text = document.get(offset, length);
} catch (org.eclipse.jface.text.BadLocationException e) {
return;
}
if (new org.sintef.thingml.resource.thingml.ui.ThingmlIgnoredWordsFilter().ignoreWord(text)) {
return;
}
collector.accept(problem);
}
public void beginCollecting() {
collector.beginCollecting();
}
public void endCollecting() {
collector.endCollecting();
}
};
}
};
org.eclipse.jface.text.reconciler.MonoReconciler reconciler = new org.eclipse.jface.text.reconciler.MonoReconciler(strategy, false);
reconciler.setDelay(500);
return reconciler;
}
}