package tool.editors;
import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextDoubleClickStrategy;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContentAssistant;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
import tool.editors.contentassist.ToolTemplateAssistProcessor;
import tool.editors.text.ToolPartitionScanner;
import tool.editors.text.ToolScanner;
import tool.editors.text.sql.SQLScanner;
public class ToolSourceViewerConfiguration extends TextSourceViewerConfiguration {
private ToolSourceDoubleClickStrategy doubleClickStrategy;
private ToolScanner scanner;
private ColorManager colorManager;
private ContentAssistant contentAssistant;
public ToolSourceViewerConfiguration(ColorManager colorManager) {
this.colorManager = colorManager;
}
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
return new String[] {
IDocument.DEFAULT_CONTENT_TYPE,
ToolPartitionScanner.TOOL_COMMENT,
ToolPartitionScanner.TOOL_SQL };
}
public ITextDoubleClickStrategy getDoubleClickStrategy(
ISourceViewer sourceViewer,
String contentType) {
if (doubleClickStrategy == null)
doubleClickStrategy = new ToolSourceDoubleClickStrategy();
return doubleClickStrategy;
}
protected ToolScanner getToolScanner() {
if (scanner == null) {
scanner = new ToolScanner(colorManager);
scanner.setDefaultReturnToken(
new Token(
new TextAttribute(
colorManager.getColor(IToolColorConstants.DEFAULT))));
}
return scanner;
}
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
PresentationReconciler reconciler = new PresentationReconciler();
//TOOL
DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getToolScanner());
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
//SQL
DefaultDamagerRepairer sqldr =
new DefaultDamagerRepairer(new SQLScanner());
reconciler.setDamager(sqldr, ToolPartitionScanner.TOOL_SQL);
reconciler.setRepairer(sqldr, ToolPartitionScanner.TOOL_SQL);
//Comments
NonRuleBasedDamagerRepairer ndr =
new NonRuleBasedDamagerRepairer(
new TextAttribute(
colorManager.getColor(IToolColorConstants.TOOL_COMMENT)));
reconciler.setDamager(ndr, ToolPartitionScanner.TOOL_COMMENT);
reconciler.setRepairer(ndr, ToolPartitionScanner.TOOL_COMMENT);
return reconciler;
}
@Override
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
if (this.contentAssistant == null){
contentAssistant = new ContentAssistant();
IContentAssistProcessor cap =
//new ToolCompletionProcessor(null);
new ToolTemplateAssistProcessor();
contentAssistant.setContentAssistProcessor(cap, IDocument.DEFAULT_CONTENT_TYPE);
contentAssistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
}
return contentAssistant;
}
@Override
public IAutoEditStrategy[] getAutoEditStrategies(
ISourceViewer sourceViewer, String contentType) {
IAutoEditStrategy strategy = (IDocument.DEFAULT_CONTENT_TYPE
.equals(contentType) ? new ToolAutoEditStrategy()
: new DefaultIndentLineAutoEditStrategy());
return new IAutoEditStrategy[] { strategy };
}
}