don't split one line PHP statements in CodeFormatter
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / editors / SQLConfiguration.java
1 package com.quantum.editors;
2
3 import java.util.HashMap;
4
5 import com.quantum.QuantumPlugin;
6
7 import org.eclipse.jface.preference.IPreferenceStore;
8 import org.eclipse.jface.preference.PreferenceConverter;
9 import org.eclipse.jface.text.IDocument;
10 import org.eclipse.jface.text.TextAttribute;
11 import org.eclipse.jface.text.contentassist.ContentAssistant;
12 import org.eclipse.jface.text.contentassist.IContentAssistant;
13 import org.eclipse.jface.text.presentation.IPresentationReconciler;
14 import org.eclipse.jface.text.presentation.PresentationReconciler;
15 import org.eclipse.jface.text.source.ISourceViewer;
16 import org.eclipse.jface.text.source.SourceViewerConfiguration;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.graphics.Color;
19 import org.eclipse.swt.graphics.RGB;
20
21 public class SQLConfiguration extends SourceViewerConfiguration {
22         private PresentationReconciler reconciler = new PresentationReconciler();
23         private ColorManager colorManager;
24         private HashMap cache = new HashMap();
25         private boolean textBold = false;
26         private boolean keywordBold = true;
27         private boolean stringBold = false;
28         private boolean commentBold = false;
29         private boolean numericBold = false;
30         public SQLConfiguration(ColorManager colorManager) {
31                 this.colorManager = colorManager;
32         }
33         public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
34                 return new String[] {
35                         IDocument.DEFAULT_CONTENT_TYPE,
36                         SQLPartitionScanner.SQL_COMMENT,
37                         SQLPartitionScanner.SQL_KEYWORD,
38                         SQLPartitionScanner.SQL_IDENTIFIER};
39         }
40
41         public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
42                 initializeColors();
43                 return reconciler;
44         }
45         public void loadPrefs() {
46                 IPreferenceStore store = QuantumPlugin.getDefault().getPreferenceStore();
47                 textBold = store.getBoolean("quantum.text.bold"); //$NON-NLS-1$
48                 keywordBold = store.getBoolean("quantum.keyword.bold"); //$NON-NLS-1$
49                 stringBold = store.getBoolean("quantum.string.bold"); //$NON-NLS-1$
50                 commentBold = store.getBoolean("quantum.comment.bold"); //$NON-NLS-1$
51                 numericBold = store.getBoolean("quantum.numeric.bold"); //$NON-NLS-1$
52                 SQLColorConstants.BACKGROUND = PreferenceConverter.getColor(store, "quantum.background.color"); //$NON-NLS-1$
53                 SQLColorConstants.DEFAULT = PreferenceConverter.getColor(store, "quantum.text.color"); //$NON-NLS-1$
54                 SQLColorConstants.IDENTIFIER = PreferenceConverter.getColor(store, "quantum.text.color"); //$NON-NLS-1$
55                 SQLColorConstants.KEYWORD = PreferenceConverter.getColor(store, "quantum.keyword.color"); //$NON-NLS-1$
56                 SQLColorConstants.STRING = PreferenceConverter.getColor(store, "quantum.string.color"); //$NON-NLS-1$
57                 SQLColorConstants.COMMENT = PreferenceConverter.getColor(store, "quantum.comment.color"); //$NON-NLS-1$
58                 SQLColorConstants.NUMERIC = PreferenceConverter.getColor(store, "quantum.numeric.color"); //$NON-NLS-1$
59         }
60         public void initializeColors() {
61                 setDamageRepairer(getAttr(SQLColorConstants.KEYWORD, keywordBold), SQLPartitionScanner.SQL_KEYWORD);
62                 setDamageRepairer(getAttr(SQLColorConstants.COMMENT, commentBold), SQLPartitionScanner.SQL_COMMENT);
63                 setDamageRepairer(getAttr(SQLColorConstants.STRING, stringBold), SQLPartitionScanner.SQL_STRING);
64                 setDamageRepairer(getAttr(SQLColorConstants.DEFAULT, textBold), IDocument.DEFAULT_CONTENT_TYPE);
65                 setDamageRepairer(getAttr(SQLColorConstants.DEFAULT, textBold), SQLPartitionScanner.SQL_SYMBOL);
66                 setDamageRepairer(getAttr(SQLColorConstants.DEFAULT, textBold), SQLPartitionScanner.SQL_IDENTIFIER);
67                 setDamageRepairer(getAttr(SQLColorConstants.DEFAULT, textBold), SQLPartitionScanner.SQL_SEPARATOR);
68                 setDamageRepairer(getAttr(SQLColorConstants.NUMERIC, numericBold), SQLPartitionScanner.SQL_NUMERIC);
69         }
70         public TextAttribute getAttr(RGB color, boolean bold) {
71                 colorManager.getColor(SQLColorConstants.BACKGROUND);
72                 Color foreground = colorManager.getColor(color);
73                 TextAttribute attr = new TextAttribute(foreground);
74                 if (bold) {
75                         return new TextAttribute(foreground, attr.getBackground(), SWT.BOLD);
76                 }
77                 return attr;
78         }
79         public void setDamageRepairer(TextAttribute attr, String token) {
80                 NonRuleBasedDamagerRepairer ndr = (NonRuleBasedDamagerRepairer) cache.get(token);
81                 if (ndr == null) {
82                         ndr =
83                                 new NonRuleBasedDamagerRepairer(attr);
84                         reconciler.setDamager(ndr, token);
85                         reconciler.setRepairer(ndr, token);
86                         cache.put(token, ndr);
87                 } else {
88                         ndr.setTextAttribute(attr);
89                 }
90         }
91 //      public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
92 //              ContentAssistant assistant = new ContentAssistant();
93 //              assistant.setContentAssistProcessor(new SQLContentAssistProcessor("default"), 
94 //                              IDocument.DEFAULT_CONTENT_TYPE);
95 //              assistant.setContentAssistProcessor(new SQLContentAssistProcessor("comment"), 
96 //                              SQLPartitionScanner.SQL_COMMENT);
97 //              assistant.setContentAssistProcessor(new SQLContentAssistProcessor("keyword"), 
98 //                              SQLPartitionScanner.SQL_KEYWORD);
99 //              assistant.setContentAssistProcessor(new SQLContentAssistProcessor("identifier"), 
100 //                              SQLPartitionScanner.SQL_IDENTIFIER);
101 //              
102 //              // everybody else is doin' it...
103 //              assistant.enableAutoActivation(true);
104 //              assistant.setAutoActivationDelay(500);
105 //              
106 //              assistant.setProposalPopupOrientation(ContentAssistant.CONTEXT_INFO_BELOW);
107 //              assistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_BELOW);
108 //              return assistant;
109 //      }
110 }