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