c088d4e229a1e6958d995290a469d232f48ad758
[phpeclipse.git] /
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation 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  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.preferences;
12
13 import java.io.BufferedReader;
14 import java.io.IOException;
15 import java.io.InputStreamReader;
16 import java.text.Collator;
17 import java.util.ArrayList;
18 import java.util.Comparator;
19 import java.util.HashMap;
20 import java.util.Iterator;
21 import java.util.Map;
22 import java.util.SortedSet;
23 import java.util.StringTokenizer;
24 import java.util.TreeSet;
25
26 import net.sourceforge.phpdt.core.JavaCore;
27 import net.sourceforge.phpdt.internal.ui.IJavaHelpContextIds;
28 import net.sourceforge.phpdt.internal.ui.dialogs.StatusInfo;
29 import net.sourceforge.phpdt.internal.ui.dialogs.StatusUtil;
30 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
31 import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter;
32 import net.sourceforge.phpdt.internal.ui.util.TabFolderLayout;
33 import net.sourceforge.phpdt.ui.PreferenceConstants;
34 import net.sourceforge.phpdt.ui.text.JavaTextTools;
35 import net.sourceforge.phpdt.ui.text.PHPSourceViewerConfiguration;
36 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
37 import net.sourceforge.phpeclipse.phpeditor.EditorUtility;
38 import net.sourceforge.phpeclipse.phpeditor.JavaSourceViewer;
39 import net.sourceforge.phpeclipse.preferences.ColorEditor;
40
41 import org.eclipse.core.runtime.IStatus;
42 import org.eclipse.core.runtime.Preferences;
43 import org.eclipse.jface.action.Action;
44 import org.eclipse.jface.dialogs.Dialog;
45 import org.eclipse.jface.preference.IPreferenceStore;
46 import org.eclipse.jface.preference.PreferenceConverter;
47 import org.eclipse.jface.preference.PreferencePage;
48 import org.eclipse.jface.resource.JFaceResources;
49 import org.eclipse.jface.text.Document;
50 import org.eclipse.jface.text.IDocument;
51 import org.eclipse.jface.text.source.SourceViewer;
52 import org.eclipse.swt.SWT;
53 import org.eclipse.swt.events.KeyEvent;
54 import org.eclipse.swt.events.KeyListener;
55 import org.eclipse.swt.events.ModifyEvent;
56 import org.eclipse.swt.events.ModifyListener;
57 import org.eclipse.swt.events.SelectionEvent;
58 import org.eclipse.swt.events.SelectionListener;
59 import org.eclipse.swt.graphics.Color;
60 import org.eclipse.swt.graphics.Font;
61 import org.eclipse.swt.graphics.Point;
62 import org.eclipse.swt.graphics.RGB;
63 import org.eclipse.swt.layout.GridData;
64 import org.eclipse.swt.layout.GridLayout;
65 import org.eclipse.swt.layout.RowLayout;
66 import org.eclipse.swt.widgets.Button;
67 import org.eclipse.swt.widgets.Combo;
68 import org.eclipse.swt.widgets.Composite;
69 import org.eclipse.swt.widgets.Control;
70 import org.eclipse.swt.widgets.Group;
71 import org.eclipse.swt.widgets.Label;
72 import org.eclipse.swt.widgets.List;
73 import org.eclipse.swt.widgets.TabFolder;
74 import org.eclipse.swt.widgets.TabItem;
75 import org.eclipse.swt.widgets.Text;
76 import org.eclipse.ui.IWorkbench;
77 import org.eclipse.ui.IWorkbenchPreferencePage;
78 import org.eclipse.ui.PlatformUI;
79 import org.eclipse.ui.editors.text.EditorsUI;
80 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
81 import org.eclipse.ui.texteditor.AnnotationPreference;
82 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
83 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
84
85 /**
86  * The page for setting the editor options.
87  */
88 public class JavaEditorPreferencePage extends PreferencePage implements
89                 IWorkbenchPreferencePage {
90         private static final String BOLD = PreferenceConstants.EDITOR_BOLD_SUFFIX;
91
92         private static final String COMPILER_TASK_TAGS = JavaCore.COMPILER_TASK_TAGS;
93
94         private static final String DELIMITER = PreferencesMessages
95                         .getString("JavaEditorPreferencePage.navigation.delimiter"); //$NON-NLS-1$
96
97         /** The keys of the overlay store. */
98         public final OverlayPreferenceStore.OverlayKey[] fKeys;
99
100         private final String[][] fSyntaxColorListModel = new String[][] {
101                         {
102                                         PreferencesMessages
103                                                         .getString("JavaEditorPreferencePage.multiLineComment"),
104                                         PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_COLOR },
105                         //$NON-NLS-1$
106                         {
107                                         PreferencesMessages
108                                                         .getString("JavaEditorPreferencePage.singleLineComment"),
109                                         PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR },
110                         //$NON-NLS-1$
111                         { PreferencesMessages.getString("JavaEditorPreferencePage.tags"),
112                                         PreferenceConstants.EDITOR_PHP_TAG_COLOR },
113                         //$NON-NLS-1$
114                         {
115                                         PreferencesMessages
116                                                         .getString("JavaEditorPreferencePage.keywords"),
117                                         PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR },
118                         {
119                                         PreferencesMessages
120                                                         .getString("JavaEditorPreferencePage.functionNames"),
121                                         PreferenceConstants.EDITOR_PHP_FUNCTIONNAME_COLOR },
122                         //$NON-NLS-1$
123                         {
124                                         PreferencesMessages
125                                                         .getString("JavaEditorPreferencePage.variables"),
126                                         PreferenceConstants.EDITOR_PHP_VARIABLE_COLOR },
127                         //$NON-NLS-1$
128                         {
129                                         PreferencesMessages
130                                                         .getString("JavaEditorPreferencePage.variables_dollar"),
131                                         PreferenceConstants.EDITOR_PHP_VARIABLE_DOLLAR_COLOR },
132                         //$NON-NLS-1$
133                         {
134                                         PreferencesMessages
135                                                         .getString("JavaEditorPreferencePage.constants"),
136                                         PreferenceConstants.EDITOR_PHP_CONSTANT_COLOR },
137                         //$NON-NLS-1$
138                         { PreferencesMessages.getString("JavaEditorPreferencePage.types"),
139                                         PreferenceConstants.EDITOR_PHP_TYPE_COLOR },
140                         //$NON-NLS-1$
141                         {
142                                         PreferencesMessages
143                                                         .getString("JavaEditorPreferencePage.strings_dq"),
144                                         PreferenceConstants.EDITOR_STRING_COLOR_DQ },
145                         {
146                                         PreferencesMessages
147                                                         .getString("JavaEditorPreferencePage.strings_sq"),
148                                         PreferenceConstants.EDITOR_STRING_COLOR_SQ },
149                         //$NON-NLS-1$
150                         {
151                                         PreferencesMessages
152                                                         .getString("JavaEditorPreferencePage.others"), PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR }, //$NON-NLS-1$
153                         {
154                                         PreferencesMessages
155                                                         .getString("JavaEditorPreferencePage.operators"),
156                                         PreferenceConstants.EDITOR_PHP_OPERATOR_COLOR },
157                         //$NON-NLS-1$
158                         {
159                                         PreferencesMessages
160                                                         .getString("JavaEditorPreferencePage.returnKeyword"),
161                                         PreferenceConstants.EDITOR_PHP_KEYWORD_RETURN_COLOR },
162                         { PreferencesMessages.getString("JavaEditorPreferencePage.braces"),
163                                         PreferenceConstants.EDITOR_PHP_BRACE_OPERATOR_COLOR },
164                         //$NON-NLS-1$
165                         {
166                                         PreferencesMessages
167                                                         .getString("JavaEditorPreferencePage.phpDocKeywords"),
168                                         PreferenceConstants.EDITOR_JAVADOC_KEYWORD_COLOR },
169                         //$NON-NLS-1$
170                         {
171                                         PreferencesMessages
172                                                         .getString("JavaEditorPreferencePage.phpDocHtmlTags"),
173                                         PreferenceConstants.EDITOR_JAVADOC_TAG_COLOR },
174                         //$NON-NLS-1$
175                         {
176                                         PreferencesMessages
177                                                         .getString("JavaEditorPreferencePage.phpDocLinks"),
178                                         PreferenceConstants.EDITOR_JAVADOC_LINKS_COLOR },
179                         //$NON-NLS-1$
180                         {
181                                         PreferencesMessages
182                                                         .getString("JavaEditorPreferencePage.phpDocOthers"), PreferenceConstants.EDITOR_JAVADOC_DEFAULT_COLOR } //$NON-NLS-1$
183         };
184
185         private final String[][] fAppearanceColorListModel = new String[][] {
186                         {
187                                         PreferencesMessages
188                                                         .getString("JavaEditorPreferencePage.lineNumberForegroundColor"),
189                                         AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR },
190                         //$NON-NLS-1$
191                         {
192                                         PreferencesMessages
193                                                         .getString("JavaEditorPreferencePage.matchingBracketsHighlightColor2"),
194                                         PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR },
195                         //$NON-NLS-1$
196                         {
197                                         PreferencesMessages
198                                                         .getString("JavaEditorPreferencePage.currentLineHighlighColor"),
199                                         AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR },
200                         //$NON-NLS-1$
201                         {
202                                         PreferencesMessages
203                                                         .getString("JavaEditorPreferencePage.printMarginColor2"),
204                                         AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR },
205                         //$NON-NLS-1$
206                         {
207                                         PreferencesMessages
208                                                         .getString("JavaEditorPreferencePage.findScopeColor2"),
209                                         PreferenceConstants.EDITOR_FIND_SCOPE_COLOR },
210                         //$NON-NLS-1$
211                         {
212                                         PreferencesMessages
213                                                         .getString("JavaEditorPreferencePage.linkColor2"), PreferenceConstants.EDITOR_LINK_COLOR }, //$NON-NLS-1$
214         };
215
216         // private final String[][] fAnnotationColorListModel;
217
218         // private final String[][] fAnnotationDecorationListModel = new String[][]{
219         // {
220         // PreferencesMessages
221         // .getString("JavaEditorPreferencePage.AnnotationDecoration.NONE"),
222         // AnnotationPreference.STYLE_NONE},
223         // //$NON-NLS-1$
224         // {
225         // PreferencesMessages
226         // .getString("JavaEditorPreferencePage.AnnotationDecoration.SQUIGGLIES"),
227         // AnnotationPreference.STYLE_SQUIGGLIES},
228         // //$NON-NLS-1$
229         // {
230         // PreferencesMessages
231         // .getString("JavaEditorPreferencePage.AnnotationDecoration.UNDERLINE"),
232         // AnnotationPreference.STYLE_UNDERLINE},
233         // //$NON-NLS-1$
234         // {
235         // PreferencesMessages
236         // .getString("JavaEditorPreferencePage.AnnotationDecoration.BOX"),
237         // AnnotationPreference.STYLE_BOX},
238         // //$NON-NLS-1$
239         // {
240         // PreferencesMessages
241         // .getString("JavaEditorPreferencePage.AnnotationDecoration.IBEAM"),
242         // AnnotationPreference.STYLE_IBEAM} //$NON-NLS-1$
243         // };
244         private OverlayPreferenceStore fOverlayStore;
245
246         private JavaTextTools fJavaTextTools;
247
248         private JavaEditorHoverConfigurationBlock fJavaEditorHoverConfigurationBlock;
249
250         private FoldingConfigurationBlock fFoldingConfigurationBlock;
251
252         private Map fColorButtons = new HashMap();
253
254         private Map fCheckBoxes = new HashMap();
255
256         private SelectionListener fCheckBoxListener = new SelectionListener() {
257                 public void widgetDefaultSelected(SelectionEvent e) {
258                 }
259
260                 public void widgetSelected(SelectionEvent e) {
261                         Button button = (Button) e.widget;
262                         fOverlayStore.setValue((String) fCheckBoxes.get(button), button
263                                         .getSelection());
264                 }
265         };
266
267         private Map fTextFields = new HashMap();
268
269         private ModifyListener fTextFieldListener = new ModifyListener() {
270                 public void modifyText(ModifyEvent e) {
271                         Text text = (Text) e.widget;
272                         fOverlayStore.setValue((String) fTextFields.get(text), text
273                                         .getText());
274                 }
275         };
276
277         private ArrayList fNumberFields = new ArrayList();
278
279         private ModifyListener fNumberFieldListener = new ModifyListener() {
280                 public void modifyText(ModifyEvent e) {
281                         numberFieldChanged((Text) e.widget);
282                 }
283         };
284
285         private List fSyntaxColorList;
286
287         private List fAppearanceColorList;
288
289         // private List fContentAssistColorList;
290         private List fAnnotationList;
291
292         private ColorEditor fSyntaxForegroundColorEditor;
293
294         private ColorEditor fAppearanceColorEditor;
295
296         private ColorEditor fAnnotationForegroundColorEditor;
297
298         private ColorEditor fContentAssistColorEditor;
299
300         private ColorEditor fBackgroundColorEditor;
301
302         private Button fBackgroundDefaultRadioButton;
303
304         private Button fBackgroundCustomRadioButton;
305
306         private Button fBackgroundColorButton;
307
308         private Button fBoldCheckBox;
309
310         // private Button fAddJavaDocTagsButton;
311
312         private Button fEscapeStringsButtonDQ;
313
314         private Button fEscapeStringsButtonSQ;
315
316         // private Button fGuessMethodArgumentsButton;
317         private SourceViewer fPreviewViewer;
318
319         private Color fBackgroundColor;
320
321         private Control fAutoInsertDelayText;
322
323         private Control fAutoInsertJavaTriggerText;
324
325         private Control fAutoInsertJavaDocTriggerText;
326
327         private Label fAutoInsertDelayLabel;
328
329         private Label fAutoInsertJavaTriggerLabel;
330
331         private Label fAutoInsertJavaDocTriggerLabel;
332
333         private Button fShowInTextCheckBox;
334
335         private Combo fDecorationStyleCombo;
336
337         private Button fHighlightInTextCheckBox;
338
339         private Button fShowInOverviewRulerCheckBox;
340
341         private Button fShowInVerticalRulerCheckBox;
342
343         private Text fBrowserLikeLinksKeyModifierText;
344
345         private Button fBrowserLikeLinksCheckBox;
346
347         private StatusInfo fBrowserLikeLinksKeyModifierStatus;
348
349         // private Button fCompletionInsertsRadioButton;
350         // private Button fCompletionOverwritesRadioButton;
351         // private Button fStickyOccurrencesButton;
352         /**
353          * Creates a new preference page.
354          */
355         public JavaEditorPreferencePage() {
356                 setDescription(PreferencesMessages
357                                 .getString("JavaEditorPreferencePage.description")); //$NON-NLS-1$
358                 setPreferenceStore(PHPeclipsePlugin.getDefault().getPreferenceStore());
359                 MarkerAnnotationPreferences markerAnnotationPreferences = new MarkerAnnotationPreferences();
360                 fKeys = createOverlayStoreKeys(markerAnnotationPreferences);
361                 fOverlayStore = new OverlayPreferenceStore(getPreferenceStore(), fKeys);
362                 // fAnnotationColorListModel =
363                 // createAnnotationTypeListModel(markerAnnotationPreferences);
364         }
365
366         private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys(
367                         MarkerAnnotationPreferences preferences) {
368                 ArrayList overlayKeys = new ArrayList();
369                 Iterator e = preferences.getAnnotationPreferences().iterator();
370                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
371                                 OverlayPreferenceStore.STRING,
372                                 PreferenceConstants.EDITOR_FOREGROUND_COLOR));
373                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
374                                 OverlayPreferenceStore.BOOLEAN,
375                                 PreferenceConstants.EDITOR_FOREGROUND_DEFAULT_COLOR));
376                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
377                                 OverlayPreferenceStore.STRING,
378                                 PreferenceConstants.EDITOR_BACKGROUND_COLOR));
379                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
380                                 OverlayPreferenceStore.BOOLEAN,
381                                 PreferenceConstants.EDITOR_BACKGROUND_DEFAULT_COLOR));
382                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
383                                 OverlayPreferenceStore.INT,
384                                 PreferenceConstants.EDITOR_TAB_WIDTH));
385                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
386                                 OverlayPreferenceStore.STRING,
387                                 PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_COLOR));
388                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
389                                 OverlayPreferenceStore.BOOLEAN,
390                                 PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_BOLD));
391                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
392                                 OverlayPreferenceStore.STRING,
393                                 PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR));
394                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
395                                 OverlayPreferenceStore.BOOLEAN,
396                                 PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_BOLD));
397                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
398                                 OverlayPreferenceStore.STRING,
399                                 PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR));
400                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
401                                 OverlayPreferenceStore.BOOLEAN,
402                                 PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD));
403
404                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
405                                 OverlayPreferenceStore.STRING,
406                                 PreferenceConstants.EDITOR_PHP_TAG_COLOR));
407                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
408                                 OverlayPreferenceStore.BOOLEAN,
409                                 PreferenceConstants.EDITOR_PHP_TAG_BOLD));
410                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
411                                 OverlayPreferenceStore.STRING,
412                                 PreferenceConstants.EDITOR_PHP_FUNCTIONNAME_COLOR));
413                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
414                                 OverlayPreferenceStore.BOOLEAN,
415                                 PreferenceConstants.EDITOR_PHP_FUNCTIONNAME_BOLD));
416                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
417                                 OverlayPreferenceStore.STRING,
418                                 PreferenceConstants.EDITOR_PHP_VARIABLE_COLOR));
419                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
420                                 OverlayPreferenceStore.BOOLEAN,
421                                 PreferenceConstants.EDITOR_PHP_VARIABLE_BOLD));
422                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
423                                 OverlayPreferenceStore.STRING,
424                                 PreferenceConstants.EDITOR_PHP_VARIABLE_DOLLAR_COLOR));
425                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
426                                 OverlayPreferenceStore.BOOLEAN,
427                                 PreferenceConstants.EDITOR_PHP_VARIABLE_DOLLAR_BOLD));
428                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
429                                 OverlayPreferenceStore.STRING,
430                                 PreferenceConstants.EDITOR_PHP_CONSTANT_COLOR));
431                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
432                                 OverlayPreferenceStore.BOOLEAN,
433                                 PreferenceConstants.EDITOR_PHP_CONSTANT_BOLD));
434                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
435                                 OverlayPreferenceStore.STRING,
436                                 PreferenceConstants.EDITOR_PHP_TYPE_COLOR));
437                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
438                                 OverlayPreferenceStore.BOOLEAN,
439                                 PreferenceConstants.EDITOR_PHP_TYPE_BOLD));
440
441                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
442                                 OverlayPreferenceStore.STRING,
443                                 PreferenceConstants.EDITOR_STRING_COLOR_DQ));
444                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
445                                 OverlayPreferenceStore.BOOLEAN,
446                                 PreferenceConstants.EDITOR_STRING_BOLD_DQ));
447                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
448                                 OverlayPreferenceStore.STRING,
449                                 PreferenceConstants.EDITOR_STRING_COLOR_SQ));
450                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
451                                 OverlayPreferenceStore.BOOLEAN,
452                                 PreferenceConstants.EDITOR_STRING_BOLD_SQ));
453                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
454                                 OverlayPreferenceStore.STRING,
455                                 PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR));
456                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
457                                 OverlayPreferenceStore.BOOLEAN,
458                                 PreferenceConstants.EDITOR_JAVA_DEFAULT_BOLD));
459                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
460                                 OverlayPreferenceStore.STRING,
461                                 PreferenceConstants.EDITOR_TASK_TAG_COLOR));
462                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
463                                 OverlayPreferenceStore.BOOLEAN,
464                                 PreferenceConstants.EDITOR_TASK_TAG_BOLD));
465                 // overlayKeys.add(new
466                 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING_DQ,
467                 // PreferenceConstants.EDITOR_JAVA_METHOD_NAME_COLOR));
468                 // overlayKeys.add(new
469                 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
470                 // PreferenceConstants.EDITOR_JAVA_METHOD_NAME_BOLD));
471                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
472                                 OverlayPreferenceStore.STRING,
473                                 PreferenceConstants.EDITOR_PHP_OPERATOR_COLOR));
474                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
475                                 OverlayPreferenceStore.BOOLEAN,
476                                 PreferenceConstants.EDITOR_PHP_OPERATOR_BOLD));
477                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
478                                 OverlayPreferenceStore.STRING,
479                                 PreferenceConstants.EDITOR_PHP_KEYWORD_RETURN_COLOR));
480                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
481                                 OverlayPreferenceStore.BOOLEAN,
482                                 PreferenceConstants.EDITOR_PHP_KEYWORD_RETURN_BOLD));
483                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
484                                 OverlayPreferenceStore.STRING,
485                                 PreferenceConstants.EDITOR_PHP_BRACE_OPERATOR_COLOR));
486                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
487                                 OverlayPreferenceStore.BOOLEAN,
488                                 PreferenceConstants.EDITOR_PHP_BRACE_OPERATOR_BOLD));
489                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
490                                 OverlayPreferenceStore.STRING,
491                                 PreferenceConstants.EDITOR_JAVADOC_KEYWORD_COLOR));
492                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
493                                 OverlayPreferenceStore.BOOLEAN,
494                                 PreferenceConstants.EDITOR_JAVADOC_KEYWORD_BOLD));
495                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
496                                 OverlayPreferenceStore.STRING,
497                                 PreferenceConstants.EDITOR_JAVADOC_TAG_COLOR));
498                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
499                                 OverlayPreferenceStore.BOOLEAN,
500                                 PreferenceConstants.EDITOR_JAVADOC_TAG_BOLD));
501                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
502                                 OverlayPreferenceStore.STRING,
503                                 PreferenceConstants.EDITOR_JAVADOC_LINKS_COLOR));
504                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
505                                 OverlayPreferenceStore.BOOLEAN,
506                                 PreferenceConstants.EDITOR_JAVADOC_LINKS_BOLD));
507                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
508                                 OverlayPreferenceStore.STRING,
509                                 PreferenceConstants.EDITOR_JAVADOC_DEFAULT_COLOR));
510                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
511                                 OverlayPreferenceStore.BOOLEAN,
512                                 PreferenceConstants.EDITOR_JAVADOC_DEFAULT_BOLD));
513                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
514                                 OverlayPreferenceStore.STRING,
515                                 PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR));
516                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
517                                 OverlayPreferenceStore.BOOLEAN,
518                                 PreferenceConstants.EDITOR_MATCHING_BRACKETS));
519                 overlayKeys
520                                 .add(new OverlayPreferenceStore.OverlayKey(
521                                                 OverlayPreferenceStore.STRING,
522                                                 AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR));
523                 overlayKeys
524                                 .add(new OverlayPreferenceStore.OverlayKey(
525                                                 OverlayPreferenceStore.BOOLEAN,
526                                                 AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE));
527                 overlayKeys
528                                 .add(new OverlayPreferenceStore.OverlayKey(
529                                                 OverlayPreferenceStore.STRING,
530                                                 AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR));
531                 overlayKeys
532                                 .add(new OverlayPreferenceStore.OverlayKey(
533                                                 OverlayPreferenceStore.INT,
534                                                 AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN));
535                 overlayKeys
536                                 .add(new OverlayPreferenceStore.OverlayKey(
537                                                 OverlayPreferenceStore.BOOLEAN,
538                                                 AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN));
539                 // overlayKeys.add(new
540                 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
541                 // PreferenceConstants.EDITOR_MARK_OCCURRENCES));
542                 // overlayKeys.add(new
543                 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
544                 // PreferenceConstants.EDITOR_STICKY_OCCURRENCES));
545                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
546                                 OverlayPreferenceStore.STRING,
547                                 PreferenceConstants.EDITOR_FIND_SCOPE_COLOR));
548                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
549                                 OverlayPreferenceStore.STRING,
550                                 PreferenceConstants.EDITOR_LINK_COLOR));
551                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
552                                 OverlayPreferenceStore.BOOLEAN,
553                                 PreferenceConstants.EDITOR_CORRECTION_INDICATION));
554                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
555                                 OverlayPreferenceStore.BOOLEAN,
556                                 PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS));
557                 overlayKeys
558                                 .add(new OverlayPreferenceStore.OverlayKey(
559                                                 OverlayPreferenceStore.BOOLEAN,
560                                                 AbstractDecoratedTextEditorPreferenceConstants.EDITOR_OVERVIEW_RULER));
561                 overlayKeys
562                                 .add(new OverlayPreferenceStore.OverlayKey(
563                                                 OverlayPreferenceStore.STRING,
564                                                 AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR));
565                 overlayKeys
566                                 .add(new OverlayPreferenceStore.OverlayKey(
567                                                 OverlayPreferenceStore.BOOLEAN,
568                                                 AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER));
569                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
570                                 OverlayPreferenceStore.BOOLEAN,
571                                 PreferenceConstants.EDITOR_SPACES_FOR_TABS));
572                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
573                                 OverlayPreferenceStore.BOOLEAN,
574                                 PreferenceConstants.CODEASSIST_AUTOACTIVATION));
575                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
576                                 OverlayPreferenceStore.INT,
577                                 PreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY));
578                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
579                                 OverlayPreferenceStore.BOOLEAN,
580                                 PreferenceConstants.CODEASSIST_AUTOINSERT));
581                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
582                                 OverlayPreferenceStore.STRING,
583                                 PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND));
584                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
585                                 OverlayPreferenceStore.STRING,
586                                 PreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND));
587                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
588                                 OverlayPreferenceStore.STRING,
589                                 PreferenceConstants.CODEASSIST_PARAMETERS_BACKGROUND));
590                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
591                                 OverlayPreferenceStore.STRING,
592                                 PreferenceConstants.CODEASSIST_PARAMETERS_FOREGROUND));
593                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
594                                 OverlayPreferenceStore.STRING,
595                                 PreferenceConstants.CODEASSIST_REPLACEMENT_BACKGROUND));
596                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
597                                 OverlayPreferenceStore.STRING,
598                                 PreferenceConstants.CODEASSIST_REPLACEMENT_FOREGROUND));
599                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
600                                 OverlayPreferenceStore.STRING,
601                                 PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA));
602                 overlayKeys
603                                 .add(new OverlayPreferenceStore.OverlayKey(
604                                                 OverlayPreferenceStore.STRING,
605                                                 PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVADOC));
606                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
607                                 OverlayPreferenceStore.BOOLEAN,
608                                 PreferenceConstants.CODEASSIST_SHOW_VISIBLE_PROPOSALS));
609                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
610                                 OverlayPreferenceStore.BOOLEAN,
611                                 PreferenceConstants.CODEASSIST_ORDER_PROPOSALS));
612                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
613                                 OverlayPreferenceStore.BOOLEAN,
614                                 PreferenceConstants.CODEASSIST_CASE_SENSITIVITY));
615                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
616                                 OverlayPreferenceStore.BOOLEAN,
617                                 PreferenceConstants.CODEASSIST_ADDIMPORT));
618                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
619                                 OverlayPreferenceStore.BOOLEAN,
620                                 PreferenceConstants.CODEASSIST_INSERT_COMPLETION));
621                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
622                                 OverlayPreferenceStore.BOOLEAN,
623                                 PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES));
624                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
625                                 OverlayPreferenceStore.BOOLEAN,
626                                 PreferenceConstants.CODEASSIST_GUESS_METHOD_ARGUMENTS));
627                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
628                                 OverlayPreferenceStore.BOOLEAN,
629                                 PreferenceConstants.EDITOR_SMART_PASTE));
630                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
631                                 OverlayPreferenceStore.BOOLEAN,
632                                 PreferenceConstants.EDITOR_CLOSE_STRINGS_DQ_PHP));
633                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
634                                 OverlayPreferenceStore.BOOLEAN,
635                                 PreferenceConstants.EDITOR_CLOSE_STRINGS_SQ_PHP));
636                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
637                                 OverlayPreferenceStore.BOOLEAN,
638                                 PreferenceConstants.EDITOR_CLOSE_BRACKETS_PHP));
639                 // overlayKeys
640                 // .add(new OverlayPreferenceStore.OverlayKey(
641                 // OverlayPreferenceStore.BOOLEAN,
642                 // PreferenceConstants.EDITOR_CLOSE_BRACES));
643                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
644                                 OverlayPreferenceStore.BOOLEAN,
645                                 PreferenceConstants.EDITOR_CLOSE_JAVADOCS));
646                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
647                                 OverlayPreferenceStore.BOOLEAN,
648                                 PreferenceConstants.EDITOR_WRAP_WORDS));
649                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
650                                 OverlayPreferenceStore.BOOLEAN,
651                                 PreferenceConstants.EDITOR_WRAP_STRINGS_DQ));
652                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
653                                 OverlayPreferenceStore.BOOLEAN,
654                                 PreferenceConstants.EDITOR_ESCAPE_STRINGS_DQ));
655                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
656                                 OverlayPreferenceStore.BOOLEAN,
657                                 PreferenceConstants.EDITOR_WRAP_STRINGS_SQ));
658                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
659                                 OverlayPreferenceStore.BOOLEAN,
660                                 PreferenceConstants.EDITOR_ESCAPE_STRINGS_SQ));
661
662                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
663                                 OverlayPreferenceStore.BOOLEAN,
664                                 PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS));
665                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
666                                 OverlayPreferenceStore.BOOLEAN,
667                                 PreferenceConstants.EDITOR_FORMAT_JAVADOCS));
668                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
669                                 OverlayPreferenceStore.BOOLEAN,
670                                 PreferenceConstants.EDITOR_P_RTRIM_ON_SAVE));
671
672                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
673                                 OverlayPreferenceStore.BOOLEAN,
674                                 PreferenceConstants.EDITOR_SMART_HOME_END));
675                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
676                                 OverlayPreferenceStore.BOOLEAN,
677                                 PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION));
678                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
679                                 OverlayPreferenceStore.BOOLEAN,
680                                 PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE));
681                 // overlayKeys.add(new
682                 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
683                 // PreferenceConstants.EDITOR_SHOW_TEXT_HOVER_AFFORDANCE));
684                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
685                                 OverlayPreferenceStore.STRING,
686                                 PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS));
687                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
688                                 OverlayPreferenceStore.STRING,
689                                 PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIER_MASKS));
690                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
691                                 OverlayPreferenceStore.BOOLEAN,
692                                 PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS));
693                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
694                                 OverlayPreferenceStore.STRING,
695                                 PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER));
696                 overlayKeys
697                                 .add(new OverlayPreferenceStore.OverlayKey(
698                                                 OverlayPreferenceStore.STRING,
699                                                 PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK));
700                 while (e.hasNext()) {
701                         AnnotationPreference info = (AnnotationPreference) e.next();
702                         overlayKeys
703                                         .add(new OverlayPreferenceStore.OverlayKey(
704                                                         OverlayPreferenceStore.STRING, info
705                                                                         .getColorPreferenceKey()));
706                         overlayKeys
707                                         .add(new OverlayPreferenceStore.OverlayKey(
708                                                         OverlayPreferenceStore.BOOLEAN, info
709                                                                         .getTextPreferenceKey()));
710                         if (info.getHighlightPreferenceKey() != null)
711                                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
712                                                 OverlayPreferenceStore.BOOLEAN, info
713                                                                 .getHighlightPreferenceKey()));
714                         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
715                                         OverlayPreferenceStore.BOOLEAN, info
716                                                         .getOverviewRulerPreferenceKey()));
717                         if (info.getVerticalRulerPreferenceKey() != null)
718                                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
719                                                 OverlayPreferenceStore.BOOLEAN, info
720                                                                 .getVerticalRulerPreferenceKey()));
721                         if (info.getTextStylePreferenceKey() != null)
722                                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
723                                                 OverlayPreferenceStore.STRING, info
724                                                                 .getTextStylePreferenceKey()));
725                 }
726                 OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys
727                                 .size()];
728                 overlayKeys.toArray(keys);
729                 return keys;
730         } /*
731                  * @see IWorkbenchPreferencePage#init()
732                  */
733
734         public void init(IWorkbench workbench) {
735         }
736
737         /*
738          * @see PreferencePage#createControl(Composite)
739          */
740         public void createControl(Composite parent) {
741                 super.createControl(parent);
742                 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
743                                 IJavaHelpContextIds.JAVA_EDITOR_PREFERENCE_PAGE);
744         }
745
746         private void handleSyntaxColorListSelection() {
747                 int i = fSyntaxColorList.getSelectionIndex();
748                 String key = fSyntaxColorListModel[i][1];
749                 RGB rgb = PreferenceConverter.getColor(fOverlayStore, key);
750                 fSyntaxForegroundColorEditor.setColorValue(rgb);
751                 fBoldCheckBox.setSelection(fOverlayStore.getBoolean(key + BOLD));
752         }
753
754         private void handleAppearanceColorListSelection() {
755                 int i = fAppearanceColorList.getSelectionIndex();
756                 String key = fAppearanceColorListModel[i][1];
757                 RGB rgb = PreferenceConverter.getColor(fOverlayStore, key);
758                 fAppearanceColorEditor.setColorValue(rgb);
759         }
760
761         // private void handleAnnotationListSelection() {
762         // int i = fAnnotationList.getSelectionIndex();
763         // String key = fAnnotationColorListModel[i][1];
764         // RGB rgb = PreferenceConverter.getColor(fOverlayStore, key);
765         // fAnnotationForegroundColorEditor.setColorValue(rgb);
766         // key = fAnnotationColorListModel[i][2];
767         // boolean showInText = fOverlayStore.getBoolean(key);
768         // fShowInTextCheckBox.setSelection(showInText);
769         // key = fAnnotationColorListModel[i][6];
770         // if (key != null) {
771         // fDecorationStyleCombo.setEnabled(showInText);
772         // for (int j = 0; j < fAnnotationDecorationListModel.length; j++) {
773         // String value = fOverlayStore.getString(key);
774         // if (fAnnotationDecorationListModel[j][1].equals(value)) {
775         // fDecorationStyleCombo.setText(fAnnotationDecorationListModel[j][0]);
776         // break;
777         // }
778         // }
779         // } else {
780         // fDecorationStyleCombo.setEnabled(false);
781         // fDecorationStyleCombo.setText(fAnnotationDecorationListModel[1][0]); //
782         // set
783         // // selection
784         // // to
785         // // squigglies
786         // // if
787         // // the
788         // // key
789         // // is
790         // // not
791         // // there
792         // // (legacy
793         // // support)
794         // }
795         // key = fAnnotationColorListModel[i][3];
796         // fShowInOverviewRulerCheckBox.setSelection(fOverlayStore.getBoolean(key));
797         // key = fAnnotationColorListModel[i][4];
798         // if (key != null) {
799         // fHighlightInTextCheckBox.setSelection(fOverlayStore.getBoolean(key));
800         // fHighlightInTextCheckBox.setEnabled(true);
801         // } else
802         // fHighlightInTextCheckBox.setEnabled(false);
803         // key = fAnnotationColorListModel[i][5];
804         // if (key != null) {
805         // fShowInVerticalRulerCheckBox.setSelection(fOverlayStore.getBoolean(key));
806         // fShowInVerticalRulerCheckBox.setEnabled(true);
807         // } else {
808         // fShowInVerticalRulerCheckBox.setSelection(true);
809         // fShowInVerticalRulerCheckBox.setEnabled(false);
810         // }
811         // }
812         private Control createSyntaxPage(Composite parent) {
813                 Composite colorComposite = new Composite(parent, SWT.NULL);
814                 colorComposite.setLayout(new GridLayout());
815                 Group backgroundComposite = new Group(colorComposite,
816                                 SWT.SHADOW_ETCHED_IN);
817                 backgroundComposite.setLayout(new RowLayout());
818                 backgroundComposite.setText(PreferencesMessages
819                                 .getString("JavaEditorPreferencePage.backgroundColor"));//$NON-NLS-1$
820                 SelectionListener backgroundSelectionListener = new SelectionListener() {
821                         public void widgetSelected(SelectionEvent e) {
822                                 boolean custom = fBackgroundCustomRadioButton.getSelection();
823                                 fBackgroundColorButton.setEnabled(custom);
824                                 fOverlayStore.setValue(
825                                                 PreferenceConstants.EDITOR_BACKGROUND_DEFAULT_COLOR,
826                                                 !custom);
827                         }
828
829                         public void widgetDefaultSelected(SelectionEvent e) {
830                         }
831                 };
832                 fBackgroundDefaultRadioButton = new Button(backgroundComposite,
833                                 SWT.RADIO | SWT.LEFT);
834                 fBackgroundDefaultRadioButton.setText(PreferencesMessages
835                                 .getString("JavaEditorPreferencePage.systemDefault")); //$NON-NLS-1$
836                 fBackgroundDefaultRadioButton
837                                 .addSelectionListener(backgroundSelectionListener);
838                 fBackgroundCustomRadioButton = new Button(backgroundComposite,
839                                 SWT.RADIO | SWT.LEFT);
840                 fBackgroundCustomRadioButton.setText(PreferencesMessages
841                                 .getString("JavaEditorPreferencePage.custom")); //$NON-NLS-1$
842                 fBackgroundCustomRadioButton
843                                 .addSelectionListener(backgroundSelectionListener);
844                 fBackgroundColorEditor = new ColorEditor(backgroundComposite);
845                 fBackgroundColorButton = fBackgroundColorEditor.getButton();
846                 Label label = new Label(colorComposite, SWT.LEFT);
847                 label.setText(PreferencesMessages
848                                 .getString("JavaEditorPreferencePage.foreground")); //$NON-NLS-1$
849                 label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
850                 Composite editorComposite = new Composite(colorComposite, SWT.NONE);
851                 GridLayout layout = new GridLayout();
852                 layout.numColumns = 2;
853                 layout.marginHeight = 0;
854                 layout.marginWidth = 0;
855                 editorComposite.setLayout(layout);
856                 GridData gd = new GridData(GridData.FILL_BOTH);
857                 editorComposite.setLayoutData(gd);
858                 fSyntaxColorList = new List(editorComposite, SWT.SINGLE | SWT.V_SCROLL
859                                 | SWT.BORDER);
860                 gd = new GridData(GridData.FILL_BOTH);
861                 gd.heightHint = convertHeightInCharsToPixels(5);
862                 fSyntaxColorList.setLayoutData(gd);
863                 Composite stylesComposite = new Composite(editorComposite, SWT.NONE);
864                 layout = new GridLayout();
865                 layout.marginHeight = 0;
866                 layout.marginWidth = 0;
867                 layout.numColumns = 2;
868                 stylesComposite.setLayout(layout);
869                 stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
870                 label = new Label(stylesComposite, SWT.LEFT);
871                 label.setText(PreferencesMessages
872                                 .getString("JavaEditorPreferencePage.color")); //$NON-NLS-1$
873                 gd = new GridData();
874                 gd.horizontalAlignment = GridData.BEGINNING;
875                 label.setLayoutData(gd);
876                 fSyntaxForegroundColorEditor = new ColorEditor(stylesComposite);
877                 Button foregroundColorButton = fSyntaxForegroundColorEditor.getButton();
878                 gd = new GridData(GridData.FILL_HORIZONTAL);
879                 gd.horizontalAlignment = GridData.BEGINNING;
880                 foregroundColorButton.setLayoutData(gd);
881                 fBoldCheckBox = new Button(stylesComposite, SWT.CHECK);
882                 fBoldCheckBox.setText(PreferencesMessages
883                                 .getString("JavaEditorPreferencePage.bold")); //$NON-NLS-1$
884                 gd = new GridData(GridData.FILL_HORIZONTAL);
885                 gd.horizontalAlignment = GridData.BEGINNING;
886                 gd.horizontalSpan = 2;
887                 fBoldCheckBox.setLayoutData(gd);
888                 label = new Label(colorComposite, SWT.LEFT);
889                 label.setText(PreferencesMessages
890                                 .getString("JavaEditorPreferencePage.preview")); //$NON-NLS-1$
891                 label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
892                 Control previewer = createPreviewer(colorComposite);
893                 gd = new GridData(GridData.FILL_BOTH);
894                 gd.widthHint = convertWidthInCharsToPixels(20);
895                 gd.heightHint = convertHeightInCharsToPixels(5);
896                 previewer.setLayoutData(gd);
897                 fSyntaxColorList.addSelectionListener(new SelectionListener() {
898                         public void widgetDefaultSelected(SelectionEvent e) {
899                                 // do nothing
900                         }
901
902                         public void widgetSelected(SelectionEvent e) {
903                                 handleSyntaxColorListSelection();
904                         }
905                 });
906                 foregroundColorButton.addSelectionListener(new SelectionListener() {
907                         public void widgetDefaultSelected(SelectionEvent e) {
908                                 // do nothing
909                         }
910
911                         public void widgetSelected(SelectionEvent e) {
912                                 int i = fSyntaxColorList.getSelectionIndex();
913                                 String key = fSyntaxColorListModel[i][1];
914                                 PreferenceConverter.setValue(fOverlayStore, key,
915                                                 fSyntaxForegroundColorEditor.getColorValue());
916                         }
917                 });
918                 fBackgroundColorButton.addSelectionListener(new SelectionListener() {
919                         public void widgetDefaultSelected(SelectionEvent e) {
920                                 // do nothing
921                         }
922
923                         public void widgetSelected(SelectionEvent e) {
924                                 PreferenceConverter.setValue(fOverlayStore,
925                                                 PreferenceConstants.EDITOR_BACKGROUND_COLOR,
926                                                 fBackgroundColorEditor.getColorValue());
927                         }
928                 });
929                 fBoldCheckBox.addSelectionListener(new SelectionListener() {
930                         public void widgetDefaultSelected(SelectionEvent e) {
931                                 // do nothing
932                         }
933
934                         public void widgetSelected(SelectionEvent e) {
935                                 int i = fSyntaxColorList.getSelectionIndex();
936                                 String key = fSyntaxColorListModel[i][1];
937                                 fOverlayStore
938                                                 .setValue(key + BOLD, fBoldCheckBox.getSelection());
939                         }
940                 });
941                 return colorComposite;
942         }
943
944         private Control createPreviewer(Composite parent) {
945                 Preferences coreStore = createTemporaryCorePreferenceStore();
946                 fJavaTextTools = new JavaTextTools(fOverlayStore, coreStore, false);
947                 IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
948                 IPreferenceStore store = new ChainedPreferenceStore(
949                                 new IPreferenceStore[] {
950                                                 fOverlayStore,
951                                                 new PreferencesAdapter(
952                                                                 createTemporaryCorePreferenceStore()),
953                                                 generalTextStore });
954
955                 fPreviewViewer = new JavaSourceViewer(parent, null, null, false,
956                                 SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, store);
957                 JavaTextTools tools = PHPeclipsePlugin.getDefault().getJavaTextTools();
958                 PHPSourceViewerConfiguration configuration = new PHPSourceViewerConfiguration(
959                                 tools.getColorManager(), store, null,
960                                 IPHPPartitions.PHP_PARTITIONING);
961                 // PHPSourceViewerConfiguration configuration =new
962                 // PHPSourceViewerConfiguration(fJavaTextTools, null,
963                 // IPHPPartitions.PHP_PARTITIONING);
964                 fPreviewViewer.configure(configuration);
965
966                 Font font = JFaceResources
967                                 .getFont(PreferenceConstants.EDITOR_TEXT_FONT);
968                 fPreviewViewer.getTextWidget().setFont(font);
969                 new JavaSourcePreviewerUpdater(fPreviewViewer, configuration, store);
970                 fPreviewViewer.setEditable(false);
971                 String content = loadPreviewContentFromFile("ColorSettingPreviewCode.txt"); //$NON-NLS-1$
972                 IDocument document = new Document(content);
973                 fJavaTextTools.setupJavaDocumentPartitioner(document,
974                                 IPHPPartitions.PHP_PARTITIONING);
975                 fPreviewViewer.setDocument(document);
976                 return fPreviewViewer.getControl();
977         }
978
979         private Preferences createTemporaryCorePreferenceStore() {
980                 Preferences result = new Preferences();
981                 result.setValue(COMPILER_TASK_TAGS, "TASK"); //$NON-NLS-1$
982                 return result;
983         }
984
985         private Control createAppearancePage(Composite parent) {
986                 Composite appearanceComposite = new Composite(parent, SWT.NONE);
987                 GridLayout layout = new GridLayout();
988                 layout.numColumns = 2;
989                 appearanceComposite.setLayout(layout);
990                 String label = PreferencesMessages
991                                 .getString("JavaEditorPreferencePage.displayedTabWidth"); //$NON-NLS-1$
992                 addTextField(appearanceComposite, label,
993                                 PreferenceConstants.EDITOR_TAB_WIDTH, 3, 0, true);
994                 label = PreferencesMessages
995                                 .getString("JavaEditorPreferencePage.printMarginColumn"); //$NON-NLS-1$
996                 addTextField(
997                                 appearanceComposite,
998                                 label,
999                                 AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN,
1000                                 3, 0, true);
1001                 label = PreferencesMessages
1002                                 .getString("JavaEditorPreferencePage.showOverviewRuler"); //$NON-NLS-1$
1003                 addCheckBox(
1004                                 appearanceComposite,
1005                                 label,
1006                                 AbstractDecoratedTextEditorPreferenceConstants.EDITOR_OVERVIEW_RULER,
1007                                 0);
1008                 label = PreferencesMessages
1009                                 .getString("JavaEditorPreferencePage.showLineNumbers"); //$NON-NLS-1$
1010                 addCheckBox(
1011                                 appearanceComposite,
1012                                 label,
1013                                 AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER,
1014                                 0);
1015                 label = PreferencesMessages
1016                                 .getString("JavaEditorPreferencePage.highlightMatchingBrackets"); //$NON-NLS-1$
1017                 addCheckBox(appearanceComposite, label,
1018                                 PreferenceConstants.EDITOR_MATCHING_BRACKETS, 0);
1019                 label = PreferencesMessages
1020                                 .getString("JavaEditorPreferencePage.highlightCurrentLine"); //$NON-NLS-1$
1021                 addCheckBox(
1022                                 appearanceComposite,
1023                                 label,
1024                                 AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE,
1025                                 0);
1026                 label = PreferencesMessages
1027                                 .getString("JavaEditorPreferencePage.showPrintMargin"); //$NON-NLS-1$
1028                 addCheckBox(
1029                                 appearanceComposite,
1030                                 label,
1031                                 AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN,
1032                                 0);
1033                 label = PreferencesMessages
1034                                 .getString("JavaEditorPreferencePage.markOccurrences"); //$NON-NLS-1$
1035                 // Button master= addCheckBox(appearanceComposite, label,
1036                 // PreferenceConstants.EDITOR_MARK_OCCURRENCES, 0); //$NON-NLS-1$
1037                 label = PreferencesMessages
1038                                 .getString("JavaEditorPreferencePage.stickyOccurrences"); //$NON-NLS-1$
1039                 // fStickyOccurrencesButton= addCheckBox(appearanceComposite, label,
1040                 // PreferenceConstants.EDITOR_STICKY_OCCURRENCES, 0); //$NON-NLS-1$
1041                 // createDependency(master, fStickyOccurrencesButton);
1042                 Label l = new Label(appearanceComposite, SWT.LEFT);
1043                 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
1044                 gd.horizontalSpan = 2;
1045                 gd.heightHint = convertHeightInCharsToPixels(1) / 2;
1046                 l.setLayoutData(gd);
1047                 l = new Label(appearanceComposite, SWT.LEFT);
1048                 l.setText(PreferencesMessages
1049                                 .getString("JavaEditorPreferencePage.appearanceOptions")); //$NON-NLS-1$
1050                 gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
1051                 gd.horizontalSpan = 2;
1052                 l.setLayoutData(gd);
1053                 Composite editorComposite = new Composite(appearanceComposite, SWT.NONE);
1054                 layout = new GridLayout();
1055                 layout.numColumns = 2;
1056                 layout.marginHeight = 0;
1057                 layout.marginWidth = 0;
1058                 editorComposite.setLayout(layout);
1059                 gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL
1060                                 | GridData.FILL_VERTICAL);
1061                 gd.horizontalSpan = 2;
1062                 editorComposite.setLayoutData(gd);
1063                 fAppearanceColorList = new List(editorComposite, SWT.SINGLE
1064                                 | SWT.V_SCROLL | SWT.BORDER);
1065                 gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING
1066                                 | GridData.FILL_HORIZONTAL);
1067                 gd.heightHint = convertHeightInCharsToPixels(8);
1068                 fAppearanceColorList.setLayoutData(gd);
1069                 Composite stylesComposite = new Composite(editorComposite, SWT.NONE);
1070                 layout = new GridLayout();
1071                 layout.marginHeight = 0;
1072                 layout.marginWidth = 0;
1073                 layout.numColumns = 2;
1074                 stylesComposite.setLayout(layout);
1075                 stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
1076                 l = new Label(stylesComposite, SWT.LEFT);
1077                 l.setText(PreferencesMessages
1078                                 .getString("JavaEditorPreferencePage.color")); //$NON-NLS-1$
1079                 gd = new GridData();
1080                 gd.horizontalAlignment = GridData.BEGINNING;
1081                 l.setLayoutData(gd);
1082                 fAppearanceColorEditor = new ColorEditor(stylesComposite);
1083                 Button foregroundColorButton = fAppearanceColorEditor.getButton();
1084                 gd = new GridData(GridData.FILL_HORIZONTAL);
1085                 gd.horizontalAlignment = GridData.BEGINNING;
1086                 foregroundColorButton.setLayoutData(gd);
1087                 fAppearanceColorList.addSelectionListener(new SelectionListener() {
1088                         public void widgetDefaultSelected(SelectionEvent e) {
1089                                 // do nothing
1090                         }
1091
1092                         public void widgetSelected(SelectionEvent e) {
1093                                 handleAppearanceColorListSelection();
1094                         }
1095                 });
1096                 foregroundColorButton.addSelectionListener(new SelectionListener() {
1097                         public void widgetDefaultSelected(SelectionEvent e) {
1098                                 // do nothing
1099                         }
1100
1101                         public void widgetSelected(SelectionEvent e) {
1102                                 int i = fAppearanceColorList.getSelectionIndex();
1103                                 String key = fAppearanceColorListModel[i][1];
1104                                 PreferenceConverter.setValue(fOverlayStore, key,
1105                                                 fAppearanceColorEditor.getColorValue());
1106                         }
1107                 });
1108                 return appearanceComposite;
1109         }
1110
1111         // private Control createAnnotationsPage(Composite parent) {
1112         // Composite composite = new Composite(parent, SWT.NULL);
1113         // GridLayout layout = new GridLayout();
1114         // layout.numColumns = 2;
1115         // composite.setLayout(layout);
1116         // String text = PreferencesMessages
1117         // .getString("JavaEditorPreferencePage.analyseAnnotationsWhileTyping");
1118         // //$NON-NLS-1$
1119         // addCheckBox(composite, text,
1120         // PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS, 0);
1121         // text = PreferencesMessages
1122         // .getString("JavaEditorPreferencePage.showQuickFixables"); //$NON-NLS-1$
1123         // addCheckBox(composite, text,
1124         // PreferenceConstants.EDITOR_CORRECTION_INDICATION, 0);
1125         // addFiller(composite);
1126         // Label label = new Label(composite, SWT.LEFT);
1127         // label.setText(PreferencesMessages
1128         // .getString("JavaEditorPreferencePage.annotationPresentationOptions"));
1129         // //$NON-NLS-1$
1130         // GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
1131         // gd.horizontalSpan = 2;
1132         // label.setLayoutData(gd);
1133         // Composite editorComposite = new Composite(composite, SWT.NONE);
1134         // layout = new GridLayout();
1135         // layout.numColumns = 2;
1136         // layout.marginHeight = 0;
1137         // layout.marginWidth = 0;
1138         // editorComposite.setLayout(layout);
1139         // gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL |
1140         // GridData.FILL_VERTICAL);
1141         // gd.horizontalSpan = 2;
1142         // editorComposite.setLayoutData(gd);
1143         // fAnnotationList = new List(editorComposite, SWT.SINGLE | SWT.V_SCROLL
1144         // | SWT.BORDER);
1145         // gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING
1146         // | GridData.FILL_HORIZONTAL);
1147         // gd.heightHint = convertHeightInCharsToPixels(10);
1148         // fAnnotationList.setLayoutData(gd);
1149         // Composite optionsComposite = new Composite(editorComposite, SWT.NONE);
1150         // layout = new GridLayout();
1151         // layout.marginHeight = 0;
1152         // layout.marginWidth = 0;
1153         // layout.numColumns = 2;
1154         // optionsComposite.setLayout(layout);
1155         // optionsComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
1156         // fShowInTextCheckBox = new Button(optionsComposite, SWT.CHECK);
1157         // fShowInTextCheckBox.setText(PreferencesMessages
1158         // .getString("JavaEditorPreferencePage.annotations.showInText"));
1159         // //$NON-NLS-1$
1160         // gd = new GridData(GridData.FILL_HORIZONTAL);
1161         // gd.horizontalAlignment = GridData.BEGINNING;
1162         // gd.horizontalSpan = 2;
1163         // fShowInTextCheckBox.setLayoutData(gd);
1164         // fDecorationStyleCombo = new Combo(optionsComposite, SWT.READ_ONLY);
1165         // for (int i = 0; i < fAnnotationDecorationListModel.length; i++)
1166         // fDecorationStyleCombo.add(fAnnotationDecorationListModel[i][0]);
1167         // gd = new GridData(GridData.FILL_HORIZONTAL);
1168         // gd.horizontalAlignment = GridData.BEGINNING;
1169         // gd.horizontalSpan = 2;
1170         // gd.horizontalIndent = 20;
1171         // fDecorationStyleCombo.setLayoutData(gd);
1172         // fHighlightInTextCheckBox = new Button(optionsComposite, SWT.CHECK);
1173         // fHighlightInTextCheckBox.setText(PreferencesMessages
1174         // .getString("TextEditorPreferencePage.annotations.highlightInText"));
1175         // //$NON-NLS-1$
1176         // gd = new GridData(GridData.FILL_HORIZONTAL);
1177         // gd.horizontalAlignment = GridData.BEGINNING;
1178         // gd.horizontalSpan = 2;
1179         // fHighlightInTextCheckBox.setLayoutData(gd);
1180         // fShowInOverviewRulerCheckBox = new Button(optionsComposite, SWT.CHECK);
1181         // fShowInOverviewRulerCheckBox.setText(PreferencesMessages
1182         // .getString("JavaEditorPreferencePage.annotations.showInOverviewRuler"));
1183         // //$NON-NLS-1$
1184         // gd = new GridData(GridData.FILL_HORIZONTAL);
1185         // gd.horizontalAlignment = GridData.BEGINNING;
1186         // gd.horizontalSpan = 2;
1187         // fShowInOverviewRulerCheckBox.setLayoutData(gd);
1188         // fShowInVerticalRulerCheckBox = new Button(optionsComposite, SWT.CHECK);
1189         // fShowInVerticalRulerCheckBox.setText(PreferencesMessages
1190         // .getString("JavaEditorPreferencePage.annotations.showInVerticalRuler"));
1191         // //$NON-NLS-1$
1192         // gd = new GridData(GridData.FILL_HORIZONTAL);
1193         // gd.horizontalAlignment = GridData.BEGINNING;
1194         // gd.horizontalSpan = 2;
1195         // fShowInVerticalRulerCheckBox.setLayoutData(gd);
1196         // label = new Label(optionsComposite, SWT.LEFT);
1197         // label.setText(PreferencesMessages
1198         // .getString("JavaEditorPreferencePage.annotations.color")); //$NON-NLS-1$
1199         // gd = new GridData();
1200         // gd.horizontalAlignment = GridData.BEGINNING;
1201         // label.setLayoutData(gd);
1202         // fAnnotationForegroundColorEditor = new ColorEditor(optionsComposite);
1203         // Button foregroundColorButton =
1204         // fAnnotationForegroundColorEditor.getButton();
1205         // gd = new GridData(GridData.FILL_HORIZONTAL);
1206         // gd.horizontalAlignment = GridData.BEGINNING;
1207         // foregroundColorButton.setLayoutData(gd);
1208         // fAnnotationList.addSelectionListener(new SelectionListener() {
1209         // public void widgetDefaultSelected(SelectionEvent e) {
1210         // // do nothing
1211         // }
1212         // public void widgetSelected(SelectionEvent e) {
1213         // handleAnnotationListSelection();
1214         // }
1215         // });
1216         // fShowInTextCheckBox.addSelectionListener(new SelectionListener() {
1217         // public void widgetDefaultSelected(SelectionEvent e) {
1218         // // do nothing
1219         // }
1220         // public void widgetSelected(SelectionEvent e) {
1221         // int i = fAnnotationList.getSelectionIndex();
1222         // String key = fAnnotationColorListModel[i][2];
1223         // fOverlayStore.setValue(key, fShowInTextCheckBox.getSelection());
1224         // String decorationKey = fAnnotationColorListModel[i][6];
1225         // fDecorationStyleCombo.setEnabled(decorationKey != null
1226         // && fShowInTextCheckBox.getSelection());
1227         // }
1228         // });
1229         // fHighlightInTextCheckBox.addSelectionListener(new SelectionListener() {
1230         // public void widgetDefaultSelected(SelectionEvent e) {
1231         // // do nothing
1232         // }
1233         // public void widgetSelected(SelectionEvent e) {
1234         // int i = fAnnotationList.getSelectionIndex();
1235         // String key = fAnnotationColorListModel[i][4];
1236         // fOverlayStore.setValue(key, fHighlightInTextCheckBox.getSelection());
1237         // }
1238         // });
1239         // fShowInOverviewRulerCheckBox.addSelectionListener(new SelectionListener()
1240         // {
1241         // public void widgetDefaultSelected(SelectionEvent e) {
1242         // // do nothing
1243         // }
1244         // public void widgetSelected(SelectionEvent e) {
1245         // int i = fAnnotationList.getSelectionIndex();
1246         // String key = fAnnotationColorListModel[i][3];
1247         // fOverlayStore
1248         // .setValue(key, fShowInOverviewRulerCheckBox.getSelection());
1249         // }
1250         // });
1251         // fShowInVerticalRulerCheckBox.addSelectionListener(new SelectionListener()
1252         // {
1253         // public void widgetDefaultSelected(SelectionEvent e) {
1254         // // do nothing
1255         // }
1256         // public void widgetSelected(SelectionEvent e) {
1257         // int i = fAnnotationList.getSelectionIndex();
1258         // String key = fAnnotationColorListModel[i][5];
1259         // fOverlayStore
1260         // .setValue(key, fShowInVerticalRulerCheckBox.getSelection());
1261         // }
1262         // });
1263         // foregroundColorButton.addSelectionListener(new SelectionListener() {
1264         // public void widgetDefaultSelected(SelectionEvent e) {
1265         // // do nothing
1266         // }
1267         // public void widgetSelected(SelectionEvent e) {
1268         // int i = fAnnotationList.getSelectionIndex();
1269         // String key = fAnnotationColorListModel[i][1];
1270         // PreferenceConverter.setValue(fOverlayStore, key,
1271         // fAnnotationForegroundColorEditor.getColorValue());
1272         // }
1273         // });
1274         // fDecorationStyleCombo.addSelectionListener(new SelectionListener() {
1275         // /**
1276         // * {@inheritdoc}
1277         // */
1278         // public void widgetDefaultSelected(SelectionEvent e) {
1279         // // do nothing
1280         // }
1281         // /**
1282         // * {@inheritdoc}
1283         // */
1284         // public void widgetSelected(SelectionEvent e) {
1285         // int i = fAnnotationList.getSelectionIndex();
1286         // String key = fAnnotationColorListModel[i][6];
1287         // if (key != null) {
1288         // for (int j = 0; j < fAnnotationDecorationListModel.length; j++) {
1289         // if (fAnnotationDecorationListModel[j][0]
1290         // .equals(fDecorationStyleCombo.getText())) {
1291         // fOverlayStore.setValue(key, fAnnotationDecorationListModel[j][1]);
1292         // break;
1293         // }
1294         // }
1295         // }
1296         // }
1297         // });
1298         // return composite;
1299         // }
1300         private String[][] createAnnotationTypeListModel(
1301                         MarkerAnnotationPreferences preferences) {
1302                 ArrayList listModelItems = new ArrayList();
1303                 SortedSet sortedPreferences = new TreeSet(new Comparator() {
1304                         /*
1305                          * @see java.util.Comparator#compare(java.lang.Object,
1306                          *      java.lang.Object)
1307                          */
1308                         public int compare(Object o1, Object o2) {
1309                                 if (!(o2 instanceof AnnotationPreference))
1310                                         return -1;
1311                                 if (!(o1 instanceof AnnotationPreference))
1312                                         return 1;
1313                                 AnnotationPreference a1 = (AnnotationPreference) o1;
1314                                 AnnotationPreference a2 = (AnnotationPreference) o2;
1315                                 return Collator.getInstance().compare(a1.getPreferenceLabel(),
1316                                                 a2.getPreferenceLabel());
1317                         }
1318                 });
1319                 sortedPreferences.addAll(preferences.getAnnotationPreferences());
1320                 Iterator e = sortedPreferences.iterator();
1321                 while (e.hasNext()) {
1322                         AnnotationPreference info = (AnnotationPreference) e.next();
1323                         listModelItems.add(new String[] { info.getPreferenceLabel(),
1324                                         info.getColorPreferenceKey(), info.getTextPreferenceKey(),
1325                                         info.getOverviewRulerPreferenceKey(),
1326                                         info.getHighlightPreferenceKey(),
1327                                         info.getVerticalRulerPreferenceKey(),
1328                                         info.getTextStylePreferenceKey() });
1329                 }
1330                 String[][] items = new String[listModelItems.size()][];
1331                 listModelItems.toArray(items);
1332                 return items;
1333         }
1334
1335         private Control createTypingPage(Composite parent) {
1336                 Composite composite = new Composite(parent, SWT.NONE);
1337                 GridLayout layout = new GridLayout();
1338                 layout.numColumns = 1;
1339                 composite.setLayout(layout);
1340                 String label;
1341                 // label = PreferencesMessages
1342                 // .getString("JavaEditorPreferencePage.overwriteMode");
1343                 // //$NON-NLS-1$
1344                 // addCheckBox(composite, label,
1345                 // PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE, 1);
1346                 // addFiller(composite);
1347                 //
1348                 // label = PreferencesMessages
1349                 // .getString("JavaEditorPreferencePage.smartHomeEnd");
1350                 // //$NON-NLS-1$
1351                 // addCheckBox(composite, label,
1352                 // PreferenceConstants.EDITOR_SMART_HOME_END, 1);
1353                 //
1354                 // label = PreferencesMessages
1355                 // .getString("JavaEditorPreferencePage.subWordNavigation");
1356                 // //$NON-NLS-1$
1357                 // addCheckBox(composite, label,
1358                 // PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION, 1);
1359                 // addFiller(composite);
1360                 Group group = new Group(composite, SWT.NONE);
1361                 layout = new GridLayout();
1362                 layout.numColumns = 2;
1363                 group.setLayout(layout);
1364                 group.setText(PreferencesMessages
1365                                 .getString("JavaEditorPreferencePage.typing.description")); //$NON-NLS-1$
1366
1367                 label = PreferencesMessages
1368                                 .getString("JavaEditorPreferencePage.wrapWords");//$NON-NLS-1$
1369                 addCheckBox(group, label, PreferenceConstants.EDITOR_WRAP_WORDS, 1);
1370
1371                 label = PreferencesMessages
1372                                 .getString("JavaEditorPreferencePage.wrapStringsDQ");//$NON-NLS-1$
1373                 Button button = addCheckBox(group, label,
1374                                 PreferenceConstants.EDITOR_WRAP_STRINGS_DQ, 1);
1375
1376                 label = PreferencesMessages
1377                                 .getString("JavaEditorPreferencePage.escapeStringsDQ");//$NON-NLS-1$
1378                 fEscapeStringsButtonDQ = addCheckBox(group, label,
1379                                 PreferenceConstants.EDITOR_ESCAPE_STRINGS_DQ, 1);
1380                 createDependency(button, fEscapeStringsButtonDQ);
1381
1382                 label = PreferencesMessages
1383                                 .getString("JavaEditorPreferencePage.wrapStringsSQ");//$NON-NLS-1$
1384                 button = addCheckBox(group, label,
1385                                 PreferenceConstants.EDITOR_WRAP_STRINGS_SQ, 1);
1386
1387                 label = PreferencesMessages
1388                                 .getString("JavaEditorPreferencePage.escapeStringsSQ");
1389                 //$NON-NLS-1$
1390                 fEscapeStringsButtonSQ = addCheckBox(group, label,
1391                                 PreferenceConstants.EDITOR_ESCAPE_STRINGS_SQ, 1);
1392                 createDependency(button, fEscapeStringsButtonSQ);
1393
1394                 label = PreferencesMessages
1395                                 .getString("JavaEditorPreferencePage.smartPaste");
1396                 //$NON-NLS-1$
1397                 addCheckBox(group, label, PreferenceConstants.EDITOR_SMART_PASTE, 1);
1398
1399                 label = PreferencesMessages
1400                                 .getString("JavaEditorPreferencePage.insertSpaceForTabs");
1401                 //$NON-NLS-1$
1402                 addCheckBox(group, label, PreferenceConstants.EDITOR_SPACES_FOR_TABS, 1);
1403
1404                 label = PreferencesMessages
1405                                 .getString("JavaEditorPreferencePage.closeStringsDQ");
1406                 //$NON-NLS-1$
1407                 addCheckBox(group, label,
1408                                 PreferenceConstants.EDITOR_CLOSE_STRINGS_DQ_PHP, 1);
1409                 label = PreferencesMessages
1410                                 .getString("JavaEditorPreferencePage.closeStringsSQ");
1411                 //$NON-NLS-1$
1412                 addCheckBox(group, label,
1413                                 PreferenceConstants.EDITOR_CLOSE_STRINGS_SQ_PHP, 1);
1414
1415                 label = PreferencesMessages
1416                                 .getString("JavaEditorPreferencePage.closeBrackets");
1417                 //$NON-NLS-1$
1418                 addCheckBox(group, label,
1419                                 PreferenceConstants.EDITOR_CLOSE_BRACKETS_PHP, 1);
1420
1421                 // label = PreferencesMessages
1422                 // .getString("JavaEditorPreferencePage.closeBraces");
1423                 // //$NON-NLS-1$
1424                 // addCheckBox(group, label, PreferenceConstants.EDITOR_CLOSE_BRACES,
1425                 // 1);
1426
1427                 label = PreferencesMessages
1428                                 .getString("JavaEditorPreferencePage.closeJavaDocs");
1429                 //$NON-NLS-1$
1430                 button = addCheckBox(group, label,
1431                                 PreferenceConstants.EDITOR_CLOSE_JAVADOCS, 1);
1432                 label = PreferencesMessages
1433                                 .getString("JavaEditorPreferencePage.formatJavaDocs");
1434                 //$NON-NLS-1$
1435                 button = addCheckBox(group, label,
1436                                 PreferenceConstants.EDITOR_FORMAT_JAVADOCS, 1);
1437
1438                 label = PreferencesMessages
1439                                 .getString("JavaEditorPreferencePage.p_rtrim_on_save");
1440                 addCheckBox(group, label, PreferenceConstants.EDITOR_P_RTRIM_ON_SAVE, 1);
1441                 //
1442                 // label = PreferencesMessages
1443                 // .getString("JavaEditorPreferencePage.addJavaDocTags");
1444                 // //$NON-NLS-1$
1445                 // fAddJavaDocTagsButton = addCheckBox(group, label,
1446                 // PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS, 1);
1447                 // createDependency(button, fAddJavaDocTagsButton);
1448                 return composite;
1449         }
1450
1451         private void addFiller(Composite composite) {
1452                 Label filler = new Label(composite, SWT.LEFT);
1453                 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
1454                 gd.horizontalSpan = 2;
1455                 gd.heightHint = convertHeightInCharsToPixels(1) / 2;
1456                 filler.setLayoutData(gd);
1457         }
1458
1459         private static void indent(Control control) {
1460                 GridData gridData = new GridData();
1461                 gridData.horizontalIndent = 20;
1462                 control.setLayoutData(gridData);
1463         }
1464
1465         private static void createDependency(final Button master,
1466                         final Control slave) {
1467                 indent(slave);
1468                 master.addSelectionListener(new SelectionListener() {
1469                         public void widgetSelected(SelectionEvent e) {
1470                                 slave.setEnabled(master.getSelection());
1471                         }
1472
1473                         public void widgetDefaultSelected(SelectionEvent e) {
1474                         }
1475                 });
1476         }
1477
1478         private void addCompletionRadioButtons(Composite contentAssistComposite) {
1479                 Composite completionComposite = new Composite(contentAssistComposite,
1480                                 SWT.NONE);
1481                 GridData ccgd = new GridData();
1482                 ccgd.horizontalSpan = 2;
1483                 completionComposite.setLayoutData(ccgd);
1484                 GridLayout ccgl = new GridLayout();
1485                 ccgl.marginWidth = 0;
1486                 ccgl.numColumns = 2;
1487                 completionComposite.setLayout(ccgl);
1488                 // SelectionListener completionSelectionListener= new SelectionAdapter()
1489                 // {
1490                 // public void widgetSelected(SelectionEvent e) {
1491                 // boolean insert= fCompletionInsertsRadioButton.getSelection();
1492                 // fOverlayStore.setValue(PreferenceConstants.CODEASSIST_INSERT_COMPLETION,
1493                 // insert);
1494                 // }
1495                 // };
1496                 //
1497                 // fCompletionInsertsRadioButton= new Button(completionComposite,
1498                 // SWT.RADIO
1499                 // | SWT.LEFT);
1500                 // fCompletionInsertsRadioButton.setText(PreferencesMessages.getString("JavaEditorPreferencePage.completionInserts"));
1501                 // //$NON-NLS-1$
1502                 // fCompletionInsertsRadioButton.setLayoutData(new GridData());
1503                 // fCompletionInsertsRadioButton.addSelectionListener(completionSelectionListener);
1504                 //
1505                 // fCompletionOverwritesRadioButton= new Button(completionComposite,
1506                 // SWT.RADIO | SWT.LEFT);
1507                 // fCompletionOverwritesRadioButton.setText(PreferencesMessages.getString("JavaEditorPreferencePage.completionOverwrites"));
1508                 // //$NON-NLS-1$
1509                 // fCompletionOverwritesRadioButton.setLayoutData(new GridData());
1510                 // fCompletionOverwritesRadioButton.addSelectionListener(completionSelectionListener);
1511         }
1512
1513         private Control createNavigationPage(Composite parent) {
1514                 Composite composite = new Composite(parent, SWT.NULL);
1515                 GridLayout layout = new GridLayout();
1516                 layout.numColumns = 2;
1517                 composite.setLayout(layout);
1518                 String text = PreferencesMessages
1519                                 .getString("JavaEditorPreferencePage.navigation.browserLikeLinks");
1520                 //$NON-NLS-1$
1521                 fBrowserLikeLinksCheckBox = addCheckBox(composite, text,
1522                                 PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS, 0);
1523                 fBrowserLikeLinksCheckBox.addSelectionListener(new SelectionListener() {
1524                         public void widgetSelected(SelectionEvent e) {
1525                                 boolean state = fBrowserLikeLinksCheckBox.getSelection();
1526                                 fBrowserLikeLinksKeyModifierText.setEnabled(state);
1527                                 handleBrowserLikeLinksKeyModifierModified();
1528                         }
1529
1530                         public void widgetDefaultSelected(SelectionEvent e) {
1531                         }
1532                 });
1533                 // Text field for modifier string
1534                 text = PreferencesMessages
1535                                 .getString("JavaEditorPreferencePage.navigation.browserLikeLinksKeyModifier");
1536                 //$NON-NLS-1$
1537                 fBrowserLikeLinksKeyModifierText = addTextField(composite, text,
1538                                 PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER, 20,
1539                                 0, false);
1540                 fBrowserLikeLinksKeyModifierText.setTextLimit(Text.LIMIT);
1541
1542                 if (computeStateMask(fOverlayStore
1543                                 .getString(PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER)) == -1) {
1544                         // Fix possible illegal modifier string
1545                         int stateMask = fOverlayStore
1546                                         .getInt(PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK);
1547                         if (stateMask == -1)
1548                                 fBrowserLikeLinksKeyModifierText.setText(""); //$NON-NLS-1$
1549                         else
1550                                 fBrowserLikeLinksKeyModifierText.setText(EditorUtility
1551                                                 .getModifierString(stateMask));
1552                 }
1553                 fBrowserLikeLinksKeyModifierText.addKeyListener(new KeyListener() {
1554                         private boolean isModifierCandidate;
1555
1556                         public void keyPressed(KeyEvent e) {
1557                                 isModifierCandidate = e.keyCode > 0 && e.character == 0
1558                                                 && e.stateMask == 0;
1559                         }
1560
1561                         public void keyReleased(KeyEvent e) {
1562                                 if (isModifierCandidate && e.stateMask > 0
1563                                                 && e.stateMask == e.stateMask && e.character == 0) {// &&
1564                                                                                                                                                         // e.time
1565                                                                                                                                                         // -time
1566                                                                                                                                                         // <
1567                                                                                                                                                         // 1000)
1568                                                                                                                                                         // {
1569                                         String modifierString = fBrowserLikeLinksKeyModifierText
1570                                                         .getText();
1571                                         Point selection = fBrowserLikeLinksKeyModifierText
1572                                                         .getSelection();
1573                                         int i = selection.x - 1;
1574                                         while (i > -1
1575                                                         && Character.isWhitespace(modifierString.charAt(i))) {
1576                                                 i--;
1577                                         }
1578                                         boolean needsPrefixDelimiter = i > -1
1579                                                         && !String.valueOf(modifierString.charAt(i))
1580                                                                         .equals(DELIMITER);
1581
1582                                         i = selection.y;
1583                                         while (i < modifierString.length()
1584                                                         && Character.isWhitespace(modifierString.charAt(i))) {
1585                                                 i++;
1586                                         }
1587                                         boolean needsPostfixDelimiter = i < modifierString.length()
1588                                                         && !String.valueOf(modifierString.charAt(i))
1589                                                                         .equals(DELIMITER);
1590
1591                                         String insertString;
1592
1593                                         if (needsPrefixDelimiter && needsPostfixDelimiter)
1594                                                 insertString = PreferencesMessages
1595                                                                 .getFormattedString(
1596                                                                                 "JavaEditorPreferencePage.navigation.insertDelimiterAndModifierAndDelimiter",
1597                                                                                 new String[] { Action
1598                                                                                                 .findModifierString(e.stateMask) }); //$NON-NLS-1$
1599                                         else if (needsPrefixDelimiter)
1600                                                 insertString = PreferencesMessages
1601                                                                 .getFormattedString(
1602                                                                                 "JavaEditorPreferencePage.navigation.insertDelimiterAndModifier",
1603                                                                                 new String[] { Action
1604                                                                                                 .findModifierString(e.stateMask) }); //$NON-NLS-1$
1605                                         else if (needsPostfixDelimiter)
1606                                                 insertString = PreferencesMessages
1607                                                                 .getFormattedString(
1608                                                                                 "JavaEditorPreferencePage.navigation.insertModifierAndDelimiter",
1609                                                                                 new String[] { Action
1610                                                                                                 .findModifierString(e.stateMask) }); //$NON-NLS-1$
1611                                         else
1612                                                 insertString = Action.findModifierString(e.stateMask);
1613
1614                                         fBrowserLikeLinksKeyModifierText.insert(insertString);
1615                                 }
1616                         }
1617                 });
1618
1619                 fBrowserLikeLinksKeyModifierText
1620                                 .addModifyListener(new ModifyListener() {
1621                                         public void modifyText(ModifyEvent e) {
1622                                                 handleBrowserLikeLinksKeyModifierModified();
1623                                         }
1624                                 });
1625                 return composite;
1626         }
1627
1628         private void handleBrowserLikeLinksKeyModifierModified() {
1629                 String modifiers = fBrowserLikeLinksKeyModifierText.getText();
1630                 int stateMask = computeStateMask(modifiers);
1631                 if (fBrowserLikeLinksCheckBox.getSelection()
1632                                 && (stateMask == -1 || (stateMask & SWT.SHIFT) != 0)) {
1633                         if (stateMask == -1)
1634                                 fBrowserLikeLinksKeyModifierStatus = new StatusInfo(
1635                                                 IStatus.ERROR,
1636                                                 PreferencesMessages
1637                                                                 .getFormattedString(
1638                                                                                 "JavaEditorPreferencePage.navigation.modifierIsNotValid", modifiers)); //$NON-NLS-1$
1639                         else
1640                                 fBrowserLikeLinksKeyModifierStatus = new StatusInfo(
1641                                                 IStatus.ERROR,
1642                                                 PreferencesMessages
1643                                                                 .getString("JavaEditorPreferencePage.navigation.shiftIsDisabled"));
1644                         //$NON-NLS-1$
1645                         setValid(false);
1646                         StatusUtil.applyToStatusLine(this,
1647                                         fBrowserLikeLinksKeyModifierStatus);
1648                 } else {
1649                         fBrowserLikeLinksKeyModifierStatus = new StatusInfo();
1650                         updateStatus(fBrowserLikeLinksKeyModifierStatus);
1651                 }
1652         }
1653
1654         private IStatus getBrowserLikeLinksKeyModifierStatus() {
1655                 if (fBrowserLikeLinksKeyModifierStatus == null)
1656                         fBrowserLikeLinksKeyModifierStatus = new StatusInfo();
1657                 return fBrowserLikeLinksKeyModifierStatus;
1658         }
1659
1660         /**
1661          * Computes the state mask for the given modifier string.
1662          * 
1663          * @param modifiers
1664          *            the string with the modifiers, separated by '+', '-', ';', ','
1665          *            or '.'
1666          * @return the state mask or -1 if the input is invalid
1667          */
1668         private int computeStateMask(String modifiers) {
1669                 if (modifiers == null)
1670                         return -1;
1671                 if (modifiers.length() == 0)
1672                         return SWT.NONE;
1673                 int stateMask = 0;
1674                 StringTokenizer modifierTokenizer = new StringTokenizer(modifiers,
1675                                 ",;.:+-* "); //$NON-NLS-1$
1676                 while (modifierTokenizer.hasMoreTokens()) {
1677                         int modifier = EditorUtility
1678                                         .findLocalizedModifier(modifierTokenizer.nextToken());
1679                         if (modifier == 0 || (stateMask & modifier) == modifier)
1680                                 return -1;
1681                         stateMask = stateMask | modifier;
1682                 }
1683                 return stateMask;
1684         }
1685
1686         /*
1687          * @see PreferencePage#createContents(Composite)
1688          */
1689         protected Control createContents(Composite parent) {
1690                 initializeDefaultColors();
1691                 fFoldingConfigurationBlock = new FoldingConfigurationBlock(
1692                                 fOverlayStore);
1693                 fOverlayStore.load();
1694                 fOverlayStore.start();
1695                 TabFolder folder = new TabFolder(parent, SWT.NONE);
1696                 folder.setLayout(new TabFolderLayout());
1697                 folder.setLayoutData(new GridData(GridData.FILL_BOTH));
1698                 TabItem item = new TabItem(folder, SWT.NONE);
1699                 item.setText(PreferencesMessages
1700                                 .getString("JavaEditorPreferencePage.general")); //$NON-NLS-1$
1701                 item.setControl(createAppearancePage(folder));
1702                 item = new TabItem(folder, SWT.NONE);
1703                 item.setText(PreferencesMessages
1704                                 .getString("JavaEditorPreferencePage.colors")); //$NON-NLS-1$
1705                 item.setControl(createSyntaxPage(folder));
1706
1707                 // item = new TabItem(folder, SWT.NONE);
1708                 // item.setText(PreferencesMessages
1709                 // .getString("JavaEditorPreferencePage.annotationsTab.title"));
1710                 // //$NON-NLS-1$
1711                 // item.setControl(createAnnotationsPage(folder));
1712                 item = new TabItem(folder, SWT.NONE);
1713                 item.setText(PreferencesMessages
1714                                 .getString("JavaEditorPreferencePage.typing.tabTitle"));
1715                 //$NON-NLS-1$
1716                 item.setControl(createTypingPage(folder));
1717
1718                 item = new TabItem(folder, SWT.NONE);
1719                 item.setText(PreferencesMessages
1720                                 .getString("JavaEditorPreferencePage.hoverTab.title"));
1721                 //$NON-NLS-1$
1722                 fJavaEditorHoverConfigurationBlock = new JavaEditorHoverConfigurationBlock(
1723                                 this, fOverlayStore);
1724                 item.setControl(fJavaEditorHoverConfigurationBlock
1725                                 .createControl(folder));
1726                 item = new TabItem(folder, SWT.NONE);
1727                 item.setText(PreferencesMessages
1728                                 .getString("JavaEditorPreferencePage.navigationTab.title"));
1729                 // //$NON-NLS-1$
1730                 item.setControl(createNavigationPage(folder));
1731                 item = new TabItem(folder, SWT.NONE);
1732                 item.setText(PreferencesMessages
1733                                 .getString("JavaEditorPreferencePage.folding.title")); //$NON-NLS-1$
1734                 item.setControl(fFoldingConfigurationBlock.createControl(folder));
1735
1736                 initialize();
1737                 Dialog.applyDialogFont(folder);
1738                 return folder;
1739         }
1740
1741         private void initialize() {
1742                 initializeFields();
1743                 for (int i = 0; i < fSyntaxColorListModel.length; i++)
1744                         fSyntaxColorList.add(fSyntaxColorListModel[i][0]);
1745                 fSyntaxColorList.getDisplay().asyncExec(new Runnable() {
1746                         public void run() {
1747                                 if (fSyntaxColorList != null && !fSyntaxColorList.isDisposed()) {
1748                                         fSyntaxColorList.select(0);
1749                                         handleSyntaxColorListSelection();
1750                                 }
1751                         }
1752                 });
1753                 for (int i = 0; i < fAppearanceColorListModel.length; i++)
1754                         fAppearanceColorList.add(fAppearanceColorListModel[i][0]);
1755                 fAppearanceColorList.getDisplay().asyncExec(new Runnable() {
1756                         public void run() {
1757                                 if (fAppearanceColorList != null
1758                                                 && !fAppearanceColorList.isDisposed()) {
1759                                         fAppearanceColorList.select(0);
1760                                         handleAppearanceColorListSelection();
1761                                 }
1762                         }
1763                 });
1764                 // for (int i = 0; i < fAnnotationColorListModel.length; i++)
1765                 // fAnnotationList.add(fAnnotationColorListModel[i][0]);
1766                 // fAnnotationList.getDisplay().asyncExec(new Runnable() {
1767                 // public void run() {
1768                 // if (fAnnotationList != null && !fAnnotationList.isDisposed()) {
1769                 // fAnnotationList.select(0);
1770                 // handleAnnotationListSelection();
1771                 // }
1772                 // }
1773                 // });
1774                 // for (int i= 0; i < fContentAssistColorListModel.length; i++)
1775                 // fContentAssistColorList.add(fContentAssistColorListModel[i][0]);
1776                 // fContentAssistColorList.getDisplay().asyncExec(new Runnable() {
1777                 // public void run() {
1778                 // if (fContentAssistColorList != null &&
1779                 // !fContentAssistColorList.isDisposed()) {
1780                 // fContentAssistColorList.select(0);
1781                 // handleContentAssistColorListSelection();
1782                 // }
1783                 // }
1784                 // });
1785                 fFoldingConfigurationBlock.initialize();
1786         }
1787
1788         private void initializeFields() {
1789                 Iterator e = fColorButtons.keySet().iterator();
1790                 while (e.hasNext()) {
1791                         ColorEditor c = (ColorEditor) e.next();
1792                         String key = (String) fColorButtons.get(c);
1793                         RGB rgb = PreferenceConverter.getColor(fOverlayStore, key);
1794                         c.setColorValue(rgb);
1795                 }
1796                 e = fCheckBoxes.keySet().iterator();
1797                 while (e.hasNext()) {
1798                         Button b = (Button) e.next();
1799                         String key = (String) fCheckBoxes.get(b);
1800                         b.setSelection(fOverlayStore.getBoolean(key));
1801                 }
1802                 e = fTextFields.keySet().iterator();
1803                 while (e.hasNext()) {
1804                         Text t = (Text) e.next();
1805                         String key = (String) fTextFields.get(t);
1806                         t.setText(fOverlayStore.getString(key));
1807                 }
1808                 RGB rgb = PreferenceConverter.getColor(fOverlayStore,
1809                                 PreferenceConstants.EDITOR_BACKGROUND_COLOR);
1810                 fBackgroundColorEditor.setColorValue(rgb);
1811                 boolean default_ = fOverlayStore
1812                                 .getBoolean(PreferenceConstants.EDITOR_BACKGROUND_DEFAULT_COLOR);
1813                 fBackgroundDefaultRadioButton.setSelection(default_);
1814                 fBackgroundCustomRadioButton.setSelection(!default_);
1815                 fBackgroundColorButton.setEnabled(!default_);
1816                 boolean closeJavaDocs = fOverlayStore
1817                                 .getBoolean(PreferenceConstants.EDITOR_CLOSE_JAVADOCS);
1818                 // fAddJavaDocTagsButton.setEnabled(closeJavaDocs);
1819                 fEscapeStringsButtonDQ.setEnabled(fOverlayStore
1820                                 .getBoolean(PreferenceConstants.EDITOR_WRAP_STRINGS_DQ));
1821                 fEscapeStringsButtonSQ.setEnabled(fOverlayStore
1822                                 .getBoolean(PreferenceConstants.EDITOR_WRAP_STRINGS_SQ));
1823                 // boolean fillMethodArguments=
1824                 // fOverlayStore.getBoolean(PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES);
1825                 // fGuessMethodArgumentsButton.setEnabled(fillMethodArguments);
1826                 // boolean completionInserts=
1827                 // fOverlayStore.getBoolean(PreferenceConstants.CODEASSIST_INSERT_COMPLETION);
1828                 // fCompletionInsertsRadioButton.setSelection(completionInserts);
1829                 // fCompletionOverwritesRadioButton.setSelection(! completionInserts);
1830                 //
1831                 fBrowserLikeLinksKeyModifierText.setEnabled(fBrowserLikeLinksCheckBox
1832                                 .getSelection());
1833                 // boolean markOccurrences=
1834                 // fOverlayStore.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES);
1835                 // fStickyOccurrencesButton.setEnabled(markOccurrences);
1836                 updateAutoactivationControls();
1837         }
1838
1839         private void initializeDefaultColors() {
1840                 if (!getPreferenceStore().contains(
1841                                 PreferenceConstants.EDITOR_BACKGROUND_COLOR)) {
1842                         RGB rgb = getControl().getDisplay().getSystemColor(
1843                                         SWT.COLOR_LIST_BACKGROUND).getRGB();
1844                         PreferenceConverter.setDefault(fOverlayStore,
1845                                         PreferenceConstants.EDITOR_BACKGROUND_COLOR, rgb);
1846                         PreferenceConverter.setDefault(getPreferenceStore(),
1847                                         PreferenceConstants.EDITOR_BACKGROUND_COLOR, rgb);
1848                 }
1849                 if (!getPreferenceStore().contains(
1850                                 PreferenceConstants.EDITOR_FOREGROUND_COLOR)) {
1851                         RGB rgb = getControl().getDisplay().getSystemColor(
1852                                         SWT.COLOR_LIST_FOREGROUND).getRGB();
1853                         PreferenceConverter.setDefault(fOverlayStore,
1854                                         PreferenceConstants.EDITOR_FOREGROUND_COLOR, rgb);
1855                         PreferenceConverter.setDefault(getPreferenceStore(),
1856                                         PreferenceConstants.EDITOR_FOREGROUND_COLOR, rgb);
1857                 }
1858         }
1859
1860         private void updateAutoactivationControls() {
1861                 // boolean autoactivation=
1862                 // fOverlayStore.getBoolean(PreferenceConstants.CODEASSIST_AUTOACTIVATION);
1863                 // fAutoInsertDelayText.setEnabled(autoactivation);
1864                 // fAutoInsertDelayLabel.setEnabled(autoactivation);
1865                 // fAutoInsertJavaTriggerText.setEnabled(autoactivation);
1866                 // fAutoInsertJavaTriggerLabel.setEnabled(autoactivation);
1867                 //
1868                 // fAutoInsertJavaDocTriggerText.setEnabled(autoactivation);
1869                 // fAutoInsertJavaDocTriggerLabel.setEnabled(autoactivation);
1870         }
1871
1872         /*
1873          * @see PreferencePage#performOk()
1874          */
1875         public boolean performOk() {
1876                 // fJavaEditorHoverConfigurationBlock.performOk();
1877                 fFoldingConfigurationBlock.performOk();
1878                 fOverlayStore
1879                                 .setValue(
1880                                                 PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK,
1881                                                 computeStateMask(fBrowserLikeLinksKeyModifierText
1882                                                                 .getText()));
1883                 fOverlayStore.propagate();
1884                 PHPeclipsePlugin.getDefault().savePluginPreferences();
1885                 return true;
1886         }
1887
1888         /*
1889          * @see PreferencePage#performDefaults()
1890          */
1891         protected void performDefaults() {
1892                 fOverlayStore.loadDefaults();
1893                 initializeFields();
1894                 handleSyntaxColorListSelection();
1895                 handleAppearanceColorListSelection();
1896                 // handleAnnotationListSelection();
1897                 // handleContentAssistColorListSelection();
1898                 // fJavaEditorHoverConfigurationBlock.performDefaults();
1899                 fFoldingConfigurationBlock.performDefaults();
1900                 super.performDefaults();
1901                 fPreviewViewer.invalidateTextPresentation();
1902         }
1903
1904         /*
1905          * @see DialogPage#dispose()
1906          */
1907         public void dispose() {
1908                 fFoldingConfigurationBlock.dispose();
1909
1910                 if (fJavaTextTools != null) {
1911                         fJavaTextTools.dispose();
1912                         fJavaTextTools = null;
1913                 }
1914                 if (fOverlayStore != null) {
1915                         fOverlayStore.stop();
1916                         fOverlayStore = null;
1917                 }
1918                 if (fBackgroundColor != null && !fBackgroundColor.isDisposed())
1919                         fBackgroundColor.dispose();
1920                 super.dispose();
1921         }
1922
1923         private Button addCheckBox(Composite parent, String label, String key,
1924                         int indentation) {
1925                 Button checkBox = new Button(parent, SWT.CHECK);
1926                 checkBox.setText(label);
1927                 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
1928                 gd.horizontalIndent = indentation;
1929                 gd.horizontalSpan = 2;
1930                 checkBox.setLayoutData(gd);
1931                 checkBox.addSelectionListener(fCheckBoxListener);
1932                 fCheckBoxes.put(checkBox, key);
1933                 return checkBox;
1934         }
1935
1936         private Text addTextField(Composite composite, String label, String key,
1937                         int textLimit, int indentation, boolean isNumber) {
1938                 return getTextControl(addLabelledTextField(composite, label, key,
1939                                 textLimit, indentation, isNumber));
1940         }
1941
1942         private static Label getLabelControl(Control[] labelledTextField) {
1943                 return (Label) labelledTextField[0];
1944         }
1945
1946         private static Text getTextControl(Control[] labelledTextField) {
1947                 return (Text) labelledTextField[1];
1948         }
1949
1950         /**
1951          * Returns an array of size 2: - first element is of type <code>Label</code>-
1952          * second element is of type <code>Text</code> Use
1953          * <code>getLabelControl</code> and <code>getTextControl</code> to get
1954          * the 2 controls.
1955          */
1956         private Control[] addLabelledTextField(Composite composite, String label,
1957                         String key, int textLimit, int indentation, boolean isNumber) {
1958                 Label labelControl = new Label(composite, SWT.NONE);
1959                 labelControl.setText(label);
1960                 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
1961                 gd.horizontalIndent = indentation;
1962                 labelControl.setLayoutData(gd);
1963                 Text textControl = new Text(composite, SWT.BORDER | SWT.SINGLE);
1964                 gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
1965                 gd.widthHint = convertWidthInCharsToPixels(textLimit + 1);
1966                 textControl.setLayoutData(gd);
1967                 textControl.setTextLimit(textLimit);
1968                 fTextFields.put(textControl, key);
1969                 if (isNumber) {
1970                         fNumberFields.add(textControl);
1971                         textControl.setText("0");
1972                         textControl.addModifyListener(fNumberFieldListener);
1973                 } else {
1974                         textControl.addModifyListener(fTextFieldListener);
1975                 }
1976                 return new Control[] { labelControl, textControl };
1977         }
1978
1979         private String loadPreviewContentFromFile(String filename) {
1980                 String line;
1981                 String separator = System.getProperty("line.separator"); //$NON-NLS-1$
1982                 StringBuffer buffer = new StringBuffer(512);
1983                 BufferedReader reader = null;
1984                 try {
1985                         reader = new BufferedReader(new InputStreamReader(getClass()
1986                                         .getResourceAsStream(filename)));
1987                         while ((line = reader.readLine()) != null) {
1988                                 buffer.append(line);
1989                                 buffer.append(separator);
1990                         }
1991                 } catch (IOException io) {
1992                         PHPeclipsePlugin.log(io);
1993                 } finally {
1994                         if (reader != null) {
1995                                 try {
1996                                         reader.close();
1997                                 } catch (IOException e) {
1998                                 }
1999                         }
2000                 }
2001                 return buffer.toString();
2002         }
2003
2004         private void numberFieldChanged(Text textControl) {
2005                 String number = textControl.getText();
2006                 IStatus status = validatePositiveNumber(number);
2007                 if (!status.matches(IStatus.ERROR))
2008                         fOverlayStore.setValue((String) fTextFields.get(textControl),
2009                                         number);
2010                 updateStatus(status);
2011         }
2012
2013         private IStatus validatePositiveNumber(String number) {
2014                 StatusInfo status = new StatusInfo();
2015                 if (number.length() == 0) {
2016                         status.setError(PreferencesMessages
2017                                         .getString("JavaEditorPreferencePage.empty_input")); //$NON-NLS-1$
2018                 } else {
2019                         try {
2020                                 int value = Integer.parseInt(number);
2021                                 if (value < 0)
2022                                         status.setError(PreferencesMessages.getFormattedString(
2023                                                         "JavaEditorPreferencePage.invalid_input", number)); //$NON-NLS-1$
2024                         } catch (NumberFormatException e) {
2025                                 status.setError(PreferencesMessages.getFormattedString(
2026                                                 "JavaEditorPreferencePage.invalid_input", number)); //$NON-NLS-1$
2027                         }
2028                 }
2029                 return status;
2030         }
2031
2032         void updateStatus(IStatus status) {
2033                 if (!status.matches(IStatus.ERROR)) {
2034                         for (int i = 0; i < fNumberFields.size(); i++) {
2035                                 Text text = (Text) fNumberFields.get(i);
2036                                 IStatus s = validatePositiveNumber(text.getText());
2037                                 status = StatusUtil.getMoreSevere(s, status);
2038                         }
2039                 }
2040                 // status=
2041                 // StatusUtil.getMoreSevere(fJavaEditorHoverConfigurationBlock.getStatus(),
2042                 // status);
2043                 // status=
2044                 // StatusUtil.getMoreSevere(getBrowserLikeLinksKeyModifierStatus(),
2045                 // status);
2046                 setValid(!status.matches(IStatus.ERROR));
2047                 StatusUtil.applyToStatusLine(this, status);
2048         }
2049 }