1 package org.simantics.sysdyn.ui.equation.expressions;
\r
3 import org.eclipse.jface.text.DefaultTextHover;
\r
4 import org.eclipse.jface.text.IDocument;
\r
5 import org.eclipse.jface.text.ITextHover;
\r
6 import org.eclipse.jface.text.TextAttribute;
\r
7 import org.eclipse.jface.text.presentation.IPresentationReconciler;
\r
8 import org.eclipse.jface.text.presentation.PresentationReconciler;
\r
9 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
\r
10 import org.eclipse.jface.text.rules.IRule;
\r
11 import org.eclipse.jface.text.rules.ITokenScanner;
\r
12 import org.eclipse.jface.text.rules.IWordDetector;
\r
13 import org.eclipse.jface.text.rules.PatternRule;
\r
14 import org.eclipse.jface.text.rules.RuleBasedScanner;
\r
15 import org.eclipse.jface.text.rules.Token;
\r
16 import org.eclipse.jface.text.rules.WordRule;
\r
17 import org.eclipse.jface.text.source.DefaultAnnotationHover;
\r
18 import org.eclipse.jface.text.source.IAnnotationHover;
\r
19 import org.eclipse.jface.text.source.ISourceViewer;
\r
20 import org.eclipse.jface.text.source.SourceViewerConfiguration;
\r
21 import org.eclipse.swt.SWT;
\r
22 import org.eclipse.swt.graphics.RGB;
\r
24 public class ExpressionFieldConfiguration extends SourceViewerConfiguration {
\r
27 ColorManager colorManager;
\r
29 public ExpressionFieldConfiguration(ColorManager colorManager) {
\r
31 this.colorManager = colorManager;
\r
34 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
\r
35 return new String[] {
\r
36 IDocument.DEFAULT_CONTENT_TYPE
\r
42 public IAutoEditStrategy[] getAutoEditStrategies(
\r
43 ISourceViewer sourceViewer, String contentType) {
\r
44 return new IAutoEditStrategy[] {
\r
45 new ReplaceTabsBySpaces(),
\r
46 new IndentLineEditStrategy(),
\r
47 new MatchingBracketsEditStrategy()
\r
52 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
\r
53 PresentationReconciler reconciler = new PresentationReconciler();
\r
55 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getSclTokenScanner());
\r
57 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
\r
58 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
\r
66 ITokenScanner getSclTokenScanner() {
\r
67 RuleBasedScanner scanner = new RuleBasedScanner();
\r
69 final Token string = new Token(new TextAttribute(colorManager.getColor(new RGB(42, 0, 255))));
\r
70 final Token reserved = new Token(
\r
72 colorManager.getColor(new RGB(127, 0, 85)),
\r
76 final Token comment = new Token(new TextAttribute(colorManager.getColor(new RGB(63, 127, 95))));
\r
78 WordRule reservedWord = new WordRule(new IWordDetector() {
\r
80 public boolean isWordStart(char c) {
\r
85 public boolean isWordPart(char c) {
\r
86 return Character.isJavaIdentifierPart(c);
\r
90 reservedWord.addWord("@a", reserved);
\r
91 reservedWord.addWord("@keywords", reserved);
\r
92 reservedWord.addWord("@forAll", reserved);
\r
93 reservedWord.addWord("@forSome", reserved);
\r
94 reservedWord.addWord("@true", reserved);
\r
95 reservedWord.addWord("@false", reserved);
\r
96 reservedWord.addWord("@base", reserved);
\r
97 reservedWord.addWord("@prefix", reserved);
\r
99 IRule[] rules = new IRule[] {
\r
100 //new MultiLineRule("\"\"\"", "\"\"\"", string),
\r
101 new PatternRule("\"", "\"", string, '\\', true),
\r
102 new PatternRule("\"\"\"", "\"\"\"", string, '\\', false),
\r
103 new PatternRule("<", ">", string, '\\', false),
\r
104 new PatternRule("#", null, comment, '\0', true),
\r
107 scanner.setRules(rules);
\r
113 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
\r
114 return new DefaultTextHover(sourceViewer);
\r
118 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
\r
119 return new DefaultAnnotationHover();
\r