Organized imports
[phpeclipse.git] / net.sourceforge.phpeclipse.xml.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.2 2005-05-06 00:55:41 stefanbjarni 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 /**
29  * DTD editor configuration.
30  * 
31  * @author Igor Malinin
32  */
33 public class DTDConfiguration extends SourceViewerConfiguration {
34         private DTDTextTools dtdTextTools;
35
36         private ITextDoubleClickStrategy dcsDefault;
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, String)
48          */
49         public ITextDoubleClickStrategy getDoubleClickStrategy(
50                 ISourceViewer sourceViewer, String contentType
51         ) {
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[] {
76                         IDocument.DEFAULT_CONTENT_TYPE,
77                         XMLPartitionScanner.XML_PI,
78                         XMLPartitionScanner.XML_COMMENT,
79                         XMLPartitionScanner.XML_DECL,
80                         XMLPartitionScanner.DTD_CONDITIONAL,
81                 };
82         }
83
84         /*
85          * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(ISourceViewer)
86          */
87         public IPresentationReconciler getPresentationReconciler(
88                 ISourceViewer sourceViewer
89         ) {
90                 PresentationReconciler reconciler = new PresentationReconciler();
91
92                 DefaultDamagerRepairer dr;
93
94                 dr = new DefaultDamagerRepairer( dtdTextTools.getDTDTextScanner() );
95                 reconciler.setDamager( dr, IDocument.DEFAULT_CONTENT_TYPE );
96                 reconciler.setRepairer( dr, IDocument.DEFAULT_CONTENT_TYPE );
97
98                 reconciler.setDamager( dr, XMLPartitionScanner.XML_PI );
99                 reconciler.setRepairer( dr, XMLPartitionScanner.XML_PI );
100
101                 dr = new DefaultDamagerRepairer( dtdTextTools.getXMLPIScanner() );
102
103                 reconciler.setDamager( dr, XMLPartitionScanner.XML_PI );
104                 reconciler.setRepairer( dr, XMLPartitionScanner.XML_PI );
105
106                 dr = new DefaultDamagerRepairer( dtdTextTools.getXMLCommentScanner() );
107
108                 reconciler.setDamager( dr, XMLPartitionScanner.XML_COMMENT );
109                 reconciler.setRepairer( dr, XMLPartitionScanner.XML_COMMENT );
110
111                 dr = new DefaultDamagerRepairer( dtdTextTools.getXMLDeclScanner() );
112
113                 reconciler.setDamager( dr, XMLPartitionScanner.XML_DECL );
114                 reconciler.setRepairer( dr, XMLPartitionScanner.XML_DECL );
115
116                 dr = new DefaultDamagerRepairer( dtdTextTools.getDTDConditionalScanner() );
117
118                 reconciler.setDamager( dr, XMLPartitionScanner.DTD_CONDITIONAL );
119                 reconciler.setRepairer( dr, XMLPartitionScanner.DTD_CONDITIONAL );
120
121                 return reconciler;
122         }
123 }