1 package com.quantum.editors;
3 import com.quantum.QuantumPlugin;
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 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
17 public class SQLEditor extends TextEditor {
18 private SQLSourceViewerConfiguration config;
19 private ColorManager colorManager;
20 private SQLContentOutlinePage outlinePage;
22 * An editor capable of editing SQL scripts
26 //System.out.println("SQL Editor");
27 colorManager = new ColorManager();
28 config = new SQLSourceViewerConfiguration(colorManager);
31 setPreferenceStore(QuantumPlugin.getDefault().getPreferenceStore());
32 IPropertyChangeListener preferenceListener = new IPropertyChangeListener() {
33 public void propertyChange(PropertyChangeEvent event) {
35 config.initializeColors();
36 getSourceViewer().invalidateTextPresentation();
37 StyledText widget = getSourceViewer().getTextWidget();
38 FontData font = PreferenceConverter.getFontData(getPreferenceStore(), "quantum.font"); //$NON-NLS-1$
39 widget.setFont(new Font(Display.getCurrent(), font));
40 Color background = colorManager.getColor(SQLColorConstants.BACKGROUND);
41 widget.setBackground(background);
45 addPropertyChangeListener(preferenceListener);
47 setSourceViewerConfiguration(config);
48 setDocumentProvider(new SQLDocumentProvider());
50 public void dispose() {
51 colorManager.dispose();
54 public void createPartControl(Composite arg0) {
55 super.createPartControl(arg0);
56 StyledText widget = getSourceViewer().getTextWidget();
57 FontData font = PreferenceConverter.getFontData(getPreferenceStore(), "quantum.font"); //$NON-NLS-1$
58 widget.setFont(new Font(Display.getCurrent(), font));
59 Color background = colorManager.getColor(SQLColorConstants.BACKGROUND);
60 widget.setBackground(background);
63 public Object getAdapter(Class required) {
64 if (IContentOutlinePage.class.equals(required)) {
65 if (this.outlinePage == null) {
66 this.outlinePage= new SQLContentOutlinePage(
67 (SQLDocumentProvider) getDocumentProvider(), this);
68 if (getEditorInput() != null)
69 this.outlinePage.setInput(getEditorInput());
71 return this.outlinePage;
73 return super.getAdapter(required);