KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > preferences > SpellingConfigurationBlock


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.internal.ui.preferences;
13
14 import java.io.File JavaDoc;
15 import java.util.ArrayList JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.List JavaDoc;
18 import java.util.Locale JavaDoc;
19 import java.util.Set JavaDoc;
20
21 import org.eclipse.core.runtime.IStatus;
22
23 import org.eclipse.core.resources.IProject;
24 import org.eclipse.core.resources.ResourcesPlugin;
25
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.events.SelectionAdapter;
28 import org.eclipse.swt.events.SelectionEvent;
29 import org.eclipse.swt.events.SelectionListener;
30 import org.eclipse.swt.layout.GridData;
31 import org.eclipse.swt.layout.GridLayout;
32 import org.eclipse.swt.widgets.Button;
33 import org.eclipse.swt.widgets.Combo;
34 import org.eclipse.swt.widgets.Composite;
35 import org.eclipse.swt.widgets.Control;
36 import org.eclipse.swt.widgets.Event;
37 import org.eclipse.swt.widgets.FileDialog;
38 import org.eclipse.swt.widgets.Group;
39 import org.eclipse.swt.widgets.Label;
40 import org.eclipse.swt.widgets.Text;
41
42 import org.eclipse.jface.dialogs.DialogPage;
43 import org.eclipse.jface.preference.IPreferenceStore;
44 import org.eclipse.jface.preference.PreferenceStore;
45
46 import org.eclipse.ui.PlatformUI;
47 import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
48
49 import org.eclipse.ui.ide.dialogs.EncodingFieldEditor;
50
51 import org.eclipse.jdt.internal.corext.util.Messages;
52
53 import org.eclipse.jdt.ui.PreferenceConstants;
54
55 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
56 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
57 import org.eclipse.jdt.internal.ui.dialogs.StatusUtil;
58 import org.eclipse.jdt.internal.ui.text.spelling.JavaSpellingEngine;
59 import org.eclipse.jdt.internal.ui.text.spelling.SpellCheckEngine;
60 import org.eclipse.jdt.internal.ui.text.spelling.SpellingEngine;
61 import org.eclipse.jdt.internal.ui.util.PixelConverter;
62 import org.eclipse.jdt.internal.ui.util.SWTUtil;
63 import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener;
64
65 /**
66  * Options configuration block for spell check related settings.
67  *
68  * @since 3.0
69  */

