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