0
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
package com.symbian.smt.gui.editors.xmleditor;
|
|
19 |
|
|
20 |
import org.eclipse.jface.text.IDocument;
|
|
21 |
import org.eclipse.jface.text.ITextDoubleClickStrategy;
|
|
22 |
import org.eclipse.jface.text.TextAttribute;
|
|
23 |
import org.eclipse.jface.text.presentation.IPresentationReconciler;
|
|
24 |
import org.eclipse.jface.text.presentation.PresentationReconciler;
|
|
25 |
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
|
|
26 |
import org.eclipse.jface.text.rules.Token;
|
|
27 |
import org.eclipse.jface.text.source.ISourceViewer;
|
|
28 |
import org.eclipse.jface.text.source.SourceViewerConfiguration;
|
|
29 |
|
|
30 |
/**
|
|
31 |
* @author barbararosi-schwartz
|
|
32 |
*
|
|
33 |
*/
|
|
34 |
public class XMLConfiguration extends SourceViewerConfiguration {
|
|
35 |
private XMLDoubleClickStrategy doubleClickStrategy;
|
|
36 |
private XMLTagScanner tagScanner;
|
|
37 |
private XMLScanner scanner;
|
|
38 |
private ColorManager colorManager;
|
|
39 |
|
|
40 |
public XMLConfiguration(ColorManager colorManager) {
|
|
41 |
this.colorManager = colorManager;
|
|
42 |
}
|
|
43 |
|
|
44 |
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
|
|
45 |
return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
|
|
46 |
XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_TAG };
|
|
47 |
}
|
|
48 |
|
|
49 |
public ITextDoubleClickStrategy getDoubleClickStrategy(
|
|
50 |
ISourceViewer sourceViewer, String contentType) {
|
|
51 |
if (doubleClickStrategy == null)
|
|
52 |
doubleClickStrategy = new XMLDoubleClickStrategy();
|
|
53 |
return doubleClickStrategy;
|
|
54 |
}
|
|
55 |
|
|
56 |
public IPresentationReconciler getPresentationReconciler(
|
|
57 |
ISourceViewer sourceViewer) {
|
|
58 |
PresentationReconciler reconciler = new PresentationReconciler();
|
|
59 |
|
|
60 |
DefaultDamagerRepairer dr = new DefaultDamagerRepairer(
|
|
61 |
getXMLTagScanner());
|
|
62 |
reconciler.setDamager(dr, XMLPartitionScanner.XML_TAG);
|
|
63 |
reconciler.setRepairer(dr, XMLPartitionScanner.XML_TAG);
|
|
64 |
|
|
65 |
dr = new DefaultDamagerRepairer(getXMLScanner());
|
|
66 |
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
|
|
67 |
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
|
|
68 |
|
|
69 |
NonRuleBasedDamagerRepairer ndr = new NonRuleBasedDamagerRepairer(
|
|
70 |
new TextAttribute(colorManager
|
|
71 |
.getColor(IXMLColorConstants.XML_COMMENT)));
|
|
72 |
reconciler.setDamager(ndr, XMLPartitionScanner.XML_COMMENT);
|
|
73 |
reconciler.setRepairer(ndr, XMLPartitionScanner.XML_COMMENT);
|
|
74 |
|
|
75 |
return reconciler;
|
|
76 |
}
|
|
77 |
|
|
78 |
protected XMLScanner getXMLScanner() {
|
|
79 |
if (scanner == null) {
|
|
80 |
scanner = new XMLScanner(colorManager);
|
|
81 |
scanner.setDefaultReturnToken(new Token(new TextAttribute(
|
|
82 |
colorManager.getColor(IXMLColorConstants.DEFAULT))));
|
|
83 |
}
|
|
84 |
return scanner;
|
|
85 |
}
|
|
86 |
|
|
87 |
protected XMLTagScanner getXMLTagScanner() {
|
|
88 |
if (tagScanner == null) {
|
|
89 |
tagScanner = new XMLTagScanner(colorManager);
|
|
90 |
tagScanner.setDefaultReturnToken(new Token(new TextAttribute(
|
|
91 |
colorManager.getColor(IXMLColorConstants.TAG))));
|
|
92 |
}
|
|
93 |
return tagScanner;
|
|
94 |
}
|
|
95 |
|
|
96 |
} |