70 public class SpellingConfigurationBlock extends OptionsConfigurationBlock {
71
72     /**
73      * Tells whether content assist proposal block should be shown.
74      * Currently the spelling engine cannot return word proposals but
75      * only correction proposals and hence this is disabled.
76      *
77      * @since 3.3
78      */

79     private static final boolean SUPPORT_CONTENT_ASSIST_PROPOSALS= false;
80     
81     
82     /** Preference keys for the preferences in this block */
83     private static final Key PREF_SPELLING_IGNORE_DIGITS= getJDTUIKey(PreferenceConstants.SPELLING_IGNORE_DIGITS);
84     private static final Key PREF_SPELLING_IGNORE_MIXED= getJDTUIKey(PreferenceConstants.SPELLING_IGNORE_MIXED);
85     private static final Key PREF_SPELLING_IGNORE_SENTENCE= getJDTUIKey(PreferenceConstants.SPELLING_IGNORE_SENTENCE);
86     private static final Key PREF_SPELLING_IGNORE_UPPER= getJDTUIKey(PreferenceConstants.SPELLING_IGNORE_UPPER);
87     private static final Key PREF_SPELLING_IGNORE_JAVA_STRINGS= getJDTUIKey(JavaSpellingEngine.SPELLING_IGNORE_JAVA_STRINGS);
88     private static final Key PREF_SPELLING_IGNORE_SINGLE_LETTERS= getJDTUIKey(PreferenceConstants.SPELLING_IGNORE_SINGLE_LETTERS);
89     private static final Key PREF_SPELLING_IGNORE_NON_LETTERS= getJDTUIKey(PreferenceConstants.SPELLING_IGNORE_NON_LETTERS);
90     private static final Key PREF_SPELLING_IGNORE_URLS= getJDTUIKey(PreferenceConstants.SPELLING_IGNORE_URLS);
91     private static final Key PREF_SPELLING_IGNORE_AMPERSAND_IN_PROPERTIES= getJDTUIKey(PreferenceConstants.SPELLING_IGNORE_AMPERSAND_IN_PROPERTIES);
92     private static final Key PREF_SPELLING_LOCALE= getJDTUIKey(PreferenceConstants.SPELLING_LOCALE);
93     private static final Key PREF_SPELLING_PROPOSAL_THRESHOLD= getJDTUIKey(PreferenceConstants.SPELLING_PROPOSAL_THRESHOLD);
94     private static final Key PREF_SPELLING_PROBLEMS_THRESHOLD= getJDTUIKey(SpellingEngine.SPELLING_PROBLEMS_THRESHOLD);
95     private static final Key PREF_SPELLING_USER_DICTIONARY= getJDTUIKey(PreferenceConstants.SPELLING_USER_DICTIONARY);
96     private static final Key PREF_SPELLING_USER_DICTIONARY_ENCODING= getJDTUIKey(PreferenceConstants.SPELLING_USER_DICTIONARY_ENCODING);
97     private static final Key PREF_SPELLING_ENABLE_CONTENTASSIST= getJDTUIKey(PreferenceConstants.SPELLING_ENABLE_CONTENTASSIST);
98
99     /**
100      * The value for no platform dictionary.
101      * @since 3.3
102      */

103     private static final String JavaDoc PREF_VALUE_NO_LOCALE= ""; //$NON-NLS-1$
104

105     
106     /**
107      * Creates a selection dependency between a master and a slave control.
108      *
109      * @param master
110      * The master button that controls the state of the slave
111      * @param slave
112      * The slave control that is enabled only if the master is
113      * selected
114      */

115     protected static void createSelectionDependency(final Button master, final Control slave) {
116
117         master.addSelectionListener(new SelectionListener() {
118
119             public void widgetDefaultSelected(SelectionEvent event) {
120                 // Do nothing
121
}
122
123             public void widgetSelected(SelectionEvent event) {
124                 slave.setEnabled(master.getSelection());
125             }
126         });
127         slave.setEnabled(master.getSelection());
128     }
129
130     /**
131      * Returns the locale codes for the locale list.
132      *
133      * @param locales
134      * The list of locales
135      * @return Array of locale codes for the list
136      */

137     protected static String JavaDoc[] getDictionaryCodes(final Set JavaDoc locales) {
138
139         int index= 0;
140         Locale JavaDoc locale= null;
141
142         final String JavaDoc[] codes= new String JavaDoc[locales.size() + 1];
143         for (final Iterator JavaDoc iterator= locales.iterator(); iterator.hasNext();) {
144             locale= (Locale JavaDoc)iterator.next();
145             codes[index++]= locale.toString();
146         }
147         codes[index++]= PREF_VALUE_NO_LOCALE;
148         return codes;
149     }
150
151     /**
152      * Returns the display labels for the locale list.
153      *
154      * @param locales
155      * The list of locales
156      * @return Array of display labels for the list
157      */

158     protected static String JavaDoc[] getDictionaryLabels(final Set JavaDoc locales) {
159
160         int index= 0;
161         Locale JavaDoc locale= null;
162
163         final String JavaDoc[] labels= new String JavaDoc[locales.size() + 1];
164         for (final Iterator JavaDoc iterator= locales.iterator(); iterator.hasNext();) {
165
166             locale= (Locale JavaDoc)iterator.next();
167             labels[index++]= locale.getDisplayName();
168         }
169         labels[index++]= PreferencesMessages.SpellingPreferencePage_dictionary_none;
170         return labels;
171     }
172
173     /**
174      * Validates that the file with the specified absolute path exists and can
175      * be opened.
176      *
177      * @param path
178      * The path of the file to validate
179      * @return <code>true</code> iff the file exists and can be opened,
180      * <code>false</code> otherwise
181      */

182     protected static IStatus validateAbsoluteFilePath(final String JavaDoc path) {
183
184         final StatusInfo status= new StatusInfo();
185         if (path.length() > 0) {
186
187             final File JavaDoc file= new File JavaDoc(path);
188             if (!file.exists() && (!file.isAbsolute() || !file.getParentFile().canWrite()))
189                 status.setError(PreferencesMessages.SpellingPreferencePage_dictionary_error);
190             else if (file.exists() && (!file.isFile() || !file.isAbsolute() || !file.canRead() || !file.canWrite()))
191                 status.setError(PreferencesMessages.SpellingPreferencePage_dictionary_error);
192
193         }
194         return status;
195     }
196
197     /**
198      * Validates that the specified locale is available.
199      *
200      * @param localeString the locale to validate
201      * @return The status of the validation
202      */

203     private static IStatus validateLocale(final String JavaDoc localeString) {
204         if (PREF_VALUE_NO_LOCALE.equals(localeString))
205             return new StatusInfo();
206
207         Locale JavaDoc locale= SpellCheckEngine.convertToLocale(localeString);
208         
209         if (SpellCheckEngine.findClosestLocale(locale) != null)
210             return new StatusInfo();
211         
212         return new StatusInfo(IStatus.ERROR, PreferencesMessages.SpellingPreferencePage_locale_error);
213     }
214     
215     /**
216      * Validates that the specified number is positive.
217      *
218      * @param number the number to validate
219      * @return The status of the validation
220      */

221     protected static IStatus validatePositiveNumber(final String JavaDoc number) {
222         final StatusInfo status= new StatusInfo();
223         if (number.length() == 0) {
224             status.setError(PreferencesMessages.SpellingPreferencePage_empty_threshold);
225         } else {
226             try {
227                 final int value= Integer.parseInt(number);
228                 if (value < 0) {
229                     status.setError(Messages.format(PreferencesMessages.SpellingPreferencePage_invalid_threshold, number));
230                 }
231             } catch (NumberFormatException JavaDoc exception) {
232                 status.setError(Messages.format(PreferencesMessages.SpellingPreferencePage_invalid_threshold, number));
233             }
234         }
235         return status;
236     }
237
238     /** The dictionary path field */
239     private Text fDictionaryPath= null;
240
241     /** The status for the workspace dictionary file */
242     private IStatus fFileStatus= new StatusInfo();
243
244     /** The status for the proposal threshold */
245     private IStatus fProposalsThresholdStatus= new StatusInfo();
246     
247     /** The status for the problems threshold */
248     private IStatus fProblemsThresholdStatus= new StatusInfo();
249     
250     /** The status for the encoding field editor */
251     private IStatus fEncodingFieldEditorStatus= new StatusInfo();
252     
253     /** The encoding field editor. */
254     private EncodingFieldEditor fEncodingEditor;
255     /** The encoding field editor's parent. */
256     private Composite fEncodingEditorParent;
257
258     /**
259      * All controls
260      * @since 3.1
261      */

262     private Control[] fAllControls;
263     
264     /**
265      * All previously enabled controls
266      * @since 3.1
267      */

268     private Control[] fEnabledControls;
269     
270     /**
271      * Creates a new spelling configuration block.
272      *
273      * @param context the status change listener
274      * @param project the Java project
275      * @param container the preference container
276      */

277     public SpellingConfigurationBlock(final IStatusChangeListener context, final IProject project, IWorkbenchPreferenceContainer container) {
278         super(context, project, getAllKeys(), container);
279
280         IStatus status= validateAbsoluteFilePath(getValue(PREF_SPELLING_USER_DICTIONARY));
281         if (status.getSeverity() != IStatus.OK)
282             setValue(PREF_SPELLING_USER_DICTIONARY, ""); //$NON-NLS-1$
283

284         status= validateLocale(getValue(PREF_SPELLING_LOCALE));
285         if (status.getSeverity() != IStatus.OK)
286             setValue(PREF_SPELLING_LOCALE, SpellCheckEngine.getDefaultLocale().toString());
287     }
288
289     protected Combo addComboBox(Composite parent, String JavaDoc label, Key key, String JavaDoc[] values, String JavaDoc[] valueLabels, int indent) {
290         ControlData data= new ControlData(key, values);
291         
292         GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
293         gd.horizontalIndent= indent;
294                 
295         Label labelControl= new Label(parent, SWT.LEFT | SWT.WRAP);
296         labelControl.setText(label);
297         labelControl.setLayoutData(gd);
298         
299         Combo comboBox= new Combo(parent, SWT.READ_ONLY);
300         comboBox.setItems(valueLabels);
301         comboBox.setData(data);
302         gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
303         gd.horizontalSpan= 2;
304         comboBox.setLayoutData(gd);
305         comboBox.addSelectionListener(getSelectionListener());
306         
307         fLabels.put(comboBox, labelControl);
308         
309         String JavaDoc currValue= getValue(key);
310         
311         Locale JavaDoc locale= SpellCheckEngine.convertToLocale(currValue);
312         locale= SpellCheckEngine.findClosestLocale(locale);
313         if (locale != null)
314             currValue= locale.toString();
315         
316         comboBox.select(data.getSelection(currValue));
317         
318         fComboBoxes.add(comboBox);
319         return comboBox;
320     }
321
322     /*
323      * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#createContents(org.eclipse.swt.widgets.Composite)
324      */

325     protected Control createContents(final Composite parent) {
326
327         Composite composite= new Composite(parent, SWT.NONE);
328         composite.setLayout(new GridLayout());
329
330         List JavaDoc allControls= new ArrayList JavaDoc();
331         final PixelConverter converter= new PixelConverter(parent);
332
333         final String JavaDoc[] trueFalse= new String JavaDoc[] { IPreferenceStore.TRUE, IPreferenceStore.FALSE };
334
335         Group user= new Group(composite, SWT.NONE);
336         user.setText(PreferencesMessages.SpellingPreferencePage_group_user);
337         user.setLayout(new GridLayout());
338         user.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
339         allControls.add(user);
340
341         String JavaDoc label= PreferencesMessages.SpellingPreferencePage_ignore_digits_label;
342         Control slave= addCheckBox(user, label, PREF_SPELLING_IGNORE_DIGITS, trueFalse, 0);
343         allControls.add(slave);
344
345         label= PreferencesMessages.SpellingPreferencePage_ignore_mixed_label;
346         slave= addCheckBox(user, label, PREF_SPELLING_IGNORE_MIXED, trueFalse, 0);
347         allControls.add(slave);
348
349         label= PreferencesMessages.SpellingPreferencePage_ignore_sentence_label;
350         slave= addCheckBox(user, label, PREF_SPELLING_IGNORE_SENTENCE, trueFalse, 0);
351         allControls.add(slave);
352
353         label= PreferencesMessages.SpellingPreferencePage_ignore_upper_label;
354         slave= addCheckBox(user, label, PREF_SPELLING_IGNORE_UPPER, trueFalse, 0);
355         allControls.add(slave);
356
357         label= PreferencesMessages.SpellingPreferencePage_ignore_url_label;
358         slave= addCheckBox(user, label, PREF_SPELLING_IGNORE_URLS, trueFalse, 0);
359         allControls.add(slave);
360         
361         label= PreferencesMessages.SpellingPreferencePage_ignore_non_letters_label;
362         slave= addCheckBox(user, label, PREF_SPELLING_IGNORE_NON_LETTERS, trueFalse, 0);
363         allControls.add(slave);
364         
365         label= PreferencesMessages.SpellingPreferencePage_ignore_single_letters_label;
366         slave= addCheckBox(user, label, PREF_SPELLING_IGNORE_SINGLE_LETTERS, trueFalse, 0);
367         allControls.add(slave);
368         
369         label= PreferencesMessages.SpellingPreferencePage_ignore_java_strings_label;
370         slave= addCheckBox(user, label, PREF_SPELLING_IGNORE_JAVA_STRINGS, trueFalse, 0);
371         allControls.add(slave);
372         
373         label= PreferencesMessages.SpellingPreferencePage_ignore_ampersand_in_properties_label;
374         slave= addCheckBox(user, label, PREF_SPELLING_IGNORE_AMPERSAND_IN_PROPERTIES, trueFalse, 0);
375         allControls.add(slave);
376
377         final Set JavaDoc locales= SpellCheckEngine.getLocalesWithInstalledDictionaries();
378         boolean hasPlaformDictionaries= locales.size() > 0;
379         
380         final Group engine= new Group(composite, SWT.NONE);
381         if (hasPlaformDictionaries)
382             engine.setText(PreferencesMessages.SpellingPreferencePage_group_dictionaries);
383         else
384             engine.setText(PreferencesMessages.SpellingPreferencePage_group_dictionary);
385         engine.setLayout(new GridLayout(4, false));
386         engine.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
387         allControls.add(engine);
388
389         if (hasPlaformDictionaries) {
390             label= PreferencesMessages.SpellingPreferencePage_dictionary_label;
391             Combo combo= addComboBox(engine, label, PREF_SPELLING_LOCALE, getDictionaryCodes(locales), getDictionaryLabels(locales), 0);
392             combo.setEnabled(locales.size() > 0);
393             allControls.add(combo);
394             allControls.add(fLabels.get(combo));
395             
396             new Label(engine, SWT.NONE); // placeholder
397
}
398         
399         label= PreferencesMessages.SpellingPreferencePage_workspace_dictionary_label;
400         fDictionaryPath= addTextField(engine, label, PREF_SPELLING_USER_DICTIONARY, 0, 0);
401         GridData gd= (GridData) fDictionaryPath.getLayoutData();
402         gd.grabExcessHorizontalSpace= true;
403         gd.widthHint= converter.convertWidthInCharsToPixels(40);
404         allControls.add(fDictionaryPath);
405         allControls.add(fLabels.get(fDictionaryPath));
406
407         
408         Button button= new Button(engine, SWT.PUSH);
409         button.setText(PreferencesMessages.SpellingPreferencePage_browse_label);
410         button.addSelectionListener(new SelectionAdapter() {
411
412             public void widgetSelected(final SelectionEvent event) {
413                 handleBrowseButtonSelected();
414             }
415         });
416         button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
417         SWTUtil.setButtonDimensionHint(button);
418         allControls.add(button);
419         
420         // Description for user dictionary
421
new Label(engine, SWT.NONE); // filler
422
Label description= new Label(engine, SWT.NONE);
423         gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
424         gd.horizontalSpan= 3;
425         description.setLayoutData(gd);
426         description.setText(PreferencesMessages.SpellingPreferencePage_user_dictionary_description);
427         allControls.add(description);
428         
429         createEncodingFieldEditor(engine, allControls);
430
431         Group advanced= new Group(composite, SWT.NONE);
432         advanced.setText(PreferencesMessages.SpellingPreferencePage_group_advanced);
433         advanced.setLayout(new GridLayout(3, false));
434         advanced.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
435         allControls.add(advanced);
436
437         label= PreferencesMessages.SpellingPreferencePage_problems_threshold;
438         int digits= 4;
439         Text text= addTextField(advanced, label, PREF_SPELLING_PROBLEMS_THRESHOLD, 0, converter.convertWidthInCharsToPixels(digits+1));
440         text.setTextLimit(digits);
441         allControls.add(text);
442         allControls.add(fLabels.get(text));
443
444         label= PreferencesMessages.SpellingPreferencePage_proposals_threshold;
445         digits= 3;
446         text= addTextField(advanced, label, PREF_SPELLING_PROPOSAL_THRESHOLD, 0, converter.convertWidthInCharsToPixels(digits+1));
447         text.setTextLimit(digits);
448         allControls.add(text);
449         allControls.add(fLabels.get(text));
450
451         if (SUPPORT_CONTENT_ASSIST_PROPOSALS) {
452             label= PreferencesMessages.SpellingPreferencePage_enable_contentassist_label;
453             button= addCheckBox(advanced, label, PREF_SPELLING_ENABLE_CONTENTASSIST, trueFalse, 0);
454             allControls.add(button);
455         }
456
457         fAllControls= (Control[]) allControls.toArray(new Control[allControls.size()]);
458         
459         PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IJavaHelpContextIds.SPELLING_CONFIGURATION_BLOCK);
460         return composite;
461     }
462
463     /**
464      * Creates the encoding field editor.
465      *
466      * @param composite the parent composite
467      * @param allControls list with all controls
468      * @since 3.3
469      */

