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.2 2006-10-21 23:14:13 pombredanne 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,
85 IDocumentProvider provider = editor.getDocumentProvider();
86 IEditorInput input = editor.getEditorInput();
87 IAnnotationModel model = provider.getAnnotationModel(input);
88 return new XMLTextHover(model);
91 return super.getTextHover(sourceViewer, contentType);
95 * @see SourceViewerConfiguration#getDoubleClickStrategy(ISourceViewer,
98 public ITextDoubleClickStrategy getDoubleClickStrategy(
99 ISourceViewer sourceViewer, String contentType) {
100 if (XMLPartitionScanner.XML_COMMENT.equals(contentType)) {
104 if (XMLPartitionScanner.XML_PI.equals(contentType)) {
108 if (XMLPartitionScanner.XML_TAG.equals(contentType)) {
112 if (XMLPartitionScanner.XML_ATTRIBUTE.equals(contentType)) {
116 if (XMLPartitionScanner.XML_CDATA.equals(contentType)) {
120 if (contentType.startsWith(XMLPartitionScanner.DTD_INTERNAL)) {
128 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredContentTypes(ISourceViewer)
130 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
131 return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
132 XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT,
133 XMLPartitionScanner.XML_DECL, XMLPartitionScanner.XML_TAG,
134 XMLPartitionScanner.XML_ATTRIBUTE,
135 XMLPartitionScanner.XML_CDATA,
136 XMLPartitionScanner.DTD_INTERNAL,
137 XMLPartitionScanner.DTD_INTERNAL_PI,
138 XMLPartitionScanner.DTD_INTERNAL_COMMENT,
139 XMLPartitionScanner.DTD_INTERNAL_DECL, };
143 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(ISourceViewer)
145 public IPresentationReconciler getPresentationReconciler(
146 ISourceViewer sourceViewer) {
147 PresentationReconciler reconciler = new PresentationReconciler();
149 DefaultDamagerRepairer dr;
151 dr = new DefaultDamagerRepairer(xmlTextTools.getXMLTextScanner());
152 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
153 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
155 dr = new DefaultDamagerRepairer(xmlTextTools.getDTDTextScanner());
156 reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL);
157 reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL);
159 dr = new DefaultDamagerRepairer(xmlTextTools.getXMLPIScanner());
161 reconciler.setDamager(dr, XMLPartitionScanner.XML_PI);
162 reconciler.setRepairer(dr, XMLPartitionScanner.XML_PI);
163 reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL_PI);
164 reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL_PI);
166 dr = new DefaultDamagerRepairer(xmlTextTools.getXMLCommentScanner());
168 reconciler.setDamager(dr, XMLPartitionScanner.XML_COMMENT);
169 reconciler.setRepairer(dr, XMLPartitionScanner.XML_COMMENT);
170 reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL_COMMENT);
171 reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL_COMMENT);
173 dr = new DefaultDamagerRepairer(xmlTextTools.getXMLDeclScanner());
175 reconciler.setDamager(dr, XMLPartitionScanner.XML_DECL);
176 reconciler.setRepairer(dr, XMLPartitionScanner.XML_DECL);
177 reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL_DECL);
178 reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL_DECL);
180 dr = new DefaultDamagerRepairer(xmlTextTools.getXMLTagScanner());
182 reconciler.setDamager(dr, XMLPartitionScanner.XML_TAG);
183 reconciler.setRepairer(dr, XMLPartitionScanner.XML_TAG);
185 dr = new DefaultDamagerRepairer(xmlTextTools.getXMLAttributeScanner());
187 reconciler.setDamager(dr, XMLPartitionScanner.XML_ATTRIBUTE);
188 reconciler.setRepairer(dr, XMLPartitionScanner.XML_ATTRIBUTE);
190 dr = new DefaultDamagerRepairer(xmlTextTools.getXMLCDATAScanner());
192 reconciler.setDamager(dr, XMLPartitionScanner.XML_CDATA);
193 reconciler.setRepairer(dr, XMLPartitionScanner.XML_CDATA);
199 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
201 public IReconciler getReconciler(ISourceViewer sourceViewer) {
202 if ((editor != null) && editor.isEditable()) {
203 MonoReconciler reconciler = new MonoReconciler(
204 new XMLReconcilingStrategy(editor), false);
205 reconciler.setProgressMonitor(new NullProgressMonitor());
206 reconciler.setDelay(500);
213 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
214 ContentAssistant assistant = new ContentAssistant();
216 .setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
218 IContentAssistProcessor processor = new BasicCompletionProcessor();
219 assistant.setContentAssistProcessor(processor,
220 IDocument.DEFAULT_CONTENT_TYPE);
221 assistant.setContentAssistProcessor(processor,
222 XMLPartitionScanner.XML_TAG);
223 assistant.setContentAssistProcessor(processor,
224 XMLPartitionScanner.XML_PI);
225 assistant.setContentAssistProcessor(processor,
226 XMLPartitionScanner.XML_COMMENT);
227 assistant.setContentAssistProcessor(processor,
228 XMLPartitionScanner.XML_DECL);
229 assistant.setContentAssistProcessor(processor,
230 XMLPartitionScanner.XML_TAG);
231 assistant.setContentAssistProcessor(processor,
232 XMLPartitionScanner.XML_ATTRIBUTE);
233 assistant.setContentAssistProcessor(processor,
234 XMLPartitionScanner.XML_CDATA);
235 assistant.setContentAssistProcessor(processor,
236 XMLPartitionScanner.DTD_INTERNAL);
237 assistant.setContentAssistProcessor(processor,
238 XMLPartitionScanner.DTD_INTERNAL_PI);
239 assistant.setContentAssistProcessor(processor,
240 XMLPartitionScanner.DTD_INTERNAL_COMMENT);
241 assistant.setContentAssistProcessor(processor,
242 XMLPartitionScanner.DTD_INTERNAL_DECL);
244 .setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
246 .setInformationControlCreator(getInformationControlCreator(sourceViewer));