1 package net.sourceforge.phpdt.sql.editors;
3 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
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;
16 public class SQLEditor extends TextEditor {
17 SQLConfiguration config;
18 private ColorManager colorManager;
20 * An editor capable of editing SQL scripts
24 colorManager = new ColorManager();
25 config = new SQLConfiguration(colorManager);
28 setPreferenceStore(PHPEclipseSQLPlugin.getDefault().getPreferenceStore());
29 IPropertyChangeListener preferenceListener = new IPropertyChangeListener() {
30 public void propertyChange(PropertyChangeEvent event) {
32 config.initializeColors();
33 getSourceViewer().invalidateTextPresentation();
34 StyledText widget = getSourceViewer().getTextWidget();
35 FontData font = PreferenceConverter.getFontData(getPreferenceStore(), "quantum.font");
36 widget.setFont(new Font(Display.getCurrent(), font));
37 Color background = colorManager.getColor(SQLColorConstants.BACKGROUND);
38 widget.setBackground(background);
42 addPropertyChangeListener(preferenceListener);
44 setSourceViewerConfiguration(config);
45 setDocumentProvider(new SQLDocumentProvider());
47 public void dispose() {
48 colorManager.dispose();
51 public void createPartControl(Composite arg0) {
52 super.createPartControl(arg0);
53 StyledText widget = getSourceViewer().getTextWidget();
54 FontData font = PreferenceConverter.getFontData(getPreferenceStore(), "quantum.font");
55 widget.setFont(new Font(Display.getCurrent(), font));
56 Color background = colorManager.getColor(SQLColorConstants.BACKGROUND);
57 widget.setBackground(background);