470     private void createEncodingFieldEditor(Composite composite, List JavaDoc allControls) {
471         Label filler= new Label(composite, SWT.NONE);
472         GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
473         gd.horizontalSpan= 4;
474         filler.setLayoutData(gd);
475         
476         Label label= new Label(composite, SWT.NONE);
477         label.setText(PreferencesMessages.SpellingPreferencePage_encoding_label);
478         label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
479         allControls.add(label);
480         
481         fEncodingEditorParent= new Composite(composite, SWT.NONE);
482         GridLayout layout= new GridLayout(2, false);
483         layout.marginWidth= 0;
484         layout.marginHeight= 0;
485         fEncodingEditorParent.setLayout(layout);
486         gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
487         gd.horizontalSpan= 3;
488         fEncodingEditorParent.setLayoutData(gd);
489         
490         fEncodingEditor= new EncodingFieldEditor(PREF_SPELLING_USER_DICTIONARY_ENCODING.getName(), "", null, fEncodingEditorParent); //$NON-NLS-1$
491

492         PreferenceStore store= new PreferenceStore();
493         String JavaDoc defaultEncoding= ResourcesPlugin.getEncoding();
494         store.setDefault(PREF_SPELLING_USER_DICTIONARY_ENCODING.getName(), defaultEncoding);
495         String JavaDoc encoding= getValue(PREF_SPELLING_USER_DICTIONARY_ENCODING);
496         if (encoding != null && encoding.length() > 0)
497             store.setValue(PREF_SPELLING_USER_DICTIONARY_ENCODING.getName(), encoding);
498
499         fEncodingEditor.setPreferenceStore(store);
500
501         // Redirect status messages from the field editor to the status change listener
502
DialogPage fakePage= new DialogPage() {
503             public void createControl(Composite c) {
504             }
505             public void setErrorMessage(String JavaDoc newMessage) {
506                 StatusInfo status= new StatusInfo();
507                 if (newMessage != null)
508                     status.setError(newMessage);
509                 fEncodingFieldEditorStatus= status;
510                 fContext.statusChanged(StatusUtil.getMostSevere(new IStatus[] { fProblemsThresholdStatus, fProposalsThresholdStatus, fFileStatus, fEncodingFieldEditorStatus }));
511             }
512         };
513         fEncodingEditor.setPage(fakePage);
514         
515         fEncodingEditor.load();
516         
517         if (encoding == null || encoding.equals(defaultEncoding) || encoding.length() == 0)
518             fEncodingEditor.loadDefault();
519         
520     }
521
522     private static Key[] getAllKeys() {
523         if (SUPPORT_CONTENT_ASSIST_PROPOSALS)
524             return new Key[] { PREF_SPELLING_USER_DICTIONARY, PREF_SPELLING_USER_DICTIONARY_ENCODING, PREF_SPELLING_IGNORE_DIGITS, PREF_SPELLING_IGNORE_MIXED, PREF_SPELLING_IGNORE_SENTENCE, PREF_SPELLING_IGNORE_UPPER, PREF_SPELLING_IGNORE_URLS, PREF_SPELLING_IGNORE_AMPERSAND_IN_PROPERTIES, PREF_SPELLING_IGNORE_NON_LETTERS, PREF_SPELLING_IGNORE_SINGLE_LETTERS, PREF_SPELLING_LOCALE, PREF_SPELLING_PROPOSAL_THRESHOLD, PREF_SPELLING_PROBLEMS_THRESHOLD, PREF_SPELLING_ENABLE_CONTENTASSIST, PREF_SPELLING_IGNORE_JAVA_STRINGS };
525         else
526             return new Key[] { PREF_SPELLING_USER_DICTIONARY, PREF_SPELLING_USER_DICTIONARY_ENCODING, PREF_SPELLING_IGNORE_DIGITS, PREF_SPELLING_IGNORE_MIXED, PREF_SPELLING_IGNORE_SENTENCE, PREF_SPELLING_IGNORE_UPPER, PREF_SPELLING_IGNORE_URLS, PREF_SPELLING_IGNORE_AMPERSAND_IN_PROPERTIES, PREF_SPELLING_IGNORE_NON_LETTERS, PREF_SPELLING_IGNORE_SINGLE_LETTERS, PREF_SPELLING_LOCALE, PREF_SPELLING_PROPOSAL_THRESHOLD, PREF_SPELLING_PROBLEMS_THRESHOLD, PREF_SPELLING_IGNORE_JAVA_STRINGS };
527     }
528
529     /*
530      * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#getFullBuildDialogStrings(boolean)
531      */

