KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > eclipse > console > editors > HQLConfiguration


1 package org.hibernate.eclipse.console.editors;
2
3 import org.eclipse.jface.text.IDocument;
4 import org.eclipse.jface.text.ITextDoubleClickStrategy;
5 import org.eclipse.jface.text.TextAttribute;
6 import org.eclipse.jface.text.presentation.IPresentationReconciler;
7 import org.eclipse.jface.text.presentation.PresentationReconciler;
8 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
9 import org.eclipse.jface.text.rules.Token;
10 import org.eclipse.jface.text.source.ISourceViewer;
11 import org.eclipse.jface.text.source.SourceViewerConfiguration;
12
13 public class HQLConfiguration extends SourceViewerConfiguration {
14     
15     private HQLTagScanner tagScanner;
16     private HQLScanner scanner;
17     private ColorManager colorManager;
18
19     public HQLConfiguration(ColorManager colorManager) {
20         this.colorManager = colorManager;
21     }
22     public String JavaDoc[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
23         return new String JavaDoc[] {
24             IDocument.DEFAULT_CONTENT_TYPE,
25             HQLPartitionScanner.HQL_COMMENT,
26             HQLPartitionScanner.HQL_TAG };
27     }
28     
29
30     protected HQLScanner getHQLScanner() {
31         if (scanner == null) {
32             scanner = new HQLScanner(colorManager);
33             scanner.setDefaultReturnToken(
34                 new Token(
35                     new TextAttribute(
36                         colorManager.getColor(IHQLColorConstants.DEFAULT))));
37         }
38         return scanner;
39     }
40     protected HQLTagScanner getXMLTagScanner() {
41         if (tagScanner == null) {
42             tagScanner = new HQLTagScanner(colorManager);
43             tagScanner.setDefaultReturnToken(
44                 new Token(
45                     new TextAttribute(
46                         colorManager.getColor(IHQLColorConstants.TAG))));
47         }
48         return tagScanner;
49     }
50
51     public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
52         PresentationReconciler reconciler = new PresentationReconciler();
53
54         DefaultDamagerRepairer dr =
55             new DefaultDamagerRepairer(getXMLTagScanner());
56         reconciler.setDamager(dr, HQLPartitionScanner.HQL_TAG);
57         reconciler.setRepairer(dr, HQLPartitionScanner.HQL_TAG);
58
59         dr = new DefaultDamagerRepairer(getHQLScanner());
60         reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
61         reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
62
63         NonRuleBasedDamagerRepairer ndr =
64             new NonRuleBasedDamagerRepairer(
65                 new TextAttribute(
66                     colorManager.getColor(IHQLColorConstants.XML_COMMENT)));
67         reconciler.setDamager(ndr, HQLPartitionScanner.HQL_COMMENT);
68         reconciler.setRepairer(ndr, HQLPartitionScanner.HQL_COMMENT);
69
70         return reconciler;
71     }
72
73 }
Popular Tags