intial source from ttp://www.sf.net/projects/wdte
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.css.ui / src / net / sourceforge / phpeclipse / css / ui / internal / preferences / CssEditorPreferencePage.java
1 /*
2  * Copyright (c) 2003-2004 Christopher Lenz and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     Christopher Lenz - initial API and implementation
10  * 
11  * $Id: CssEditorPreferencePage.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $
12  */
13
14 package net.sourceforge.phpeclipse.css.ui.internal.preferences;
15
16 import java.util.Iterator;
17
18 import net.sourceforge.phpeclipse.css.ui.CssUI;
19 import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages;
20 import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences;
21
22 import org.eclipse.jface.preference.PreferencePage;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Control;
26 import org.eclipse.swt.widgets.TabFolder;
27 import org.eclipse.swt.widgets.TabItem;
28 import org.eclipse.ui.IWorkbench;
29 import org.eclipse.ui.IWorkbenchPreferencePage;
30 import org.eclipse.ui.texteditor.AnnotationPreference;
31 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
32
33 /**
34  * Implements the CSS editor preference page.
35  */
36 public class CssEditorPreferencePage extends PreferencePage
37         implements IWorkbenchPreferencePage {
38
39         // Instance Variables ------------------------------------------------------
40
41         private OverlayPreferenceStore overlayStore;
42
43         private CssEditorAppearanceConfigurationBlock appearanceBlock;
44         private CssEditorSyntaxConfigurationBlock syntaxBlock;
45         private CssEditorContentAssistConfigurationBlock contentAssistBlock;
46         private CssEditorAnnotationsConfigurationBlock annotationsBlock;
47         private CssEditorTypingConfigurationBlock typingBlock;
48
49         // PreferencePage Implementation -------------------------------------------
50
51         /**
52          * @see PreferencePage#createContents(Composite)
53          */
54         protected Control createContents(Composite parent) {
55
56                 TabFolder folder = new TabFolder(parent, SWT.NONE);
57                 TabItem item;
58
59                 item = new TabItem(folder, SWT.NONE);
60                 item.setText(getString("appearance")); //$NON-NLS-1$
61                 item.setControl(createAppearancePage(folder));
62
63                 item = new TabItem(folder, SWT.NONE);
64                 item.setText(getString("syntax")); //$NON-NLS-1$
65                 item.setControl(createSyntaxPage(folder));
66
67                 item = new TabItem(folder, SWT.NONE);
68                 item.setText(getString("contentAssist")); //$NON-NLS-1$
69                 item.setControl(createCodeAssistPage(folder));
70
71                 item = new TabItem(folder, SWT.NONE);
72                 item.setText(getString("annotations")); //$NON-NLS-1$
73                 item.setControl(createAnnotationsPage(folder));
74
75                 item = new TabItem(folder, SWT.NONE);
76                 item.setText(getString("typing")); //$NON-NLS-1$
77                 item.setControl(createTypingPage(folder));
78
79                 return folder;
80         }
81
82         /**
83          * @see PreferencePage#dispose()
84          */
85         public void dispose() {
86                 if (overlayStore != null) {
87                         overlayStore.stopListening();
88                         overlayStore = null;
89                 }
90                 super.dispose();
91         }
92
93         /**
94          * @see PreferencePage#performOk()
95          */
96         public boolean performOk() {
97                 overlayStore.propagate();
98                 CssUI.getDefault().savePluginPreferences();
99                 return true;
100         }
101
102         /**
103          * @see PreferencePage#performDefaults()
104          */
105         protected void performDefaults() {
106                 overlayStore.loadDefaults();
107                 super.performDefaults();
108         }
109         
110         // IWorkbenchPreferencePage Implementation ---------------------------------
111
112         /**
113          * @see IWorkbenchPreferencePage#init(IWorkbench)
114          */
115         public void init(IWorkbench workbench) {
116                 setDescription(getString("description")); //$NON-NLS-1$
117                 setPreferenceStore(CssUI.getDefault().getPreferenceStore());
118
119                 MarkerAnnotationPreferences preferences =
120                         new MarkerAnnotationPreferences();
121                 overlayStore = createOverlayStore(preferences);
122                 overlayStore.load();
123                 overlayStore.startListening();
124         }
125
126         // Private Methods ---------------------------------------------------------
127
128         private OverlayPreferenceStore createOverlayStore(
129                 MarkerAnnotationPreferences preferences) {
130
131                 OverlayPreferenceStore store = 
132                         new OverlayPreferenceStore(getPreferenceStore());
133
134                 Iterator e = preferences.getAnnotationPreferences().iterator();
135                 while (e.hasNext()) {
136                         AnnotationPreference info = (AnnotationPreference) e.next();
137                         store.addStringKey(info.getColorPreferenceKey());
138                         store.addBooleanKey(info.getTextPreferenceKey());
139                         store.addBooleanKey(info.getOverviewRulerPreferenceKey());
140                 }
141
142                 // Appearance
143                 store.addIntKey(CssUIPreferences.EDITOR_TAB_WIDTH);
144                 store.addBooleanKey(CssUIPreferences.EDITOR_CURRENT_LINE);
145                 store.addStringKey(CssUIPreferences.EDITOR_CURRENT_LINE_COLOR);
146                 store.addBooleanKey(CssUIPreferences.EDITOR_MATCHING_BRACKETS);
147                 store.addStringKey(CssUIPreferences.EDITOR_MATCHING_BRACKETS_COLOR);
148                 store.addBooleanKey(CssUIPreferences.EDITOR_PRINT_MARGIN);
149                 store.addStringKey(CssUIPreferences.EDITOR_PRINT_MARGIN_COLOR);
150                 store.addIntKey(CssUIPreferences.EDITOR_PRINT_MARGIN_COLUMN);
151                 store.addBooleanKey(CssUIPreferences.EDITOR_OVERVIEW_RULER);
152                 store.addStringKey(CssUIPreferences.EDITOR_LINE_NUMBER_RULER_COLOR);
153                 store.addBooleanKey(CssUIPreferences.EDITOR_LINE_NUMBER_RULER);
154
155                 // Syntax coloring
156                 store.addStringKey(CssUIPreferences.EDITOR_FOREGROUND_COLOR);
157                 store.addBooleanKey(
158                         CssUIPreferences.EDITOR_FOREGROUND_DEFAULT_COLOR);
159                 store.addStringKey(CssUIPreferences.EDITOR_BACKGROUND_COLOR);
160                 store.addBooleanKey(
161                         CssUIPreferences.EDITOR_BACKGROUND_DEFAULT_COLOR);
162                 store.addStringKey(CssUIPreferences.EDITOR_COMMENT_COLOR);
163                 store.addBooleanKey(CssUIPreferences.EDITOR_COMMENT_BOLD);
164                 store.addStringKey(CssUIPreferences.EDITOR_STRING_COLOR);
165                 store.addBooleanKey(CssUIPreferences.EDITOR_STRING_BOLD);
166                 store.addStringKey(CssUIPreferences.EDITOR_PROPERTY_COLOR);
167                 store.addBooleanKey(CssUIPreferences.EDITOR_PROPERTY_BOLD);
168                 store.addStringKey(CssUIPreferences.EDITOR_AT_KEYWORD_COLOR);
169                 store.addBooleanKey(CssUIPreferences.EDITOR_AT_KEYWORD_BOLD);
170                 store.addStringKey(CssUIPreferences.EDITOR_PSEUDO_CLASS_COLOR);
171                 store.addBooleanKey(CssUIPreferences.EDITOR_PSEUDO_CLASS_BOLD);
172                 store.addStringKey(CssUIPreferences.EDITOR_DEFAULT_COLOR);
173                 store.addBooleanKey(CssUIPreferences.EDITOR_DEFAULT_BOLD);
174
175                 // Content assist
176                 store.addBooleanKey(CssUIPreferences.CONTENTASSIST_AUTOINSERT);
177                 store.addBooleanKey(CssUIPreferences.CONTENTASSIST_ORDER_PROPOSALS);
178                 store.addBooleanKey(CssUIPreferences.CONTENTASSIST_AUTOACTIVATION);
179                 store.addIntKey(
180                         CssUIPreferences.CONTENTASSIST_AUTOACTIVATION_DELAY);
181                 store.addStringKey(
182                         CssUIPreferences.CONTENTASSIST_AUTOACTIVATION_TRIGGERS);
183                 store.addStringKey(
184                         CssUIPreferences.CONTENTASSIST_PROPOSALS_BACKGROUND);
185                 store.addStringKey(
186                         CssUIPreferences.CONTENTASSIST_PROPOSALS_FOREGROUND);
187
188                 // Typing
189                 store.addBooleanKey(CssUIPreferences.EDITOR_SPACES_FOR_TABS);
190                 store.addBooleanKey(CssUIPreferences.EDITOR_CLOSE_STRINGS);
191                 store.addBooleanKey(
192                         CssUIPreferences.EDITOR_CLOSE_BRACKETS_AND_PARENS);
193                 store.addBooleanKey(CssUIPreferences.EDITOR_CLOSE_BRACES);
194
195                 return store;
196         }
197         
198         private Control createAppearancePage(Composite parent) {
199                 appearanceBlock =
200                         new CssEditorAppearanceConfigurationBlock(overlayStore); 
201                 return appearanceBlock.createControl(parent);
202         }
203
204         private Control createSyntaxPage(Composite parent) {
205                 syntaxBlock = new CssEditorSyntaxConfigurationBlock(overlayStore); 
206                 return syntaxBlock.createControl(parent);
207         }
208
209         private Control createCodeAssistPage(Composite parent) {
210                 contentAssistBlock =
211                         new CssEditorContentAssistConfigurationBlock(overlayStore);
212                 return contentAssistBlock.createControl(parent);
213         }
214
215         private Control createAnnotationsPage(Composite parent) {
216                 annotationsBlock =
217                         new CssEditorAnnotationsConfigurationBlock(overlayStore); 
218                 return annotationsBlock.createControl(parent);
219         }
220
221         private Control createTypingPage(Composite parent) {
222                 typingBlock = new CssEditorTypingConfigurationBlock(overlayStore); 
223                 return typingBlock.createControl(parent);
224         }
225
226         private static String getString(String key) {
227                 return CssUIMessages.getString(
228                         "CssEditorPreferencePage." + key); //$NON-NLS-1$
229         }
230
231 }