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