532     protected final String JavaDoc[] getFullBuildDialogStrings(final boolean workspace) {
533         return null;
534     }
535     
536     /*
537      * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#performOk()
538      * @since 3.3
539      */

540     public boolean performOk() {
541         fEncodingEditor.store();
542         if (fEncodingEditor.presentsDefaultValue())
543             setValue(PREF_SPELLING_USER_DICTIONARY_ENCODING, ""); //$NON-NLS-1$
544
else
545             setValue(PREF_SPELLING_USER_DICTIONARY_ENCODING, fEncodingEditor.getPreferenceStore().getString(PREF_SPELLING_USER_DICTIONARY_ENCODING.getName()));
546         return super.performOk();
547     }
548     
549     /*
550      * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#performApply()
551      * @since 3.3
552      */

553     public boolean performApply() {
554         fEncodingEditor.store();
555         if (fEncodingEditor.presentsDefaultValue())
556             setValue(PREF_SPELLING_USER_DICTIONARY_ENCODING, ""); //$NON-NLS-1$
557
else
558             setValue(PREF_SPELLING_USER_DICTIONARY_ENCODING, fEncodingEditor.getPreferenceStore().getString(PREF_SPELLING_USER_DICTIONARY_ENCODING.getName()));
559         return super.performApply();
560     }
561
562     /*
563      * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#performDefaults()
564      * @since 3.3
565      */

