refactory: added UI removed from core plugin.
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpeclipse / xml / ui / internal / text / DTDConfiguration.java
1 /*
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
7  *
8  * Contributors:
9  *     Igor Malinin - initial contribution
10  *
11  * $Id: DTDConfiguration.java,v 1.3 2006-10-21 23:14:13 pombredanne Exp $
12  */
13
14 package net.sourceforge.phpeclipse.xml.ui.internal.text;
15
16 import net.sourceforge.phpeclipse.ui.text.TextDoubleClickStrategy;
17 import net.sourceforge.phpeclipse.xml.ui.text.DTDTextTools;
18
19 import org.eclipse.jface.text.IDocument;
20 import org.eclipse.jface.text.ITextDoubleClickStrategy;
21 import org.eclipse.jface.text.presentation.IPresentationReconciler;
22 import org.eclipse.jface.text.presentation.PresentationReconciler;
23 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
24 import org.eclipse.jface.text.source.ISourceViewer;
25 import org.eclipse.jface.text.source.SourceViewerConfiguration;
26
27 /**
28  * DTD editor configuration.
29  * 
30  * @author Igor Malinin
31  */
32 public class DTDConfiguration extends SourceViewerConfiguration {
33         private DTDTextTools dtdTextTools;
34
35         private ITextDoubleClickStrategy dcsDefault;
36
37         private ITextDoubleClickStrategy dcsSimple;
38
39         public DTDConfiguration(DTDTextTools tools) {
40                 dtdTextTools = tools;
41
42                 dcsDefault = new TextDoubleClickStrategy();
43                 dcsSimple = new SimpleDoubleClickStrategy();
44         }
45
46         /*
47          * @see SourceViewerConfiguration#getDoubleClickStrategy(ISourceViewer,
48          *      String)
49          */
50         public ITextDoubleClickStrategy getDoubleClickStrategy(
51                         ISourceViewer sourceViewer, String contentType) {
52                 if (XMLPartitionScanner.XML_PI.equals(contentType)) {
53                         return dcsSimple;
54                 }
55
56                 if (XMLPartitionScanner.XML_COMMENT.equals(contentType)) {
57                         return dcsSimple;
58                 }
59
60                 if (XMLPartitionScanner.XML_DECL.equals(contentType)) {
61                         return dcsSimple;
62                 }
63
64                 if (XMLPartitionScanner.DTD_CONDITIONAL.equals(contentType)) {
65                         return dcsSimple;
66                 }
67
68                 return dcsDefault;
69         }
70
71         /*
72          * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredContentTypes(ISourceViewer)
73          */
74         public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
75                 return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
76                                 XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT,
77                                 XMLPartitionScanner.XML_DECL,
78                                 XMLPartitionScanner.DTD_CONDITIONAL, };
79         }
80
81         /*
82          * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(ISourceViewer)
83          */
84         public IPresentationReconciler getPresentationReconciler(
85                         ISourceViewer sourceViewer) {
86                 PresentationReconciler reconciler = new PresentationReconciler();
87
88                 DefaultDamagerRepairer dr;
89
90                 dr = new DefaultDamagerRepairer(dtdTextTools.getDTDTextScanner());
91                 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
92                 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
93
94                 reconciler.setDamager(dr, XMLPartitionScanner.XML_PI);
95                 reconciler.setRepairer(dr, XMLPartitionScanner.XML_PI);
96
97                 dr = new DefaultDamagerRepairer(dtdTextTools.getXMLPIScanner());
98
99                 reconciler.setDamager(dr, XMLPartitionScanner.XML_PI);
100                 reconciler.setRepairer(dr, XMLPartitionScanner.XML_PI);
101
102                 dr = new DefaultDamagerRepairer(dtdTextTools.getXMLCommentScanner());
103
104                 reconciler.setDamager(dr, XMLPartitionScanner.XML_COMMENT);
105                 reconciler.setRepairer(dr, XMLPartitionScanner.XML_COMMENT);
106
107                 dr = new DefaultDamagerRepairer(dtdTextTools.getXMLDeclScanner());
108
109                 reconciler.setDamager(dr, XMLPartitionScanner.XML_DECL);
110                 reconciler.setRepairer(dr, XMLPartitionScanner.XML_DECL);
111
112                 dr = new DefaultDamagerRepairer(dtdTextTools.getDTDConditionalScanner());
113
114                 reconciler.setDamager(dr, XMLPartitionScanner.DTD_CONDITIONAL);
115                 reconciler.setRepairer(dr, XMLPartitionScanner.DTD_CONDITIONAL);
116
117                 return reconciler;
118         }
119 }