1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.properties.widgets.expressions;
\r
14 import org.eclipse.jface.text.DefaultTextHover;
\r
15 import org.eclipse.jface.text.IDocument;
\r
16 import org.eclipse.jface.text.ITextHover;
\r
17 import org.eclipse.jface.text.TextAttribute;
\r
18 import org.eclipse.jface.text.presentation.IPresentationReconciler;
\r
19 import org.eclipse.jface.text.presentation.PresentationReconciler;
\r
20 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
\r
21 import org.eclipse.jface.text.rules.IRule;
\r
22 import org.eclipse.jface.text.rules.ITokenScanner;
\r
23 import org.eclipse.jface.text.rules.IWordDetector;
\r
24 import org.eclipse.jface.text.rules.MultiLineRule;
\r
25 import org.eclipse.jface.text.rules.RuleBasedScanner;
\r
26 import org.eclipse.jface.text.rules.Token;
\r
27 import org.eclipse.jface.text.rules.WordRule;
\r
28 import org.eclipse.jface.text.source.DefaultAnnotationHover;
\r
29 import org.eclipse.jface.text.source.IAnnotationHover;
\r
30 import org.eclipse.jface.text.source.ISourceViewer;
\r
31 import org.eclipse.jface.text.source.SourceViewerConfiguration;
\r
32 import org.eclipse.swt.SWT;
\r
33 import org.eclipse.swt.graphics.RGB;
\r
34 import org.simantics.sysdyn.ui.properties.VariableNameValidator;
\r
36 public class ExpressionFieldConfiguration extends SourceViewerConfiguration {
\r
39 ColorManager colorManager;
\r
41 public ExpressionFieldConfiguration(ColorManager colorManager) {
\r
43 this.colorManager = colorManager;
\r
46 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
\r
47 return new String[] {
\r
48 IDocument.DEFAULT_CONTENT_TYPE
\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
64 ITokenScanner getSclTokenScanner() {
\r
65 RuleBasedScanner scanner = new RuleBasedScanner();
\r
67 final Token reserved = new Token(
\r
69 colorManager.getColor(new RGB(127, 0, 85)),
\r
73 final Token defaultToken = new Token(new TextAttribute(colorManager.getColor(new RGB(0, 0, 0))));
\r
75 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
81 return Character.isLetter(c);
\r
85 public boolean isWordPart(char c) {
\r
86 return Character.isLetter(c);
\r
91 for(String s : VariableNameValidator.keywords) {
\r
92 reservedWord.addWord(s, reserved);
\r
95 IRule[] rules = new IRule[] {
\r
97 new MultiLineRule("/*", "*/", comment)
\r
99 scanner.setRules(rules);
\r
105 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
\r
106 return new DefaultTextHover(sourceViewer);
\r
110 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
\r
111 return new DefaultAnnotationHover();
\r