566     public void performDefaults() {
567         super.performDefaults();
568         
569         setValue(PREF_SPELLING_USER_DICTIONARY_ENCODING, ""); //$NON-NLS-1$
570

571         fEncodingEditor.getPreferenceStore().setValue(fEncodingEditor.getPreferenceName(), ResourcesPlugin.getEncoding());
572         fEncodingEditor.load();
573         
574         fEncodingEditor.loadDefault();
575     }
576
577     /**
578      * Handles selections of the browse button.
579      */

580     protected void handleBrowseButtonSelected() {
581         final FileDialog dialog= new FileDialog(fDictionaryPath.getShell(), SWT.OPEN);
582         dialog.setText(PreferencesMessages.SpellingPreferencePage_filedialog_title);
583         dialog.setFilterPath(fDictionaryPath.getText());
584
585         final String JavaDoc path= dialog.open();
586         if (path != null)
587             fDictionaryPath.setText(path);
588     }
589
590     /*
591      * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#validateSettings(java.lang.String,java.lang.String)
592      */

593     protected void validateSettings(final Key key, final String JavaDoc oldValue, final String JavaDoc newValue) {
594         if (key == null || PREF_SPELLING_PROPOSAL_THRESHOLD.equals(key))
595             fProposalsThresholdStatus= validatePositiveNumber(getValue(PREF_SPELLING_PROPOSAL_THRESHOLD));
596         
597         if (key == null || PREF_SPELLING_PROBLEMS_THRESHOLD.equals(key))
598             fProblemsThresholdStatus= validatePositiveNumber(getValue(PREF_SPELLING_PROBLEMS_THRESHOLD));
599
600         if (key == null || PREF_SPELLING_USER_DICTIONARY.equals(key))
601             fFileStatus= validateAbsoluteFilePath(getValue(PREF_SPELLING_USER_DICTIONARY));
602
603         fContext.statusChanged(StatusUtil.getMostSevere(new IStatus[] { fProblemsThresholdStatus, fProposalsThresholdStatus, fFileStatus, fEncodingFieldEditorStatus }));
604     }
605     
606     /*
607      * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#updateCheckBox(org.eclipse.swt.widgets.Button)
608      * @since 3.1
609      */

