Modified: 1596135 - debugger: open browser when debugging starts
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / preferences / CodeAssistConfigurationBlock.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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
12 package net.sourceforge.phpdt.internal.ui.preferences;
13
14 import java.util.ArrayList;
15 import java.util.HashMap;
16 import java.util.Iterator;
17 import java.util.Map;
18
19 import net.sourceforge.phpdt.internal.ui.dialogs.StatusInfo;
20 import net.sourceforge.phpdt.internal.ui.dialogs.StatusUtil;
21 import net.sourceforge.phpdt.internal.ui.util.PixelConverter;
22 import net.sourceforge.phpdt.ui.PreferenceConstants;
23
24 import org.eclipse.core.runtime.IStatus;
25 import org.eclipse.jface.preference.PreferenceConverter;
26 import org.eclipse.jface.preference.PreferencePage;
27 import org.eclipse.jface.text.Assert;
28 import org.eclipse.swt.SWT;
29 import org.eclipse.swt.events.ModifyEvent;
30 import org.eclipse.swt.events.ModifyListener;
31 import org.eclipse.swt.events.SelectionAdapter;
32 import org.eclipse.swt.events.SelectionEvent;
33 import org.eclipse.swt.events.SelectionListener;
34 import org.eclipse.swt.graphics.RGB;
35 import org.eclipse.swt.layout.GridData;
36 import org.eclipse.swt.layout.GridLayout;
37 import org.eclipse.swt.widgets.Button;
38 import org.eclipse.swt.widgets.Composite;
39 import org.eclipse.swt.widgets.Control;
40 import org.eclipse.swt.widgets.Label;
41 import org.eclipse.swt.widgets.List;
42 import org.eclipse.swt.widgets.Text;
43
44 /**
45  * Configures the code assist preferences.
46  * 
47  * @since 3.0
48  */
49 class CodeAssistConfigurationBlock implements IPreferenceConfigurationBlock {
50
51         private OverlayPreferenceStore fStore;
52
53         private PreferencePage fMainPreferencePage;
54
55         private List fContentAssistColorList;
56
57         private ColorEditor fContentAssistColorEditor;
58
59         private Control fAutoInsertDelayText;
60
61         private Control fAutoInsertJavaTriggerText;
62
63         private Control fAutoInsertJavaDocTriggerText;
64
65         private Control fAutoInsertHTMLTriggerText;
66
67         private Label fAutoInsertDelayLabel;
68
69         private Label fAutoInsertJavaTriggerLabel;
70
71         private Label fAutoInsertJavaDocTriggerLabel;
72
73         private Label fAutoInsertHTMLTriggerLabel;
74
75         // private Button fCompletionInsertsRadioButton;
76         // private Button fCompletionOverwritesRadioButton;
77         /**
78          * List of master/slave listeners when there's a dependency.
79          * 
80          * @see #createDependency(Button, String, Control)
81          * @since 3.0
82          */
83         private ArrayList fMasterSlaveListeners = new ArrayList();
84
85         private final String[][] fContentAssistColorListModel = new String[][] {
86                         {
87                                         PreferencesMessages
88                                                         .getString("JavaEditorPreferencePage.backgroundForCompletionProposals"), PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND }, //$NON-NLS-1$
89                         {
90                                         PreferencesMessages
91                                                         .getString("JavaEditorPreferencePage.foregroundForCompletionProposals"), PreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND }, //$NON-NLS-1$
92                         // {PreferencesMessages.getString("JavaEditorPreferencePage.backgroundForMethodParameters"),
93                         // PreferenceConstants.CODEASSIST_PARAMETERS_BACKGROUND },
94                         // //$NON-NLS-1$
95                         // {PreferencesMessages.getString("JavaEditorPreferencePage.foregroundForMethodParameters"),
96                         // PreferenceConstants.CODEASSIST_PARAMETERS_FOREGROUND },
97                         // //$NON-NLS-1$
98                         // {PreferencesMessages.getString("JavaEditorPreferencePage.backgroundForCompletionReplacement"),
99                         // PreferenceConstants.CODEASSIST_REPLACEMENT_BACKGROUND },
100                         // //$NON-NLS-1$
101                         // {PreferencesMessages.getString("JavaEditorPreferencePage.foregroundForCompletionReplacement"),
102                         // PreferenceConstants.CODEASSIST_REPLACEMENT_FOREGROUND }
103                         // //$NON-NLS-1$
104         };
105
106         private Map fCheckBoxes = new HashMap();
107
108         private SelectionListener fCheckBoxListener = new SelectionListener() {
109                 public void widgetDefaultSelected(SelectionEvent e) {
110                 }
111
112                 public void widgetSelected(SelectionEvent e) {
113                         Button button = (Button) e.widget;
114                         fStore.setValue((String) fCheckBoxes.get(button), button
115                                         .getSelection());
116                 }
117         };
118
119         private Map fTextFields = new HashMap();
120
121         private ModifyListener fTextFieldListener = new ModifyListener() {
122                 public void modifyText(ModifyEvent e) {
123                         Text text = (Text) e.widget;
124                         fStore.setValue((String) fTextFields.get(text), text.getText());
125                 }
126         };
127
128         private ArrayList fNumberFields = new ArrayList();
129
130         private ModifyListener fNumberFieldListener = new ModifyListener() {
131                 public void modifyText(ModifyEvent e) {
132                         numberFieldChanged((Text) e.widget);
133                 }
134         };
135
136         public CodeAssistConfigurationBlock(PreferencePage mainPreferencePage,
137                         OverlayPreferenceStore store) {
138                 Assert.isNotNull(mainPreferencePage);
139                 Assert.isNotNull(store);
140                 fStore = store;
141                 fStore.addKeys(createOverlayStoreKeys());
142                 fMainPreferencePage = mainPreferencePage;
143         }
144
145         private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys() {
146
147                 ArrayList overlayKeys = new ArrayList();
148
149                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
150                                 OverlayPreferenceStore.BOOLEAN,
151                                 PreferenceConstants.CODEASSIST_AUTOACTIVATION));
152                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
153                                 OverlayPreferenceStore.INT,
154                                 PreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY));
155                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
156                                 OverlayPreferenceStore.BOOLEAN,
157                                 PreferenceConstants.CODEASSIST_AUTOINSERT));
158                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
159                                 OverlayPreferenceStore.STRING,
160                                 PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND));
161                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
162                                 OverlayPreferenceStore.STRING,
163                                 PreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND));
164                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
165                                 OverlayPreferenceStore.STRING,
166                                 PreferenceConstants.CODEASSIST_PARAMETERS_BACKGROUND));
167                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
168                                 OverlayPreferenceStore.STRING,
169                                 PreferenceConstants.CODEASSIST_PARAMETERS_FOREGROUND));
170                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
171                                 OverlayPreferenceStore.STRING,
172                                 PreferenceConstants.CODEASSIST_REPLACEMENT_BACKGROUND));
173                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
174                                 OverlayPreferenceStore.STRING,
175                                 PreferenceConstants.CODEASSIST_REPLACEMENT_FOREGROUND));
176                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
177                                 OverlayPreferenceStore.STRING,
178                                 PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA));
179                 overlayKeys
180                                 .add(new OverlayPreferenceStore.OverlayKey(
181                                                 OverlayPreferenceStore.STRING,
182                                                 PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVADOC));
183                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
184                                 OverlayPreferenceStore.STRING,
185                                 PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_HTML));
186                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
187                                 OverlayPreferenceStore.BOOLEAN,
188                                 PreferenceConstants.CODEASSIST_SHOW_VISIBLE_PROPOSALS));
189                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
190                                 OverlayPreferenceStore.BOOLEAN,
191                                 PreferenceConstants.CODEASSIST_ORDER_PROPOSALS));
192                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
193                                 OverlayPreferenceStore.BOOLEAN,
194                                 PreferenceConstants.CODEASSIST_CASE_SENSITIVITY));
195                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
196                                 OverlayPreferenceStore.BOOLEAN,
197                                 PreferenceConstants.CODEASSIST_ADDIMPORT));
198                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
199                                 OverlayPreferenceStore.BOOLEAN,
200                                 PreferenceConstants.CODEASSIST_INSERT_COMPLETION));
201                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
202                                 OverlayPreferenceStore.BOOLEAN,
203                                 PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES));
204                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
205                                 OverlayPreferenceStore.BOOLEAN,
206                                 PreferenceConstants.CODEASSIST_GUESS_METHOD_ARGUMENTS));
207                 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
208                                 OverlayPreferenceStore.BOOLEAN,
209                                 PreferenceConstants.CODEASSIST_PREFIX_COMPLETION));
210
211                 OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys
212                                 .size()];
213                 overlayKeys.toArray(keys);
214                 return keys;
215         }
216
217         /**
218          * Creates page for hover preferences.
219          * 
220          * @param parent
221          *            the parent composite
222          * @return the control for the preference page
223          */
224         public Control createControl(Composite parent) {
225
226                 PixelConverter pixelConverter = new PixelConverter(parent);
227
228                 Composite contentAssistComposite = new Composite(parent, SWT.NONE);
229                 contentAssistComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
230                 GridLayout layout = new GridLayout();
231                 layout.numColumns = 2;
232                 contentAssistComposite.setLayout(layout);
233
234                 // addCompletionRadioButtons(contentAssistComposite);
235
236                 String label;
237                 // label=
238                 // PreferencesMessages.getString("JavaEditorPreferencePage.insertSingleProposalsAutomatically");
239                 // //$NON-NLS-1$
240                 // addCheckBox(contentAssistComposite, label,
241                 // PreferenceConstants.CODEASSIST_AUTOINSERT, 0);
242                 //              
243                 // label=
244                 // PreferencesMessages.getString("JavaEditorPreferencePage.completePrefixes");
245                 // //$NON-NLS-1$
246                 // addCheckBox(contentAssistComposite, label,
247                 // PreferenceConstants.CODEASSIST_PREFIX_COMPLETION, 0);
248                 //              
249                 // label=
250                 // PreferencesMessages.getString("JavaEditorPreferencePage.showOnlyProposalsVisibleInTheInvocationContext");
251                 // //$NON-NLS-1$
252                 // addCheckBox(contentAssistComposite, label,
253                 // PreferenceConstants.CODEASSIST_SHOW_VISIBLE_PROPOSALS, 0);
254                 //              
255                 // label=
256                 // PreferencesMessages.getString("JavaEditorPreferencePage.presentProposalsInAlphabeticalOrder");
257                 // //$NON-NLS-1$
258                 // addCheckBox(contentAssistComposite, label,
259                 // PreferenceConstants.CODEASSIST_ORDER_PROPOSALS, 0);
260                 //              
261                 // label=
262                 // PreferencesMessages.getString("JavaEditorPreferencePage.automaticallyAddImportInsteadOfQualifiedName");
263                 // //$NON-NLS-1$
264                 // addCheckBox(contentAssistComposite, label,
265                 // PreferenceConstants.CODEASSIST_ADDIMPORT, 0);
266                 //              
267                 // label=
268                 // PreferencesMessages.getString("JavaEditorPreferencePage.fillArgumentNamesOnMethodCompletion");
269                 // //$NON-NLS-1$
270                 // Button master= addCheckBox(contentAssistComposite, label,
271                 // PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES, 0);
272                 //              
273                 // label=
274                 // PreferencesMessages.getString("JavaEditorPreferencePage.guessArgumentNamesOnMethodCompletion");
275                 // //$NON-NLS-1$
276                 // Button slave= addCheckBox(contentAssistComposite, label,
277                 // PreferenceConstants.CODEASSIST_GUESS_METHOD_ARGUMENTS, 0);
278                 // createDependency(master,
279                 // PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES, slave);
280                 //              
281                 label = PreferencesMessages
282                                 .getString("JavaEditorPreferencePage.enableAutoActivation"); //$NON-NLS-1$
283                 final Button autoactivation = addCheckBox(contentAssistComposite,
284                                 label, PreferenceConstants.CODEASSIST_AUTOACTIVATION, 0);
285                 autoactivation.addSelectionListener(new SelectionAdapter() {
286                         public void widgetSelected(SelectionEvent e) {
287                                 updateAutoactivationControls();
288                         }
289                 });
290
291                 Control[] labelledTextField;
292                 label = PreferencesMessages
293                                 .getString("JavaEditorPreferencePage.autoActivationDelay"); //$NON-NLS-1$
294                 labelledTextField = addLabelledTextField(contentAssistComposite, label,
295                                 PreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY, 4, 0, true);
296                 fAutoInsertDelayLabel = getLabelControl(labelledTextField);
297                 fAutoInsertDelayText = getTextControl(labelledTextField);
298
299                 label = PreferencesMessages
300                                 .getString("JavaEditorPreferencePage.autoActivationTriggersForJava"); //$NON-NLS-1$
301                 labelledTextField = addLabelledTextField(contentAssistComposite, label,
302                                 PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA, 4,
303                                 0, false);
304                 fAutoInsertJavaTriggerLabel = getLabelControl(labelledTextField);
305                 fAutoInsertJavaTriggerText = getTextControl(labelledTextField);
306
307                 label = PreferencesMessages
308                                 .getString("JavaEditorPreferencePage.autoActivationTriggersForJavaDoc"); //$NON-NLS-1$
309                 labelledTextField = addLabelledTextField(contentAssistComposite, label,
310                                 PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVADOC,
311                                 4, 0, false);
312                 fAutoInsertJavaDocTriggerLabel = getLabelControl(labelledTextField);
313                 fAutoInsertJavaDocTriggerText = getTextControl(labelledTextField);
314
315                 label = PreferencesMessages
316                                 .getString("JavaEditorPreferencePage.autoActivationTriggersForHTML"); //$NON-NLS-1$
317                 labelledTextField = addLabelledTextField(contentAssistComposite, label,
318                                 PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_HTML, 4,
319                                 0, false);
320                 fAutoInsertHTMLTriggerLabel = getLabelControl(labelledTextField);
321                 fAutoInsertHTMLTriggerText = getTextControl(labelledTextField);
322
323                 Label l = new Label(contentAssistComposite, SWT.LEFT);
324                 l.setText(PreferencesMessages
325                                 .getString("JavaEditorPreferencePage.codeAssist.colorOptions")); //$NON-NLS-1$
326                 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
327                 gd.horizontalSpan = 2;
328                 l.setLayoutData(gd);
329
330                 Composite editorComposite = new Composite(contentAssistComposite,
331                                 SWT.NONE);
332                 layout = new GridLayout();
333                 layout.numColumns = 2;
334                 layout.marginHeight = 0;
335                 layout.marginWidth = 0;
336                 editorComposite.setLayout(layout);
337                 gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL
338                                 | GridData.FILL_VERTICAL);
339                 gd.horizontalSpan = 2;
340                 editorComposite.setLayoutData(gd);
341
342                 fContentAssistColorList = new List(editorComposite, SWT.SINGLE
343                                 | SWT.V_SCROLL | SWT.BORDER);
344                 gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING
345                                 | GridData.FILL_HORIZONTAL);
346                 gd.heightHint = pixelConverter.convertHeightInCharsToPixels(8);
347                 fContentAssistColorList.setLayoutData(gd);
348
349                 Composite stylesComposite = new Composite(editorComposite, SWT.NONE);
350                 layout = new GridLayout();
351                 layout.marginHeight = 0;
352                 layout.marginWidth = 0;
353                 layout.numColumns = 2;
354                 stylesComposite.setLayout(layout);
355                 stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
356
357                 l = new Label(stylesComposite, SWT.LEFT);
358                 l.setText(PreferencesMessages
359                                 .getString("JavaEditorPreferencePage.codeAssist.color")); //$NON-NLS-1$
360                 gd = new GridData();
361                 gd.horizontalAlignment = GridData.BEGINNING;
362                 l.setLayoutData(gd);
363
364                 fContentAssistColorEditor = new ColorEditor(stylesComposite);
365                 Button colorButton = fContentAssistColorEditor.getButton();
366                 gd = new GridData(GridData.FILL_HORIZONTAL);
367                 gd.horizontalAlignment = GridData.BEGINNING;
368                 colorButton.setLayoutData(gd);
369
370                 fContentAssistColorList.addSelectionListener(new SelectionListener() {
371                         public void widgetDefaultSelected(SelectionEvent e) {
372                                 // do nothing
373                         }
374
375                         public void widgetSelected(SelectionEvent e) {
376                                 handleContentAssistColorListSelection();
377                         }
378                 });
379                 colorButton.addSelectionListener(new SelectionListener() {
380                         public void widgetDefaultSelected(SelectionEvent e) {
381                                 // do nothing
382                         }
383
384                         public void widgetSelected(SelectionEvent e) {
385                                 int i = fContentAssistColorList.getSelectionIndex();
386                                 String key = fContentAssistColorListModel[i][1];
387
388                                 PreferenceConverter.setValue(fStore, key,
389                                                 fContentAssistColorEditor.getColorValue());
390                         }
391                 });
392
393                 return contentAssistComposite;
394         }
395
396         private void createDependency(final Button master, String masterKey,
397                         final Control slave) {
398                 indent(slave);
399                 boolean masterState = fStore.getBoolean(masterKey);
400                 slave.setEnabled(masterState);
401                 SelectionListener listener = new SelectionListener() {
402                         public void widgetSelected(SelectionEvent e) {
403                                 slave.setEnabled(master.getSelection());
404                         }
405
406                         public void widgetDefaultSelected(SelectionEvent e) {
407                         }
408                 };
409                 master.addSelectionListener(listener);
410                 fMasterSlaveListeners.add(listener);
411         }
412
413         private static void indent(Control control) {
414                 GridData gridData = new GridData();
415                 gridData.horizontalIndent = 20;
416                 control.setLayoutData(gridData);
417         }
418
419         private static Text getTextControl(Control[] labelledTextField) {
420                 return (Text) labelledTextField[1];
421         }
422
423         private static Label getLabelControl(Control[] labelledTextField) {
424                 return (Label) labelledTextField[0];
425         }
426
427         /**
428          * Returns an array of size 2: - first element is of type <code>Label</code> -
429          * second element is of type <code>Text</code> Use
430          * <code>getLabelControl</code> and <code>getTextControl</code> to get
431          * the 2 controls.
432          * 
433          * @param composite
434          *            the parent composite
435          * @param label
436          *            the text field's label
437          * @param key
438          *            the preference key
439          * @param textLimit
440          *            the text limit
441          * @param indentation
442          *            the field's indentation
443          * @param isNumber
444          *            <code>true</code> iff this text field is used to e4dit a
445          *            number
446          * @return
447          */
448         private Control[] addLabelledTextField(Composite composite, String label,
449                         String key, int textLimit, int indentation, boolean isNumber) {
450
451                 PixelConverter pixelConverter = new PixelConverter(composite);
452
453                 Label labelControl = new Label(composite, SWT.NONE);
454                 labelControl.setText(label);
455                 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
456                 gd.horizontalIndent = indentation;
457                 labelControl.setLayoutData(gd);
458
459                 Text textControl = new Text(composite, SWT.BORDER | SWT.SINGLE);
460                 gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
461                 gd.widthHint = pixelConverter
462                                 .convertWidthInCharsToPixels(textLimit + 1);
463                 textControl.setLayoutData(gd);
464                 textControl.setTextLimit(textLimit);
465                 fTextFields.put(textControl, key);
466                 if (isNumber) {
467                         fNumberFields.add(textControl);
468                         textControl.addModifyListener(fNumberFieldListener);
469                 } else {
470                         textControl.addModifyListener(fTextFieldListener);
471                 }
472
473                 return new Control[] { labelControl, textControl };
474         }
475
476         private void addCompletionRadioButtons(Composite contentAssistComposite) {
477                 Composite completionComposite = new Composite(contentAssistComposite,
478                                 SWT.NONE);
479                 GridData ccgd = new GridData();
480                 ccgd.horizontalSpan = 2;
481                 completionComposite.setLayoutData(ccgd);
482                 GridLayout ccgl = new GridLayout();
483                 ccgl.marginWidth = 0;
484                 ccgl.numColumns = 2;
485                 completionComposite.setLayout(ccgl);
486
487                 // SelectionListener completionSelectionListener= new SelectionAdapter()
488                 // {
489                 // public void widgetSelected(SelectionEvent e) {
490                 // boolean insert= fCompletionInsertsRadioButton.getSelection();
491                 // fStore.setValue(PreferenceConstants.CODEASSIST_INSERT_COMPLETION,
492                 // insert);
493                 // }
494                 // };
495                 //              
496                 // fCompletionInsertsRadioButton= new Button(completionComposite,
497                 // SWT.RADIO | SWT.LEFT);
498                 // fCompletionInsertsRadioButton.setText(PreferencesMessages.getString("JavaEditorPreferencePage.completionInserts"));
499                 // //$NON-NLS-1$
500                 // fCompletionInsertsRadioButton.setLayoutData(new GridData());
501                 // fCompletionInsertsRadioButton.addSelectionListener(completionSelectionListener);
502                 //              
503                 // fCompletionOverwritesRadioButton= new Button(completionComposite,
504                 // SWT.RADIO | SWT.LEFT);
505                 // fCompletionOverwritesRadioButton.setText(PreferencesMessages.getString("JavaEditorPreferencePage.completionOverwrites"));
506                 // //$NON-NLS-1$
507                 // fCompletionOverwritesRadioButton.setLayoutData(new GridData());
508                 // fCompletionOverwritesRadioButton.addSelectionListener(completionSelectionListener);
509         }
510
511         public void initialize() {
512                 initializeFields();
513
514                 for (int i = 0; i < fContentAssistColorListModel.length; i++)
515                         fContentAssistColorList.add(fContentAssistColorListModel[i][0]);
516                 fContentAssistColorList.getDisplay().asyncExec(new Runnable() {
517                         public void run() {
518                                 if (fContentAssistColorList != null
519                                                 && !fContentAssistColorList.isDisposed()) {
520                                         fContentAssistColorList.select(0);
521                                         handleContentAssistColorListSelection();
522                                 }
523                         }
524                 });
525
526         }
527
528         void initializeFields() {
529                 Iterator e = fCheckBoxes.keySet().iterator();
530                 while (e.hasNext()) {
531                         Button b = (Button) e.next();
532                         String key = (String) fCheckBoxes.get(b);
533                         b.setSelection(fStore.getBoolean(key));
534                 }
535
536                 e = fTextFields.keySet().iterator();
537                 while (e.hasNext()) {
538                         Text t = (Text) e.next();
539                         String key = (String) fTextFields.get(t);
540                         t.setText(fStore.getString(key));
541                 }
542
543                 // boolean completionInserts=
544                 // fStore.getBoolean(PreferenceConstants.CODEASSIST_INSERT_COMPLETION);
545                 // fCompletionInsertsRadioButton.setSelection(completionInserts);
546                 // fCompletionOverwritesRadioButton.setSelection(! completionInserts);
547
548                 updateAutoactivationControls();
549
550                 updateStatus(validatePositiveNumber("0")); //$NON-NLS-1$
551
552                 // Update slaves
553                 Iterator iter = fMasterSlaveListeners.iterator();
554                 while (iter.hasNext()) {
555                         SelectionListener listener = (SelectionListener) iter.next();
556                         listener.widgetSelected(null);
557                 }
558         }
559
560         private void updateAutoactivationControls() {
561                 boolean autoactivation = fStore
562                                 .getBoolean(PreferenceConstants.CODEASSIST_AUTOACTIVATION);
563                 fAutoInsertDelayText.setEnabled(autoactivation);
564                 fAutoInsertDelayLabel.setEnabled(autoactivation);
565
566                 fAutoInsertJavaTriggerText.setEnabled(autoactivation);
567                 fAutoInsertJavaTriggerLabel.setEnabled(autoactivation);
568
569                 fAutoInsertJavaDocTriggerText.setEnabled(autoactivation);
570                 fAutoInsertJavaDocTriggerLabel.setEnabled(autoactivation);
571
572                 fAutoInsertHTMLTriggerText.setEnabled(autoactivation);
573                 fAutoInsertHTMLTriggerLabel.setEnabled(autoactivation);
574         }
575
576         public void performOk() {
577         }
578
579         public void performDefaults() {
580                 handleContentAssistColorListSelection();
581                 initializeFields();
582         }
583
584         private void handleContentAssistColorListSelection() {
585                 int i = fContentAssistColorList.getSelectionIndex();
586                 String key = fContentAssistColorListModel[i][1];
587                 RGB rgb = PreferenceConverter.getColor(fStore, key);
588                 fContentAssistColorEditor.setColorValue(rgb);
589         }
590
591         private void numberFieldChanged(Text textControl) {
592                 String number = textControl.getText();
593                 IStatus status = validatePositiveNumber(number);
594                 if (!status.matches(IStatus.ERROR))
595                         fStore.setValue((String) fTextFields.get(textControl), number);
596                 updateStatus(status);
597         }
598
599         private IStatus validatePositiveNumber(String number) {
600                 StatusInfo status = new StatusInfo();
601                 if (number.length() == 0) {
602                         status.setError(PreferencesMessages
603                                         .getString("JavaEditorPreferencePage.empty_input")); //$NON-NLS-1$
604                 } else {
605                         try {
606                                 int value = Integer.parseInt(number);
607                                 if (value < 0)
608                                         status.setError(PreferencesMessages.getFormattedString(
609                                                         "JavaEditorPreferencePage.invalid_input", number)); //$NON-NLS-1$
610                         } catch (NumberFormatException e) {
611                                 status.setError(PreferencesMessages.getFormattedString(
612                                                 "JavaEditorPreferencePage.invalid_input", number)); //$NON-NLS-1$
613                         }
614                 }
615                 return status;
616         }
617
618         private void updateStatus(IStatus status) {
619                 fMainPreferencePage.setValid(status.isOK());
620                 StatusUtil.applyToStatusLine(fMainPreferencePage, status);
621         }
622
623         private Button addCheckBox(Composite parent, String label, String key,
624                         int indentation) {
625                 Button checkBox = new Button(parent, SWT.CHECK);
626                 checkBox.setText(label);
627
628                 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
629                 gd.horizontalIndent = indentation;
630                 gd.horizontalSpan = 2;
631                 checkBox.setLayoutData(gd);
632                 checkBox.addSelectionListener(fCheckBoxListener);
633
634                 fCheckBoxes.put(checkBox, key);
635
636                 return checkBox;
637         }
638
639         /*
640          * @see DialogPage#dispose()
641          */
642         public void dispose() {
643                 // nothing to dispose
644         }
645 }