1 4 package org.terracotta.dso.editors.xml; 5 6 import org.eclipse.jface.text.IDocument; 7 import org.eclipse.jface.text.ITextDoubleClickStrategy; 8 import org.eclipse.jface.text.TextAttribute; 9 import org.eclipse.jface.text.presentation.IPresentationReconciler; 10 import org.eclipse.jface.text.presentation.PresentationReconciler; 11 import org.eclipse.jface.text.rules.DefaultDamagerRepairer; 12 import org.eclipse.jface.text.rules.Token; 13 import org.eclipse.jface.text.source.ISourceViewer; 14 import org.eclipse.jface.text.source.SourceViewerConfiguration; 15 16 17 public class XMLConfiguration extends SourceViewerConfiguration { 18 private XMLDoubleClickStrategy doubleClickStrategy; 19 private XMLTagScanner tagScanner; 20 private XMLScanner scanner; 21 private ColorManager colorManager; 22 23 public XMLConfiguration(ColorManager colorManager) { 24 this.colorManager = colorManager; 25 } 26 public String [] getConfiguredContentTypes(ISourceViewer sourceViewer) { 27 return new String [] { 28 IDocument.DEFAULT_CONTENT_TYPE, 29 XMLPartitionScanner.XML_COMMENT, 30 XMLPartitionScanner.XML_TAG }; 31 } 32 public ITextDoubleClickStrategy getDoubleClickStrategy( 33 ISourceViewer sourceViewer, 34 String contentType) { 35 if (doubleClickStrategy == null) 36 doubleClickStrategy = new XMLDoubleClickStrategy(); 37 return doubleClickStrategy; 38 } 39 40 protected XMLScanner getXMLScanner() { 41 if (scanner == null) { 42 scanner = new XMLScanner(colorManager); 43 scanner.setDefaultReturnToken( 44 new Token( 45 new TextAttribute( 46 colorManager.getColor(IXMLColorConstants.DEFAULT)))); 47 } 48 return scanner; 49 } 50 protected XMLTagScanner getXMLTagScanner() { 51 if (tagScanner == null) { 52 tagScanner = new XMLTagScanner(colorManager); 53 tagScanner.setDefaultReturnToken( 54 new Token( 55 new TextAttribute( 56 colorManager.getColor(IXMLColorConstants.TAG)))); 57 } 58 return tagScanner; 59 } 60 61 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { 62 PresentationReconciler reconciler = new PresentationReconciler(); 63 64 DefaultDamagerRepairer dr = 65 new DefaultDamagerRepairer(getXMLTagScanner()); 66 reconciler.setDamager(dr, XMLPartitionScanner.XML_TAG); 67 reconciler.setRepairer(dr, XMLPartitionScanner.XML_TAG); 68 69 dr = new DefaultDamagerRepairer(getXMLScanner()); 70 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); 71 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); 72 73 NonRuleBasedDamagerRepairer ndr = 74 new NonRuleBasedDamagerRepairer( 75 new TextAttribute( 76 colorManager.getColor(IXMLColorConstants.XML_COMMENT))); 77 reconciler.setDamager(ndr, XMLPartitionScanner.XML_COMMENT); 78 reconciler.setRepairer(ndr, XMLPartitionScanner.XML_COMMENT); 79 80 return reconciler; 81 } 82 83 } | Popular Tags |