XMLConfiguration.java
上传用户:fanxing
上传日期:2017-01-19
资源大小:36k
文件大小:4k
- /*******************************************************************************
- * Copyright (c) 2005 Prashant Deva.
-
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License - v 1.0
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- *******************************************************************************/
- package projection_test.editors;
- 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.IContentAssistant;
- import org.eclipse.jface.text.presentation.IPresentationReconciler;
- import org.eclipse.jface.text.presentation.PresentationReconciler;
- import org.eclipse.jface.text.reconciler.IReconciler;
- import org.eclipse.jface.text.reconciler.MonoReconciler;
- import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
- import org.eclipse.jface.text.rules.Token;
- import org.eclipse.jface.text.source.ISourceViewer;
- import org.eclipse.jface.text.source.SourceViewerConfiguration;
- public class XMLConfiguration extends SourceViewerConfiguration {
- private XMLDoubleClickStrategy doubleClickStrategy;
- private XMLTagScanner tagScanner;
- private XMLScanner scanner;
- private ColorManager colorManager;
- private XMLEditor editor;
- public XMLConfiguration(ColorManager colorManager,XMLEditor editor) {
- this.colorManager = colorManager;
- this.editor = editor;
- }
- public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
- return new String[] {
- IDocument.DEFAULT_CONTENT_TYPE,
- XMLPartitionScanner.XML_COMMENT,
- XMLPartitionScanner.XML_TAG };
- }
- public ITextDoubleClickStrategy getDoubleClickStrategy(
- ISourceViewer sourceViewer,
- String contentType) {
- if (doubleClickStrategy == null)
- doubleClickStrategy = new XMLDoubleClickStrategy();
- return doubleClickStrategy;
- }
- protected XMLScanner getXMLScanner() {
- if (scanner == null) {
- scanner = new XMLScanner(colorManager);
- scanner.setDefaultReturnToken(
- new Token(
- new TextAttribute(
- colorManager.getColor(IXMLColorConstants.DEFAULT))));
- }
- return scanner;
- }
- protected XMLTagScanner getXMLTagScanner() {
- if (tagScanner == null) {
- tagScanner = new XMLTagScanner(colorManager);
- tagScanner.setDefaultReturnToken(
- new Token(
- new TextAttribute(
- colorManager.getColor(IXMLColorConstants.TAG))));
- }
- return tagScanner;
- }
- public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
- PresentationReconciler reconciler = new PresentationReconciler();
- DefaultDamagerRepairer dr =
- new DefaultDamagerRepairer(getXMLTagScanner());
- reconciler.setDamager(dr, XMLPartitionScanner.XML_TAG);
- reconciler.setRepairer(dr, XMLPartitionScanner.XML_TAG);
- dr = new DefaultDamagerRepairer(getXMLScanner());
- reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
- reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
- NonRuleBasedDamagerRepairer ndr =
- new NonRuleBasedDamagerRepairer(
- new TextAttribute(
- colorManager.getColor(IXMLColorConstants.XML_COMMENT)));
- reconciler.setDamager(ndr, XMLPartitionScanner.XML_COMMENT);
- reconciler.setRepairer(ndr, XMLPartitionScanner.XML_COMMENT);
- return reconciler;
- }
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getContentAssistant(org.eclipse.jface.text.source.ISourceViewer)
- */
- public IContentAssistant getContentAssistant(ISourceViewer sourceViewer)
- {
- ContentAssistant assistant = new ContentAssistant();
- assistant.setContentAssistProcessor(new XMLContentAssistantProcessor(),IDocument.DEFAULT_CONTENT_TYPE);
- assistant.enableAutoActivation(true);
-
- return assistant;
- }
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getReconciler(org.eclipse.jface.text.source.ISourceViewer)
- */
- public IReconciler getReconciler(ISourceViewer sourceViewer)
- {
- XmlReconcilingStrategy strategy = new XmlReconcilingStrategy();
- strategy.setEditor(editor);
-
- MonoReconciler reconciler = new MonoReconciler(strategy,false);
-
- return reconciler;
- }
- }