Added Pref option to configure for which extensions the internal parser should be...
[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 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
16
17 public class SQLEditor extends TextEditor {
18         private SQLSourceViewerConfiguration config;
19         private ColorManager colorManager;
20         private SQLContentOutlinePage outlinePage;
21         /**
22          * An editor capable of editing SQL scripts
23          */
24         public SQLEditor() {
25                 super();
26 //System.out.println("SQL Editor");
27                 colorManager = new ColorManager();
28                 config = new SQLSourceViewerConfiguration(colorManager);
29                 config.loadPrefs();
30                 
31                 setPreferenceStore(QuantumPlugin.getDefault().getPreferenceStore());
32                 IPropertyChangeListener preferenceListener = new IPropertyChangeListener() {
33                         public void propertyChange(PropertyChangeEvent event) {
34                                 config.loadPrefs();
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);
42                         }
43                 };
44                 getPreferenceStore().
45                         addPropertyChangeListener(preferenceListener);
46
47                 setSourceViewerConfiguration(config);
48                 setDocumentProvider(new SQLDocumentProvider());
49         }
50         public void dispose() {
51                 colorManager.dispose();
52                 super.dispose();
53         }
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);
61         }
62         
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());
70                         }
71                         return this.outlinePage;
72                 }
73                 return super.getAdapter(required);
74         }
75
76 }