001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package org.terracotta.dso.editors.xml;
006:
007: import org.eclipse.jface.text.IDocument;
008: import org.eclipse.jface.text.ITextDoubleClickStrategy;
009: import org.eclipse.jface.text.TextAttribute;
010: import org.eclipse.jface.text.presentation.IPresentationReconciler;
011: import org.eclipse.jface.text.presentation.PresentationReconciler;
012: import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
013: import org.eclipse.jface.text.rules.Token;
014: import org.eclipse.jface.text.source.Annotation;
015: import org.eclipse.jface.text.source.DefaultAnnotationHover;
016: import org.eclipse.jface.text.source.IAnnotationHover;
017: import org.eclipse.jface.text.source.ISourceViewer;
018: import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
019:
020: public class XMLConfiguration extends TextSourceViewerConfiguration {
021: private XMLDoubleClickStrategy doubleClickStrategy;
022: private XMLTagScanner tagScanner;
023: private XMLScanner scanner;
024: private ColorManager colorManager;
025:
026: public XMLConfiguration(ColorManager colorManager) {
027: this .colorManager = colorManager;
028: }
029:
030: public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
031: return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
032: XMLPartitionScanner.XML_COMMENT,
033: XMLPartitionScanner.XML_TAG };
034: }
035:
036: public ITextDoubleClickStrategy getDoubleClickStrategy(
037: ISourceViewer sourceViewer, String contentType) {
038: if (doubleClickStrategy == null)
039: doubleClickStrategy = new XMLDoubleClickStrategy();
040: return doubleClickStrategy;
041: }
042:
043: protected XMLScanner getXMLScanner() {
044: if (scanner == null) {
045: scanner = new XMLScanner(colorManager);
046: scanner
047: .setDefaultReturnToken(new Token(
048: new TextAttribute(
049: colorManager
050: .getColor(IXMLColorConstants.DEFAULT))));
051: }
052: return scanner;
053: }
054:
055: protected XMLTagScanner getXMLTagScanner() {
056: if (tagScanner == null) {
057: tagScanner = new XMLTagScanner(colorManager);
058: tagScanner.setDefaultReturnToken(new Token(
059: new TextAttribute(colorManager
060: .getColor(IXMLColorConstants.TAG))));
061: }
062: return tagScanner;
063: }
064:
065: public IPresentationReconciler getPresentationReconciler(
066: ISourceViewer sourceViewer) {
067: PresentationReconciler reconciler = new PresentationReconciler();
068:
069: DefaultDamagerRepairer dr = new DefaultDamagerRepairer(
070: getXMLTagScanner());
071: reconciler.setDamager(dr, XMLPartitionScanner.XML_TAG);
072: reconciler.setRepairer(dr, XMLPartitionScanner.XML_TAG);
073:
074: dr = new DefaultDamagerRepairer(getXMLScanner());
075: reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
076: reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
077:
078: NonRuleBasedDamagerRepairer ndr = new NonRuleBasedDamagerRepairer(
079: new TextAttribute(colorManager
080: .getColor(IXMLColorConstants.XML_COMMENT)));
081: reconciler.setDamager(ndr, XMLPartitionScanner.XML_COMMENT);
082: reconciler.setRepairer(ndr, XMLPartitionScanner.XML_COMMENT);
083:
084: return reconciler;
085: }
086:
087: public IAnnotationHover getAnnotationHover(
088: ISourceViewer sourceViewer) {
089: return new DefaultAnnotationHover() {
090: protected boolean isIncluded(Annotation annotation) {
091: return isShowInVerticalRuler(annotation);
092: }
093: };
094: }
095:
096: /*
097: * @see SourceViewerConfiguration#getOverviewRulerAnnotationHover(ISourceViewer)
098: * @since 3.0
099: */
100: public IAnnotationHover getOverviewRulerAnnotationHover(
101: ISourceViewer sourceViewer) {
102: return new DefaultAnnotationHover() {
103: protected boolean isIncluded(Annotation annotation) {
104: return isShowInOverviewRuler(annotation);
105: }
106: };
107: }
108: }
|