610     protected void updateCheckBox(Button curr) {
611         super.updateCheckBox(curr);
612         Event event= new Event();
613         event.type= SWT.Selection;
614         event.display= curr.getDisplay();
615         event.widget= curr;
616         curr.notifyListeners(SWT.Selection, event);
617     }
618     
619     /**
620      * Sets the enabled state.
621      *
622      * @param enabled the new state
623      * @since 3.1
624      */

625     protected void setEnabled(boolean enabled) {
626         fEncodingEditor.setEnabled(enabled, fEncodingEditorParent);
627         
628         if (enabled && fEnabledControls != null) {
629             for (int i= fEnabledControls.length - 1; i >= 0; i--)
630                 fEnabledControls[i].setEnabled(true);
631             fEnabledControls= null;
632         }
633         if (!enabled && fEnabledControls == null) {
634             List JavaDoc enabledControls= new ArrayList JavaDoc();
635             for (int i= fAllControls.length - 1; i >= 0; i--) {
636                 Control control= fAllControls[i];
637                 if (control.isEnabled()) {
638                     enabledControls.add(control);
639                     control.setEnabled(false);
640                 }
641             }
642             fEnabledControls= (Control[]) enabledControls.toArray(new Control[enabledControls.size()]);
643         }
644     }
645     
646     
647 }
648
Popular Tags