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