misc
[phpeclipse.git] / net.sourceforge.phpeclipse.smarty.ui / src / net / sourceforge / phpdt / smarty / ui / internal / text / SmartyConfiguration.java
1 /*
2  * Created on 25.08.2004
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */
7 package net.sourceforge.phpdt.smarty.ui.internal.text;
8
9 import java.util.Map;
10
11 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLConfiguration;
12 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
13 import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools;
14
15 import org.eclipse.jface.text.IDocument;
16 import org.eclipse.jface.text.contentassist.ContentAssistant;
17 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
18 import org.eclipse.jface.text.contentassist.IContentAssistant;
19 import org.eclipse.jface.text.presentation.IPresentationReconciler;
20 import org.eclipse.jface.text.presentation.PresentationReconciler;
21 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
22 import org.eclipse.jface.text.source.ISourceViewer;
23 import org.eclipse.ui.texteditor.ITextEditor;
24
25 public class SmartyConfiguration extends XMLConfiguration {
26   private SmartyTagScanner smartyTagScanner;
27   public SmartyConfiguration(XMLTextTools tools) {
28     this(tools, null);
29   }
30
31   public SmartyConfiguration(XMLTextTools tools, ITextEditor editor) {
32     super(tools, editor);
33     Map tokens = tools.getTokens();
34     smartyTagScanner = new SmartyTagScanner(tokens);
35   }
36
37   public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
38     ContentAssistant assistant = new ContentAssistant();
39     assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
40
41     IContentAssistProcessor processor = new SmartyCompletionProcessor();
42     assistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE);
43     assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_TAG);
44     assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_PI);
45     assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_COMMENT);
46     assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_DECL);
47     assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_TAG);
48     assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_ATTRIBUTE);
49     assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_CDATA);
50
51     assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
52     assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
53
54     return assistant;
55   }
56         /**
57          * Returns a scanner which is configured to scan XML text.
58          * 
59          * @return  an XML text scanner
60          */
61         public SmartyTagScanner getSmartyScanner() {
62                 return smartyTagScanner;
63         }
64   /*
65    * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(ISourceViewer)
66    */
67   public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
68     PresentationReconciler reconciler = new PresentationReconciler();
69
70     DefaultDamagerRepairer dr;
71
72     dr = new DefaultDamagerRepairer(getSmartyScanner());
73     reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
74     reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
75
76     dr = new DefaultDamagerRepairer(xmlTextTools.getDTDTextScanner());
77     reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL);
78     reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL);
79
80     dr = new DefaultDamagerRepairer(xmlTextTools.getXMLPIScanner());
81
82     reconciler.setDamager(dr, XMLPartitionScanner.XML_PI);
83     reconciler.setRepairer(dr, XMLPartitionScanner.XML_PI);
84     reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL_PI);
85     reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL_PI);
86
87     dr = new DefaultDamagerRepairer(xmlTextTools.getXMLCommentScanner());
88
89     reconciler.setDamager(dr, XMLPartitionScanner.XML_COMMENT);
90     reconciler.setRepairer(dr, XMLPartitionScanner.XML_COMMENT);
91     reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL_COMMENT);
92     reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL_COMMENT);
93
94     dr = new DefaultDamagerRepairer(xmlTextTools.getXMLDeclScanner());
95
96     reconciler.setDamager(dr, XMLPartitionScanner.XML_DECL);
97     reconciler.setRepairer(dr, XMLPartitionScanner.XML_DECL);
98     reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL_DECL);
99     reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL_DECL);
100
101     dr = new DefaultDamagerRepairer(xmlTextTools.getXMLTagScanner());
102
103     reconciler.setDamager(dr, XMLPartitionScanner.XML_TAG);
104     reconciler.setRepairer(dr, XMLPartitionScanner.XML_TAG);
105
106     dr = new DefaultDamagerRepairer(xmlTextTools.getXMLAttributeScanner());
107
108     reconciler.setDamager(dr, XMLPartitionScanner.XML_ATTRIBUTE);
109     reconciler.setRepairer(dr, XMLPartitionScanner.XML_ATTRIBUTE);
110
111     dr = new DefaultDamagerRepairer(xmlTextTools.getXMLCDATAScanner());
112
113     reconciler.setDamager(dr, XMLPartitionScanner.XML_CDATA);
114     reconciler.setRepairer(dr, XMLPartitionScanner.XML_CDATA);
115
116     return reconciler;
117   }
118 }