show HTML files as local resources (no 'http://' url prefix)
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / editors / SQLEditor.java
1 package com.quantum.editors;
2
3 import com.quantum.QuantumPlugin;
4
5 import org.eclipse.jface.preference.PreferenceConverter;
6 import org.eclipse.jface.util.IPropertyChangeListener;
7 import org.eclipse.jface.util.PropertyChangeEvent;
8 import org.eclipse.swt.custom.StyledText;
9 import org.eclipse.swt.graphics.Color;
10 import org.eclipse.swt.graphics.Font;
11 import org.eclipse.swt.graphics.FontData;
12 import org.eclipse.swt.widgets.Composite;
13 import org.eclipse.swt.widgets.Display;
14 import org.eclipse.ui.editors.text.TextEditor;
15
16 public class SQLEditor extends TextEditor {
17         SQLConfiguration config;
18         private ColorManager colorManager;
19         /**
20          * An editor capable of editing SQL scripts
21          */
22         public SQLEditor() {
23                 super();
24                 colorManager = new ColorManager();
25                 config = new SQLConfiguration(colorManager);
26                 config.loadPrefs();
27                 
28                 setPreferenceStore(QuantumPlugin.getDefault().getPreferenceStore());
29                 IPropertyChangeListener preferenceListener = new IPropertyChangeListener() {
30                         public void propertyChange(PropertyChangeEvent event) {
31                                 config.loadPrefs();
32                                 config.initializeColors();
33                                 getSourceViewer().invalidateTextPresentation();
34                                 StyledText widget = getSourceViewer().getTextWidget();
35                                 FontData font = PreferenceConverter.getFontData(getPreferenceStore(), "quantum.font"); //$NON-NLS-1$
36                                 widget.setFont(new Font(Display.getCurrent(), font));
37                                 Color background = colorManager.getColor(SQLColorConstants.BACKGROUND);
38                                 widget.setBackground(background);
39                         }
40                 };
41                 getPreferenceStore().
42                         addPropertyChangeListener(preferenceListener);
43
44                 setSourceViewerConfiguration(config);
45                 setDocumentProvider(new SQLDocumentProvider());
46         }
47         public void dispose() {
48                 colorManager.dispose();
49                 super.dispose();
50         }
51         public void createPartControl(Composite arg0) {
52                 super.createPartControl(arg0);
53                 StyledText widget = getSourceViewer().getTextWidget();
54                 FontData font = PreferenceConverter.getFontData(getPreferenceStore(), "quantum.font"); //$NON-NLS-1$
55                 widget.setFont(new Font(Display.getCurrent(), font));
56                 Color background = colorManager.getColor(SQLColorConstants.BACKGROUND);
57                 widget.setBackground(background);
58         }
59 }