KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > XMLConfiguration


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.editor;
12
13 import org.eclipse.jface.text.IDocument;
14 import org.eclipse.jface.text.ITextDoubleClickStrategy;
15 import org.eclipse.jface.text.TextAttribute;
16 import org.eclipse.jface.text.presentation.IPresentationReconciler;
17 import org.eclipse.jface.text.presentation.PresentationReconciler;
18 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
19 import org.eclipse.jface.text.rules.Token;
20 import org.eclipse.jface.text.source.IAnnotationHover;
21 import org.eclipse.jface.text.source.ISourceViewer;
22 import org.eclipse.pde.internal.ui.editor.text.AnnotationHover;
23 import org.eclipse.pde.internal.ui.editor.text.IColorManager;
24 import org.eclipse.pde.internal.ui.editor.text.IPDEColorConstants;
25 import org.eclipse.pde.internal.ui.editor.text.NonRuleBasedDamagerRepairer;
26 import org.eclipse.pde.internal.ui.editor.text.XMLPartitionScanner;
27 import org.eclipse.pde.internal.ui.editor.text.XMLScanner;
28 import org.eclipse.pde.internal.ui.editor.text.XMLTagScanner;
29 import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
30
31 public class XMLConfiguration extends TextSourceViewerConfiguration {
32     private XMLDoubleClickStrategy doubleClickStrategy;
33     private XMLTagScanner tagScanner;
34     private XMLScanner pdeScanner;
35     private IColorManager colorManager;
36
37     public XMLConfiguration(IColorManager colorManager) {
38         setColorManager(colorManager);
39     }
40     
41     public void setColorManager(IColorManager colorManager) {
42         this.colorManager = colorManager;
43     }
44     
45     public String JavaDoc[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
46         return new String JavaDoc[] {
47             IDocument.DEFAULT_CONTENT_TYPE,
48             XMLPartitionScanner.XML_COMMENT,
49             XMLPartitionScanner.XML_TAG };
50     }
51     public ITextDoubleClickStrategy getDoubleClickStrategy(
52         ISourceViewer sourceViewer,
53         String JavaDoc contentType) {
54         if (doubleClickStrategy == null)
55             doubleClickStrategy = new XMLDoubleClickStrategy();
56         return doubleClickStrategy;
57     }
58     protected XMLScanner getPDEScanner() {
59         if (pdeScanner == null) {
60             pdeScanner = new XMLScanner(colorManager);
61             pdeScanner.setDefaultReturnToken(
62                 new Token(
63                     new TextAttribute(colorManager.getColor(IPDEColorConstants.P_DEFAULT))));
64         }
65         return pdeScanner;
66     }
67     protected XMLTagScanner getPDETagScanner() {
68         if (tagScanner == null) {
69             tagScanner = new XMLTagScanner(colorManager);
70             tagScanner.setDefaultReturnToken(
71                 new Token(new TextAttribute(colorManager.getColor(IPDEColorConstants.P_TAG))));
72         }
73         return tagScanner;
74     }
75     public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
76         PresentationReconciler reconciler = new PresentationReconciler();
77
78         DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getPDEScanner());
79         reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
80         reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
81
82         dr = new DefaultDamagerRepairer(getPDETagScanner());
83         reconciler.setDamager(dr, XMLPartitionScanner.XML_TAG);
84         reconciler.setRepairer(dr, XMLPartitionScanner.XML_TAG);
85
86         NonRuleBasedDamagerRepairer ndr =
87             new NonRuleBasedDamagerRepairer(
88                 new TextAttribute(colorManager.getColor(IPDEColorConstants.P_XML_COMMENT)));
89         reconciler.setDamager(ndr, XMLPartitionScanner.XML_COMMENT);
90         reconciler.setRepairer(ndr, XMLPartitionScanner.XML_COMMENT);
91
92         return reconciler;
93     }
94     
95     public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
96         return new AnnotationHover();
97     }
98     
99     public IColorManager getColorManager(){
100         return colorManager;
101     
102     }
103 }
104
Popular Tags