001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.examples.templateeditor.editors;
011:
012: import org.eclipse.jface.text.IDocument;
013: import org.eclipse.jface.text.ITextDoubleClickStrategy;
014: import org.eclipse.jface.text.TextAttribute;
015: import org.eclipse.jface.text.contentassist.ContentAssistant;
016: import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
017: import org.eclipse.jface.text.contentassist.IContentAssistant;
018: import org.eclipse.jface.text.presentation.IPresentationReconciler;
019: import org.eclipse.jface.text.presentation.PresentationReconciler;
020: import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
021: import org.eclipse.jface.text.rules.Token;
022: import org.eclipse.jface.text.source.ISourceViewer;
023:
024: import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
025: import org.eclipse.ui.examples.templateeditor.template.XMLCompletionProcessor;
026:
027: public class XMLConfiguration extends TextSourceViewerConfiguration {
028:
029: private XMLDoubleClickStrategy doubleClickStrategy;
030: private XMLTagScanner tagScanner;
031: private XMLScanner scanner;
032: private ColorManager colorManager;
033:
034: public XMLConfiguration(ColorManager colorManager) {
035: this .colorManager = colorManager;
036: }
037:
038: public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
039: return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
040: XMLPartitionScanner.XML_COMMENT,
041: XMLPartitionScanner.XML_TAG };
042: }
043:
044: public ITextDoubleClickStrategy getDoubleClickStrategy(
045: ISourceViewer sourceViewer, String contentType) {
046: if (doubleClickStrategy == null)
047: doubleClickStrategy = new XMLDoubleClickStrategy();
048: return doubleClickStrategy;
049: }
050:
051: protected XMLScanner getXMLScanner() {
052: if (scanner == null) {
053: scanner = new XMLScanner(colorManager);
054: scanner
055: .setDefaultReturnToken(new Token(
056: new TextAttribute(
057: colorManager
058: .getColor(IXMLColorConstants.DEFAULT))));
059: }
060: return scanner;
061: }
062:
063: protected XMLTagScanner getXMLTagScanner() {
064: if (tagScanner == null) {
065: tagScanner = new XMLTagScanner(colorManager);
066: tagScanner.setDefaultReturnToken(new Token(
067: new TextAttribute(colorManager
068: .getColor(IXMLColorConstants.TAG))));
069: }
070: return tagScanner;
071: }
072:
073: public IPresentationReconciler getPresentationReconciler(
074: ISourceViewer sourceViewer) {
075: PresentationReconciler reconciler = new PresentationReconciler();
076:
077: DefaultDamagerRepairer dr = new DefaultDamagerRepairer(
078: getXMLTagScanner());
079: reconciler.setDamager(dr, XMLPartitionScanner.XML_TAG);
080: reconciler.setRepairer(dr, XMLPartitionScanner.XML_TAG);
081:
082: dr = new DefaultDamagerRepairer(getXMLScanner());
083: reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
084: reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
085:
086: NonRuleBasedDamagerRepairer ndr = new NonRuleBasedDamagerRepairer(
087: new TextAttribute(colorManager
088: .getColor(IXMLColorConstants.XML_COMMENT)));
089: reconciler.setDamager(ndr, XMLPartitionScanner.XML_COMMENT);
090: reconciler.setRepairer(ndr, XMLPartitionScanner.XML_COMMENT);
091:
092: return reconciler;
093: }
094:
095: public IContentAssistant getContentAssistant(
096: ISourceViewer sourceViewer) {
097: ContentAssistant assistant = new ContentAssistant();
098: assistant
099: .setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
100:
101: IContentAssistProcessor processor = new XMLCompletionProcessor();
102: assistant.setContentAssistProcessor(processor,
103: IDocument.DEFAULT_CONTENT_TYPE);
104: assistant.setContentAssistProcessor(processor,
105: XMLPartitionScanner.XML_TAG);
106:
107: assistant
108: .setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
109: assistant
110: .setInformationControlCreator(getInformationControlCreator(sourceViewer));
111:
112: return assistant;
113: }
114:
115: }
|