]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.document.ui/src/org/simantics/document/ui/CSSSourceViewerConfiguration.java
Externalize strings in org.simantics.document.ui
[simantics/platform.git] / bundles / org.simantics.document.ui / src / org / simantics / document / ui / CSSSourceViewerConfiguration.java
index 32627049b07334ec62b4b6f37fc4ac8b00d5f00e..44f0694f56a1849ce59a86b536e6d5c59fe95576 100644 (file)
-package org.simantics.document.ui;\r
-\r
-import org.eclipse.jface.preference.IPreferenceStore;\r
-import org.eclipse.jface.text.DefaultInformationControl;\r
-import org.eclipse.jface.text.IDocument;\r
-import org.eclipse.jface.text.IInformationControl;\r
-import org.eclipse.jface.text.IInformationControlCreator;\r
-import org.eclipse.jface.text.ITextHover;\r
-import org.eclipse.jface.text.TextAttribute;\r
-import org.eclipse.jface.text.contentassist.ContentAssistant;\r
-import org.eclipse.jface.text.contentassist.IContentAssistant;\r
-import org.eclipse.jface.text.presentation.IPresentationReconciler;\r
-import org.eclipse.jface.text.presentation.PresentationReconciler;\r
-import org.eclipse.jface.text.rules.DefaultDamagerRepairer;\r
-import org.eclipse.jface.text.rules.EndOfLineRule;\r
-import org.eclipse.jface.text.rules.IRule;\r
-import org.eclipse.jface.text.rules.ITokenScanner;\r
-import org.eclipse.jface.text.rules.IWordDetector;\r
-import org.eclipse.jface.text.rules.MultiLineRule;\r
-import org.eclipse.jface.text.rules.PatternRule;\r
-import org.eclipse.jface.text.rules.RuleBasedScanner;\r
-import org.eclipse.jface.text.rules.Token;\r
-import org.eclipse.jface.text.rules.WordRule;\r
-import org.eclipse.jface.text.source.DefaultAnnotationHover;\r
-import org.eclipse.jface.text.source.IAnnotationHover;\r
-import org.eclipse.jface.text.source.ISharedTextColors;\r
-import org.eclipse.jface.text.source.ISourceViewer;\r
-import org.eclipse.jface.text.source.SourceViewerConfiguration;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.graphics.Device;\r
-import org.eclipse.swt.graphics.Font;\r
-import org.eclipse.swt.graphics.RGB;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.ui.editors.text.EditorsUI;\r
-import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;\r
-\r
-public class CSSSourceViewerConfiguration extends SourceViewerConfiguration {\r
-\r
-    public static final char[] CONTENT_ASSIST_AUTO_CHARS = new char[] { '.' };\r
-    Device device;\r
-    \r
-    ISharedTextColors sharedTextColors;\r
-    IPreferenceStore preferenceStore;\r
-    \r
-    private CSSTextEditorEnvironment editorEnvironment;\r
-    \r
-    public CSSSourceViewerConfiguration(Device device,\r
-            ISharedTextColors sharedTextColors) {\r
-        this.device = device;\r
-        this.sharedTextColors = sharedTextColors;\r
-        this.preferenceStore = EditorsUI.getPreferenceStore();\r
-        \r
-        this.editorEnvironment = new CSSTextEditorEnvironment();\r
-    }\r
-\r
-    public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {\r
-        return new String[] {\r
-            IDocument.DEFAULT_CONTENT_TYPE\r
-        };\r
-    }\r
-    \r
-       @Override\r
-    public int getTabWidth(ISourceViewer sourceViewer) {\r
-               if (preferenceStore == null)\r
-                       return super.getTabWidth(sourceViewer);\r
-               return preferenceStore.getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH);\r
-       }\r
-\r
-       @Override\r
-       public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {\r
-               String[] indentPrefixes = getIndentPrefixesForTab(getTabWidth(sourceViewer));\r
-               if (indentPrefixes == null)\r
-                       return null;\r
-\r
-               int length = indentPrefixes.length;\r
-               if (length > 2) {\r
-                       // Swap first with second last\r
-                       String first = indentPrefixes[0];\r
-                       indentPrefixes[0] = indentPrefixes[length - 2];\r
-                       indentPrefixes[length - 2] = first;\r
-               }\r
-\r
-               return indentPrefixes;\r
-       }\r
-    \r
-    public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {\r
-        PresentationReconciler reconciler = new PresentationReconciler();\r
-        \r
-        DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getSclTokenScanner());\r
-        \r
-        reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);\r
-        reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);\r
-        \r
-        return reconciler;\r
-    }\r
-    \r
-    ITokenScanner getSclTokenScanner() {\r
-        RuleBasedScanner scanner = new RuleBasedScanner();\r
-        \r
-        Font font = new Font(device, "Courier New", 10, SWT.NORMAL);\r
-        Font boldFont = new Font(device, "Courier New", 10, SWT.BOLD);\r
-\r
-        Token defaultToken = new Token(\r
-                new TextAttribute(\r
-                        sharedTextColors.getColor(new RGB(0, 0, 0)),\r
-                        null,\r
-                        0,\r
-                        font\r
-                ));\r
-        Token string = new Token(new TextAttribute(\r
-                sharedTextColors.getColor(new RGB(42, 0, 255)),\r
-                null,\r
-                0,\r
-                font\r
-                ));\r
-        Token reserved = new Token(\r
-                new TextAttribute(\r
-                        sharedTextColors.getColor(new RGB(127, 0, 85)),\r
-                        null,\r
-                        SWT.BOLD,\r
-                        boldFont\r
-                ));\r
-        Token comment = new Token(new TextAttribute(\r
-                sharedTextColors.getColor(new RGB(63, 127, 95)),\r
-                null,\r
-                0,\r
-                font\r
-                ));\r
-\r
-        WordRule reservedWord = new WordRule(new IWordDetector() {          \r
-            @Override\r
-            public boolean isWordStart(char c) {\r
-                return Character.isJavaIdentifierStart(c);\r
-            }\r
-            \r
-            @Override\r
-            public boolean isWordPart(char c) {\r
-                return Character.isJavaIdentifierPart(c) || c=='.';\r
-            }\r
-        });\r
-\r
-        reservedWord.addWord("if", reserved);\r
-        reservedWord.addWord("then", reserved);\r
-        reservedWord.addWord("else", reserved);\r
-        reservedWord.addWord("match", reserved);\r
-        reservedWord.addWord("with", reserved);\r
-        reservedWord.addWord("data", reserved);\r
-        reservedWord.addWord("type", reserved);\r
-        reservedWord.addWord("class", reserved);\r
-        \r
-        IRule[] rules = new IRule[] {\r
-            //new MultiLineRule("\"\"\"", "\"\"\"", string),\r
-            new PatternRule("\"", "\"", string, '\\', true),\r
-            new MultiLineRule("/*", "*/", comment),\r
-            new EndOfLineRule("//", comment),\r
-            reservedWord\r
-        };\r
-        scanner.setRules(rules);\r
-        scanner.setDefaultReturnToken(defaultToken);\r
-        \r
-        return scanner;\r
-    }\r
-    \r
-    @Override\r
-    public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {\r
-        return new CSSEditorTextHover(sourceViewer, editorEnvironment);\r
-    }\r
-    \r
-    @Override\r
-    public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {\r
-        return new DefaultAnnotationHover();\r
-    }\r
-    \r
-    @Override\r
-    public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {\r
-        ContentAssistant assistant = new ContentAssistant();\r
-        assistant.enableColoredLabels(true);\r
-        assistant.setStatusLineVisible(true);\r
-\r
-        assistant.enableAutoActivation(true);\r
-        assistant.enableAutoInsert(true);\r
-        assistant.setContentAssistProcessor(new CSSCompletionAssistProcessor(editorEnvironment), IDocument.DEFAULT_CONTENT_TYPE);\r
-        assistant.setInformationControlCreator(CREATOR);\r
-        assistant.setRestoreCompletionProposalSize(Activator.getDefault().getDialogSettings()); \r
-        return assistant;\r
-    }\r
-    \r
-    private static final IInformationControlCreator CREATOR = new IInformationControlCreator() {\r
-        \r
-        @Override\r
-        public IInformationControl createInformationControl(Shell parent) {\r
-            return new DefaultInformationControl(parent);\r
-        }\r
-    };\r
-\r
-//    @Override\r
-//    public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {\r
-//        return new ContentFormatter();\r
-//    }\r
-}\r
+package org.simantics.document.ui;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.DefaultInformationControl;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IInformationControl;
+import org.eclipse.jface.text.IInformationControlCreator;
+import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.presentation.IPresentationReconciler;
+import org.eclipse.jface.text.presentation.PresentationReconciler;
+import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
+import org.eclipse.jface.text.rules.EndOfLineRule;
+import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.ITokenScanner;
+import org.eclipse.jface.text.rules.IWordDetector;
+import org.eclipse.jface.text.rules.MultiLineRule;
+import org.eclipse.jface.text.rules.PatternRule;
+import org.eclipse.jface.text.rules.RuleBasedScanner;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.text.rules.WordRule;
+import org.eclipse.jface.text.source.DefaultAnnotationHover;
+import org.eclipse.jface.text.source.IAnnotationHover;
+import org.eclipse.jface.text.source.ISharedTextColors;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Device;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
+
+public class CSSSourceViewerConfiguration extends SourceViewerConfiguration {
+
+    public static final char[] CONTENT_ASSIST_AUTO_CHARS = new char[] { '.' };
+    Device device;
+    
+    ISharedTextColors sharedTextColors;
+    IPreferenceStore preferenceStore;
+    
+    private CSSTextEditorEnvironment editorEnvironment;
+    
+    public CSSSourceViewerConfiguration(Device device,
+            ISharedTextColors sharedTextColors) {
+        this.device = device;
+        this.sharedTextColors = sharedTextColors;
+        this.preferenceStore = EditorsUI.getPreferenceStore();
+        
+        this.editorEnvironment = new CSSTextEditorEnvironment();
+    }
+
+    public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
+        return new String[] {
+            IDocument.DEFAULT_CONTENT_TYPE
+        };
+    }
+    
+       @Override
+    public int getTabWidth(ISourceViewer sourceViewer) {
+               if (preferenceStore == null)
+                       return super.getTabWidth(sourceViewer);
+               return preferenceStore.getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH);
+       }
+
+       @Override
+       public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
+               String[] indentPrefixes = getIndentPrefixesForTab(getTabWidth(sourceViewer));
+               if (indentPrefixes == null)
+                       return null;
+
+               int length = indentPrefixes.length;
+               if (length > 2) {
+                       // Swap first with second last
+                       String first = indentPrefixes[0];
+                       indentPrefixes[0] = indentPrefixes[length - 2];
+                       indentPrefixes[length - 2] = first;
+               }
+
+               return indentPrefixes;
+       }
+    
+    public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
+        PresentationReconciler reconciler = new PresentationReconciler();
+        
+        DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getSclTokenScanner());
+        
+        reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
+        reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
+        
+        return reconciler;
+    }
+    
+    ITokenScanner getSclTokenScanner() {
+        RuleBasedScanner scanner = new RuleBasedScanner();
+        
+        Font font = new Font(device, "Courier New", 10, SWT.NORMAL); //$NON-NLS-1$
+        Font boldFont = new Font(device, "Courier New", 10, SWT.BOLD); //$NON-NLS-1$
+
+        Token defaultToken = new Token(
+                new TextAttribute(
+                        sharedTextColors.getColor(new RGB(0, 0, 0)),
+                        null,
+                        0,
+                        font
+                ));
+        Token string = new Token(new TextAttribute(
+                sharedTextColors.getColor(new RGB(42, 0, 255)),
+                null,
+                0,
+                font
+                ));
+        Token reserved = new Token(
+                new TextAttribute(
+                        sharedTextColors.getColor(new RGB(127, 0, 85)),
+                        null,
+                        SWT.BOLD,
+                        boldFont
+                ));
+        Token comment = new Token(new TextAttribute(
+                sharedTextColors.getColor(new RGB(63, 127, 95)),
+                null,
+                0,
+                font
+                ));
+
+        WordRule reservedWord = new WordRule(new IWordDetector() {          
+            @Override
+            public boolean isWordStart(char c) {
+                return Character.isJavaIdentifierStart(c);
+            }
+            
+            @Override
+            public boolean isWordPart(char c) {
+                return Character.isJavaIdentifierPart(c) || c=='.';
+            }
+        });
+
+        reservedWord.addWord("if", reserved); //$NON-NLS-1$
+        reservedWord.addWord("then", reserved); //$NON-NLS-1$
+        reservedWord.addWord("else", reserved); //$NON-NLS-1$
+        reservedWord.addWord("match", reserved); //$NON-NLS-1$
+        reservedWord.addWord("with", reserved); //$NON-NLS-1$
+        reservedWord.addWord("data", reserved); //$NON-NLS-1$
+        reservedWord.addWord("type", reserved); //$NON-NLS-1$
+        reservedWord.addWord("class", reserved); //$NON-NLS-1$
+        
+        IRule[] rules = new IRule[] {
+            //new MultiLineRule("\"\"\"", "\"\"\"", string),
+            new PatternRule("\"", "\"", string, '\\', true), //$NON-NLS-1$ //$NON-NLS-2$
+            new MultiLineRule("/*", "*/", comment), //$NON-NLS-1$ //$NON-NLS-2$
+            new EndOfLineRule("//", comment), //$NON-NLS-1$
+            reservedWord
+        };
+        scanner.setRules(rules);
+        scanner.setDefaultReturnToken(defaultToken);
+        
+        return scanner;
+    }
+    
+    @Override
+    public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
+        return new CSSEditorTextHover(sourceViewer, editorEnvironment);
+    }
+    
+    @Override
+    public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
+        return new DefaultAnnotationHover();
+    }
+    
+    @Override
+    public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
+        ContentAssistant assistant = new ContentAssistant();
+        assistant.enableColoredLabels(true);
+        assistant.setStatusLineVisible(true);
+
+        assistant.enableAutoActivation(true);
+        assistant.enableAutoInsert(true);
+        assistant.setContentAssistProcessor(new CSSCompletionAssistProcessor(editorEnvironment), IDocument.DEFAULT_CONTENT_TYPE);
+        assistant.setInformationControlCreator(CREATOR);
+        assistant.setRestoreCompletionProposalSize(Activator.getDefault().getDialogSettings()); 
+        return assistant;
+    }
+    
+    private static final IInformationControlCreator CREATOR = new IInformationControlCreator() {
+        
+        @Override
+        public IInformationControl createInformationControl(Shell parent) {
+            return new DefaultInformationControl(parent);
+        }
+    };
+
+//    @Override
+//    public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
+//        return new ContentFormatter();
+//    }
+}