2 * Copyright (c) 2002-2004 Widespace, OU and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * Igor Malinin - initial contribution
11 * $Id: XMLConfiguration.java,v 1.1 2004-09-02 18:28:03 jsurfer Exp $
14 package net.sourceforge.phpeclipse.xml.ui.internal.text;
16 import net.sourceforge.phpeclipse.ui.templates.template.BasicCompletionProcessor;
17 import net.sourceforge.phpeclipse.ui.text.TextDoubleClickStrategy;
18 import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools;
20 import org.eclipse.core.runtime.NullProgressMonitor;
21 import org.eclipse.jface.text.IDocument;
22 import org.eclipse.jface.text.ITextDoubleClickStrategy;
23 import org.eclipse.jface.text.ITextHover;
24 import org.eclipse.jface.text.contentassist.ContentAssistant;
25 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
26 import org.eclipse.jface.text.contentassist.IContentAssistant;
27 import org.eclipse.jface.text.presentation.IPresentationReconciler;
28 import org.eclipse.jface.text.presentation.PresentationReconciler;
29 import org.eclipse.jface.text.reconciler.IReconciler;
30 import org.eclipse.jface.text.reconciler.MonoReconciler;
31 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
32 import org.eclipse.jface.text.source.IAnnotationHover;
33 import org.eclipse.jface.text.source.IAnnotationModel;
34 import org.eclipse.jface.text.source.ISourceViewer;
35 import org.eclipse.ui.IEditorInput;
36 import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
37 import org.eclipse.ui.texteditor.IDocumentProvider;
38 import org.eclipse.ui.texteditor.ITextEditor;
41 * XML editor configuration.
43 * @author Igor Malinin
45 public class XMLConfiguration extends TextSourceViewerConfiguration {
46 protected XMLTextTools xmlTextTools;
48 private ITextDoubleClickStrategy dcsDefault;
50 private ITextDoubleClickStrategy dcsSimple;
52 private ITextDoubleClickStrategy dcsTag;
54 private ITextDoubleClickStrategy dcsAttValue;
56 /** The associated editor. */
57 private ITextEditor editor;
59 public XMLConfiguration(XMLTextTools tools) {
63 public XMLConfiguration(XMLTextTools tools, ITextEditor editor) {
66 dcsDefault = new TextDoubleClickStrategy();
67 dcsSimple = new SimpleDoubleClickStrategy();
68 dcsTag = new TagDoubleClickStrategy();
69 dcsAttValue = new AttValueDoubleClickStrategy();
73 * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
75 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
76 return new XMLAnnotationHover();
80 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String)
82 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
84 IDocumentProvider provider = editor.getDocumentProvider();
85 IEditorInput input = editor.getEditorInput();
86 IAnnotationModel model = provider.getAnnotationModel(input);
87 return new XMLTextHover(model);
90 return super.getTextHover(sourceViewer, contentType);
94 * @see SourceViewerConfiguration#getDoubleClickStrategy(ISourceViewer, String)
96 public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
97 if (XMLPartitionScanner.XML_COMMENT.equals(contentType)) {
101 if (XMLPartitionScanner.XML_PI.equals(contentType)) {
105 if (XMLPartitionScanner.XML_TAG.equals(contentType)) {
109 if (XMLPartitionScanner.XML_ATTRIBUTE.equals(contentType)) {
113 if (XMLPartitionScanner.XML_CDATA.equals(contentType)) {
117 if (contentType.startsWith(XMLPartitionScanner.DTD_INTERNAL)) {
125 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredContentTypes(ISourceViewer)
127 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
128 return new String[] { IDocument.DEFAULT_CONTENT_TYPE, XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT,
129 XMLPartitionScanner.XML_DECL, XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_ATTRIBUTE,
130 XMLPartitionScanner.XML_CDATA, XMLPartitionScanner.DTD_INTERNAL, XMLPartitionScanner.DTD_INTERNAL_PI,
131 XMLPartitionScanner.DTD_INTERNAL_COMMENT, XMLPartitionScanner.DTD_INTERNAL_DECL, };
135 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(ISourceViewer)
137 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
138 PresentationReconciler reconciler = new PresentationReconciler();
140 DefaultDamagerRepairer dr;
142 dr = new DefaultDamagerRepairer(xmlTextTools.getXMLTextScanner());
143 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
144 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
146 dr = new DefaultDamagerRepairer(xmlTextTools.getDTDTextScanner());
147 reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL);
148 reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL);
150 dr = new DefaultDamagerRepairer(xmlTextTools.getXMLPIScanner());
152 reconciler.setDamager(dr, XMLPartitionScanner.XML_PI);
153 reconciler.setRepairer(dr, XMLPartitionScanner.XML_PI);
154 reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL_PI);
155 reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL_PI);
157 dr = new DefaultDamagerRepairer(xmlTextTools.getXMLCommentScanner());
159 reconciler.setDamager(dr, XMLPartitionScanner.XML_COMMENT);
160 reconciler.setRepairer(dr, XMLPartitionScanner.XML_COMMENT);
161 reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL_COMMENT);
162 reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL_COMMENT);
164 dr = new DefaultDamagerRepairer(xmlTextTools.getXMLDeclScanner());
166 reconciler.setDamager(dr, XMLPartitionScanner.XML_DECL);
167 reconciler.setRepairer(dr, XMLPartitionScanner.XML_DECL);
168 reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL_DECL);
169 reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL_DECL);
171 dr = new DefaultDamagerRepairer(xmlTextTools.getXMLTagScanner());
173 reconciler.setDamager(dr, XMLPartitionScanner.XML_TAG);
174 reconciler.setRepairer(dr, XMLPartitionScanner.XML_TAG);
176 dr = new DefaultDamagerRepairer(xmlTextTools.getXMLAttributeScanner());
178 reconciler.setDamager(dr, XMLPartitionScanner.XML_ATTRIBUTE);
179 reconciler.setRepairer(dr, XMLPartitionScanner.XML_ATTRIBUTE);
181 dr = new DefaultDamagerRepairer(xmlTextTools.getXMLCDATAScanner());
183 reconciler.setDamager(dr, XMLPartitionScanner.XML_CDATA);
184 reconciler.setRepairer(dr, XMLPartitionScanner.XML_CDATA);
190 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
192 public IReconciler getReconciler(ISourceViewer sourceViewer) {
193 if ((editor != null) && editor.isEditable()) {
194 MonoReconciler reconciler = new MonoReconciler(new XMLReconcilingStrategy(editor), false);
195 reconciler.setProgressMonitor(new NullProgressMonitor());
196 reconciler.setDelay(500);
203 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
204 ContentAssistant assistant = new ContentAssistant();
205 assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
207 IContentAssistProcessor processor = new BasicCompletionProcessor();
208 assistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE);
209 assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_TAG);
210 assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_PI);
211 assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_COMMENT);
212 assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_DECL);
213 assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_TAG);
214 assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_ATTRIBUTE);
215 assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_CDATA);
216 assistant.setContentAssistProcessor(processor, XMLPartitionScanner.DTD_INTERNAL);
217 assistant.setContentAssistProcessor(processor, XMLPartitionScanner.DTD_INTERNAL_PI);
218 assistant.setContentAssistProcessor(processor, XMLPartitionScanner.DTD_INTERNAL_COMMENT);
219 assistant.setContentAssistProcessor(processor, XMLPartitionScanner.DTD_INTERNAL_DECL);
220 assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
221 assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));