Source Code Cross Referenced for SpellingConfigurationBlock.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » ui » preferences » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » jdt » org.eclipse.jdt.internal.ui.preferences 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2007 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.jdt.internal.ui.preferences;
011:
012:        import java.io.File;
013:        import java.util.ArrayList;
014:        import java.util.Iterator;
015:        import java.util.List;
016:        import java.util.Locale;
017:        import java.util.Set;
018:
019:        import org.eclipse.core.variables.IStringVariableManager;
020:        import org.eclipse.core.variables.VariablesPlugin;
021:
022:        import org.eclipse.core.runtime.CoreException;
023:        import org.eclipse.core.runtime.IStatus;
024:
025:        import org.eclipse.core.resources.IProject;
026:        import org.eclipse.core.resources.ResourcesPlugin;
027:
028:        import org.eclipse.swt.SWT;
029:        import org.eclipse.swt.events.SelectionAdapter;
030:        import org.eclipse.swt.events.SelectionEvent;
031:        import org.eclipse.swt.events.SelectionListener;
032:        import org.eclipse.swt.layout.GridData;
033:        import org.eclipse.swt.layout.GridLayout;
034:        import org.eclipse.swt.widgets.Button;
035:        import org.eclipse.swt.widgets.Combo;
036:        import org.eclipse.swt.widgets.Composite;
037:        import org.eclipse.swt.widgets.Control;
038:        import org.eclipse.swt.widgets.Event;
039:        import org.eclipse.swt.widgets.FileDialog;
040:        import org.eclipse.swt.widgets.Group;
041:        import org.eclipse.swt.widgets.Label;
042:        import org.eclipse.swt.widgets.Text;
043:
044:        import org.eclipse.jface.dialogs.DialogPage;
045:        import org.eclipse.jface.preference.IPreferenceStore;
046:        import org.eclipse.jface.preference.PreferenceStore;
047:        import org.eclipse.jface.window.Window;
048:
049:        import org.eclipse.ui.PlatformUI;
050:        import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
051:
052:        import org.eclipse.ui.ide.dialogs.EncodingFieldEditor;
053:
054:        import org.eclipse.debug.ui.StringVariableSelectionDialog;
055:
056:        import org.eclipse.jdt.internal.corext.util.Messages;
057:
058:        import org.eclipse.jdt.ui.PreferenceConstants;
059:
060:        import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
061:        import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
062:        import org.eclipse.jdt.internal.ui.dialogs.StatusUtil;
063:        import org.eclipse.jdt.internal.ui.text.spelling.SpellCheckEngine;
064:        import org.eclipse.jdt.internal.ui.util.PixelConverter;
065:        import org.eclipse.jdt.internal.ui.util.SWTUtil;
066:        import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener;
067:
068:        /**
069:         * Options configuration block for spell check related settings.
070:         * 
071:         * @since 3.0
072:         */
073:        public class SpellingConfigurationBlock extends
074:                OptionsConfigurationBlock {
075:
076:            /**
077:             * Tells whether content assist proposal block should be shown.
078:             * Currently the spelling engine cannot return word proposals but
079:             * only correction proposals and hence this is disabled.
080:             * 
081:             * @since 3.3
082:             */
083:            private static final boolean SUPPORT_CONTENT_ASSIST_PROPOSALS = false;
084:
085:            /** Preference keys for the preferences in this block */
086:            private static final Key PREF_SPELLING_IGNORE_DIGITS = getJDTUIKey(PreferenceConstants.SPELLING_IGNORE_DIGITS);
087:            private static final Key PREF_SPELLING_IGNORE_MIXED = getJDTUIKey(PreferenceConstants.SPELLING_IGNORE_MIXED);
088:            private static final Key PREF_SPELLING_IGNORE_SENTENCE = getJDTUIKey(PreferenceConstants.SPELLING_IGNORE_SENTENCE);
089:            private static final Key PREF_SPELLING_IGNORE_UPPER = getJDTUIKey(PreferenceConstants.SPELLING_IGNORE_UPPER);
090:            private static final Key PREF_SPELLING_IGNORE_JAVA_STRINGS = getJDTUIKey(PreferenceConstants.SPELLING_IGNORE_JAVA_STRINGS);
091:            private static final Key PREF_SPELLING_IGNORE_SINGLE_LETTERS = getJDTUIKey(PreferenceConstants.SPELLING_IGNORE_SINGLE_LETTERS);
092:            private static final Key PREF_SPELLING_IGNORE_NON_LETTERS = getJDTUIKey(PreferenceConstants.SPELLING_IGNORE_NON_LETTERS);
093:            private static final Key PREF_SPELLING_IGNORE_URLS = getJDTUIKey(PreferenceConstants.SPELLING_IGNORE_URLS);
094:            private static final Key PREF_SPELLING_IGNORE_AMPERSAND_IN_PROPERTIES = getJDTUIKey(PreferenceConstants.SPELLING_IGNORE_AMPERSAND_IN_PROPERTIES);
095:            private static final Key PREF_SPELLING_LOCALE = getJDTUIKey(PreferenceConstants.SPELLING_LOCALE);
096:            private static final Key PREF_SPELLING_PROPOSAL_THRESHOLD = getJDTUIKey(PreferenceConstants.SPELLING_PROPOSAL_THRESHOLD);
097:            private static final Key PREF_SPELLING_PROBLEMS_THRESHOLD = getJDTUIKey(PreferenceConstants.SPELLING_PROBLEMS_THRESHOLD);
098:            private static final Key PREF_SPELLING_USER_DICTIONARY = getJDTUIKey(PreferenceConstants.SPELLING_USER_DICTIONARY);
099:            private static final Key PREF_SPELLING_USER_DICTIONARY_ENCODING = getJDTUIKey(PreferenceConstants.SPELLING_USER_DICTIONARY_ENCODING);
100:            private static final Key PREF_SPELLING_ENABLE_CONTENTASSIST = getJDTUIKey(PreferenceConstants.SPELLING_ENABLE_CONTENTASSIST);
101:
102:            /**
103:             * The value for no platform dictionary.
104:             * @since 3.3
105:             */
106:            private static final String PREF_VALUE_NO_LOCALE = ""; //$NON-NLS-1$
107:
108:            /**
109:             * Creates a selection dependency between a master and a slave control.
110:             * 
111:             * @param master
112:             *                   The master button that controls the state of the slave
113:             * @param slave
114:             *                   The slave control that is enabled only if the master is
115:             *                   selected
116:             */
117:            protected static void createSelectionDependency(
118:                    final Button master, final Control slave) {
119:
120:                master.addSelectionListener(new SelectionListener() {
121:
122:                    public void widgetDefaultSelected(SelectionEvent event) {
123:                        // Do nothing
124:                    }
125:
126:                    public void widgetSelected(SelectionEvent event) {
127:                        slave.setEnabled(master.getSelection());
128:                    }
129:                });
130:                slave.setEnabled(master.getSelection());
131:            }
132:
133:            /**
134:             * Returns the locale codes for the locale list.
135:             * 
136:             * @param locales
137:             *                   The list of locales
138:             * @return Array of locale codes for the list
139:             */
140:            protected static String[] getDictionaryCodes(final Set locales) {
141:
142:                int index = 0;
143:                Locale locale = null;
144:
145:                final String[] codes = new String[locales.size() + 1];
146:                for (final Iterator iterator = locales.iterator(); iterator
147:                        .hasNext();) {
148:                    locale = (Locale) iterator.next();
149:                    codes[index++] = locale.toString();
150:                }
151:                codes[index++] = PREF_VALUE_NO_LOCALE;
152:                return codes;
153:            }
154:
155:            /**
156:             * Returns the display labels for the locale list.
157:             * 
158:             * @param locales
159:             *                   The list of locales
160:             * @return Array of display labels for the list
161:             */
162:            protected static String[] getDictionaryLabels(final Set locales) {
163:
164:                int index = 0;
165:                Locale locale = null;
166:
167:                final String[] labels = new String[locales.size() + 1];
168:                for (final Iterator iterator = locales.iterator(); iterator
169:                        .hasNext();) {
170:
171:                    locale = (Locale) iterator.next();
172:                    labels[index++] = locale.getDisplayName();
173:                }
174:                labels[index++] = PreferencesMessages.SpellingPreferencePage_dictionary_none;
175:                return labels;
176:            }
177:
178:            /**
179:             * Validates that the file with the specified absolute path exists and can
180:             * be opened.
181:             * 
182:             * @param path
183:             *                   The path of the file to validate
184:             * @return a status without error if the path is valid
185:             */
186:            protected static IStatus validateAbsoluteFilePath(String path) {
187:
188:                final StatusInfo status = new StatusInfo();
189:                IStringVariableManager variableManager = VariablesPlugin
190:                        .getDefault().getStringVariableManager();
191:                try {
192:                    path = variableManager.performStringSubstitution(path);
193:                    if (path.length() > 0) {
194:
195:                        final File file = new File(path);
196:                        if (!file.exists()
197:                                && (!file.isAbsolute() || !file.getParentFile()
198:                                        .canWrite()))
199:                            status
200:                                    .setError(PreferencesMessages.SpellingPreferencePage_dictionary_error);
201:                        else if (file.exists()
202:                                && (!file.isFile() || !file.isAbsolute()
203:                                        || !file.canRead() || !file.canWrite()))
204:                            status
205:                                    .setError(PreferencesMessages.SpellingPreferencePage_dictionary_error);
206:                    }
207:                } catch (CoreException e) {
208:                    status.setError(e.getLocalizedMessage());
209:                }
210:                return status;
211:            }
212:
213:            /**
214:             * Validates that the specified locale is available.
215:             * 
216:             * @param localeString the locale to validate
217:             * @return The status of the validation
218:             */
219:            private static IStatus validateLocale(final String localeString) {
220:                if (PREF_VALUE_NO_LOCALE.equals(localeString))
221:                    return new StatusInfo();
222:
223:                Locale locale = SpellCheckEngine.convertToLocale(localeString);
224:
225:                if (SpellCheckEngine.findClosestLocale(locale) != null)
226:                    return new StatusInfo();
227:
228:                return new StatusInfo(IStatus.ERROR,
229:                        PreferencesMessages.SpellingPreferencePage_locale_error);
230:            }
231:
232:            /**
233:             * Validates that the specified number is positive.
234:             * 
235:             * @param number the number to validate
236:             * @return The status of the validation
237:             */
238:            protected static IStatus validatePositiveNumber(final String number) {
239:                final StatusInfo status = new StatusInfo();
240:                if (number.length() == 0) {
241:                    status
242:                            .setError(PreferencesMessages.SpellingPreferencePage_empty_threshold);
243:                } else {
244:                    try {
245:                        final int value = Integer.parseInt(number);
246:                        if (value < 0) {
247:                            status
248:                                    .setError(Messages
249:                                            .format(
250:                                                    PreferencesMessages.SpellingPreferencePage_invalid_threshold,
251:                                                    number));
252:                        }
253:                    } catch (NumberFormatException exception) {
254:                        status
255:                                .setError(Messages
256:                                        .format(
257:                                                PreferencesMessages.SpellingPreferencePage_invalid_threshold,
258:                                                number));
259:                    }
260:                }
261:                return status;
262:            }
263:
264:            /** The dictionary path field */
265:            private Text fDictionaryPath = null;
266:
267:            /** The status for the workspace dictionary file */
268:            private IStatus fFileStatus = new StatusInfo();
269:
270:            /** The status for the proposal threshold */
271:            private IStatus fThresholdStatus = new StatusInfo();
272:
273:            /** The status for the encoding field editor */
274:            private IStatus fEncodingFieldEditorStatus = new StatusInfo();
275:
276:            /** The encoding field editor. */
277:            private EncodingFieldEditor fEncodingEditor;
278:            /** The encoding field editor's parent. */
279:            private Composite fEncodingEditorParent;
280:
281:            /**
282:             * All controls
283:             * @since 3.1
284:             */
285:            private Control[] fAllControls;
286:
287:            /**
288:             * All previously enabled controls
289:             * @since 3.1
290:             */
291:            private Control[] fEnabledControls;
292:
293:            /**
294:             * Creates a new spelling configuration block.
295:             * 
296:             * @param context the status change listener
297:             * @param project the Java project
298:             * @param container the preference container
299:             */
300:            public SpellingConfigurationBlock(
301:                    final IStatusChangeListener context,
302:                    final IProject project,
303:                    IWorkbenchPreferenceContainer container) {
304:                super (context, project, getAllKeys(), container);
305:
306:                IStatus status = validateAbsoluteFilePath(getValue(PREF_SPELLING_USER_DICTIONARY));
307:                if (status.getSeverity() != IStatus.OK)
308:                    setValue(PREF_SPELLING_USER_DICTIONARY, ""); //$NON-NLS-1$
309:
310:                status = validateLocale(getValue(PREF_SPELLING_LOCALE));
311:                if (status.getSeverity() != IStatus.OK)
312:                    setValue(PREF_SPELLING_LOCALE, SpellCheckEngine
313:                            .getDefaultLocale().toString());
314:            }
315:
316:            protected Combo addComboBox(Composite parent, String label,
317:                    Key key, String[] values, String[] valueLabels, int indent) {
318:                ControlData data = new ControlData(key, values);
319:
320:                GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
321:                gd.horizontalIndent = indent;
322:
323:                Label labelControl = new Label(parent, SWT.LEFT | SWT.WRAP);
324:                labelControl.setText(label);
325:                labelControl.setLayoutData(gd);
326:
327:                Combo comboBox = new Combo(parent, SWT.READ_ONLY);
328:                comboBox.setItems(valueLabels);
329:                comboBox.setData(data);
330:                gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
331:                gd.horizontalSpan = 2;
332:                comboBox.setLayoutData(gd);
333:                comboBox.addSelectionListener(getSelectionListener());
334:
335:                fLabels.put(comboBox, labelControl);
336:
337:                String currValue = getValue(key);
338:
339:                Locale locale = SpellCheckEngine.convertToLocale(currValue);
340:                locale = SpellCheckEngine.findClosestLocale(locale);
341:                if (locale != null)
342:                    currValue = locale.toString();
343:
344:                comboBox.select(data.getSelection(currValue));
345:
346:                fComboBoxes.add(comboBox);
347:                return comboBox;
348:            }
349:
350:            /*
351:             * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#createContents(org.eclipse.swt.widgets.Composite)
352:             */
353:            protected Control createContents(final Composite parent) {
354:
355:                Composite composite = new Composite(parent, SWT.NONE);
356:                composite.setLayout(new GridLayout());
357:
358:                List allControls = new ArrayList();
359:                final PixelConverter converter = new PixelConverter(parent);
360:
361:                final String[] trueFalse = new String[] {
362:                        IPreferenceStore.TRUE, IPreferenceStore.FALSE };
363:
364:                Group user = new Group(composite, SWT.NONE);
365:                user
366:                        .setText(PreferencesMessages.SpellingPreferencePage_group_user);
367:                user.setLayout(new GridLayout());
368:                user.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
369:                allControls.add(user);
370:
371:                String label = PreferencesMessages.SpellingPreferencePage_ignore_digits_label;
372:                Control slave = addCheckBox(user, label,
373:                        PREF_SPELLING_IGNORE_DIGITS, trueFalse, 0);
374:                allControls.add(slave);
375:
376:                label = PreferencesMessages.SpellingPreferencePage_ignore_mixed_label;
377:                slave = addCheckBox(user, label, PREF_SPELLING_IGNORE_MIXED,
378:                        trueFalse, 0);
379:                allControls.add(slave);
380:
381:                label = PreferencesMessages.SpellingPreferencePage_ignore_sentence_label;
382:                slave = addCheckBox(user, label, PREF_SPELLING_IGNORE_SENTENCE,
383:                        trueFalse, 0);
384:                allControls.add(slave);
385:
386:                label = PreferencesMessages.SpellingPreferencePage_ignore_upper_label;
387:                slave = addCheckBox(user, label, PREF_SPELLING_IGNORE_UPPER,
388:                        trueFalse, 0);
389:                allControls.add(slave);
390:
391:                label = PreferencesMessages.SpellingPreferencePage_ignore_url_label;
392:                slave = addCheckBox(user, label, PREF_SPELLING_IGNORE_URLS,
393:                        trueFalse, 0);
394:                allControls.add(slave);
395:
396:                label = PreferencesMessages.SpellingPreferencePage_ignore_non_letters_label;
397:                slave = addCheckBox(user, label,
398:                        PREF_SPELLING_IGNORE_NON_LETTERS, trueFalse, 0);
399:                allControls.add(slave);
400:
401:                label = PreferencesMessages.SpellingPreferencePage_ignore_single_letters_label;
402:                slave = addCheckBox(user, label,
403:                        PREF_SPELLING_IGNORE_SINGLE_LETTERS, trueFalse, 0);
404:                allControls.add(slave);
405:
406:                label = PreferencesMessages.SpellingPreferencePage_ignore_java_strings_label;
407:                slave = addCheckBox(user, label,
408:                        PREF_SPELLING_IGNORE_JAVA_STRINGS, trueFalse, 0);
409:                allControls.add(slave);
410:
411:                label = PreferencesMessages.SpellingPreferencePage_ignore_ampersand_in_properties_label;
412:                slave = addCheckBox(user, label,
413:                        PREF_SPELLING_IGNORE_AMPERSAND_IN_PROPERTIES,
414:                        trueFalse, 0);
415:                allControls.add(slave);
416:
417:                final Set locales = SpellCheckEngine
418:                        .getLocalesWithInstalledDictionaries();
419:                boolean hasPlaformDictionaries = locales.size() > 0;
420:
421:                final Group engine = new Group(composite, SWT.NONE);
422:                if (hasPlaformDictionaries)
423:                    engine
424:                            .setText(PreferencesMessages.SpellingPreferencePage_group_dictionaries);
425:                else
426:                    engine
427:                            .setText(PreferencesMessages.SpellingPreferencePage_group_dictionary);
428:                engine.setLayout(new GridLayout(4, false));
429:                engine.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
430:                allControls.add(engine);
431:
432:                if (hasPlaformDictionaries) {
433:                    label = PreferencesMessages.SpellingPreferencePage_dictionary_label;
434:                    Combo combo = addComboBox(engine, label,
435:                            PREF_SPELLING_LOCALE, getDictionaryCodes(locales),
436:                            getDictionaryLabels(locales), 0);
437:                    combo.setEnabled(locales.size() > 0);
438:                    allControls.add(combo);
439:                    allControls.add(fLabels.get(combo));
440:
441:                    new Label(engine, SWT.NONE); // placeholder
442:                }
443:
444:                label = PreferencesMessages.SpellingPreferencePage_workspace_dictionary_label;
445:                fDictionaryPath = addTextField(engine, label,
446:                        PREF_SPELLING_USER_DICTIONARY, 0, 0);
447:                GridData gd = (GridData) fDictionaryPath.getLayoutData();
448:                gd.grabExcessHorizontalSpace = true;
449:                gd.widthHint = converter.convertWidthInCharsToPixels(40);
450:                allControls.add(fDictionaryPath);
451:                allControls.add(fLabels.get(fDictionaryPath));
452:
453:                Composite buttons = new Composite(engine, SWT.NONE);
454:                buttons.setLayout(new GridLayout(2, true));
455:                buttons.setLayoutData(new GridData(
456:                        GridData.HORIZONTAL_ALIGN_END));
457:
458:                Button button = new Button(buttons, SWT.PUSH);
459:                button
460:                        .setText(PreferencesMessages.SpellingPreferencePage_browse_label);
461:                button.addSelectionListener(new SelectionAdapter() {
462:
463:                    public void widgetSelected(final SelectionEvent event) {
464:                        handleBrowseButtonSelected();
465:                    }
466:                });
467:                SWTUtil.setButtonDimensionHint(button);
468:                button.setLayoutData(new GridData(
469:                        GridData.HORIZONTAL_ALIGN_FILL));
470:                allControls.add(button);
471:
472:                button = new Button(buttons, SWT.PUSH);
473:                button
474:                        .setText(PreferencesMessages.SpellingPreferencePage_variables);
475:                button.addSelectionListener(new SelectionAdapter() {
476:
477:                    public void widgetSelected(SelectionEvent e) {
478:                        handleVariablesButtonSelected();
479:                    }
480:
481:                });
482:                SWTUtil.setButtonDimensionHint(button);
483:                button.setLayoutData(new GridData(
484:                        GridData.HORIZONTAL_ALIGN_FILL));
485:                allControls.add(button);
486:
487:                // Description for user dictionary
488:                new Label(engine, SWT.NONE); // filler
489:                Label description = new Label(engine, SWT.NONE);
490:                gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
491:                gd.horizontalSpan = 3;
492:                description.setLayoutData(gd);
493:                description
494:                        .setText(PreferencesMessages.SpellingPreferencePage_user_dictionary_description);
495:                allControls.add(description);
496:
497:                createEncodingFieldEditor(engine, allControls);
498:
499:                Group advanced = new Group(composite, SWT.NONE);
500:                advanced
501:                        .setText(PreferencesMessages.SpellingPreferencePage_group_advanced);
502:                advanced.setLayout(new GridLayout(3, false));
503:                advanced.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
504:                allControls.add(advanced);
505:
506:                label = PreferencesMessages.SpellingPreferencePage_problems_threshold;
507:                int digits = 4;
508:                Text text = addTextField(advanced, label,
509:                        PREF_SPELLING_PROBLEMS_THRESHOLD, 0, converter
510:                                .convertWidthInCharsToPixels(digits + 1));
511:                text.setTextLimit(digits);
512:                allControls.add(text);
513:                allControls.add(fLabels.get(text));
514:
515:                label = PreferencesMessages.SpellingPreferencePage_proposals_threshold;
516:                digits = 3;
517:                text = addTextField(advanced, label,
518:                        PREF_SPELLING_PROPOSAL_THRESHOLD, 0, converter
519:                                .convertWidthInCharsToPixels(digits + 1));
520:                text.setTextLimit(digits);
521:                gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
522:                allControls.add(text);
523:                allControls.add(fLabels.get(text));
524:
525:                if (SUPPORT_CONTENT_ASSIST_PROPOSALS) {
526:                    label = PreferencesMessages.SpellingPreferencePage_enable_contentassist_label;
527:                    button = addCheckBox(advanced, label,
528:                            PREF_SPELLING_ENABLE_CONTENTASSIST, trueFalse, 0);
529:                    allControls.add(button);
530:                }
531:
532:                fAllControls = (Control[]) allControls
533:                        .toArray(new Control[allControls.size()]);
534:
535:                PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
536:                        IJavaHelpContextIds.SPELLING_CONFIGURATION_BLOCK);
537:                return composite;
538:            }
539:
540:            /**
541:             * Creates the encoding field editor.
542:             * 
543:             * @param composite the parent composite
544:             * @param allControls list with all controls
545:             * @since 3.3
546:             */
547:            private void createEncodingFieldEditor(Composite composite,
548:                    List allControls) {
549:                Label filler = new Label(composite, SWT.NONE);
550:                GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
551:                gd.horizontalSpan = 4;
552:                filler.setLayoutData(gd);
553:
554:                Label label = new Label(composite, SWT.NONE);
555:                label
556:                        .setText(PreferencesMessages.SpellingPreferencePage_encoding_label);
557:                label.setLayoutData(new GridData(
558:                        GridData.VERTICAL_ALIGN_BEGINNING));
559:                allControls.add(label);
560:
561:                fEncodingEditorParent = new Composite(composite, SWT.NONE);
562:                GridLayout layout = new GridLayout(2, false);
563:                layout.marginWidth = 0;
564:                layout.marginHeight = 0;
565:                fEncodingEditorParent.setLayout(layout);
566:                gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
567:                gd.horizontalSpan = 3;
568:                fEncodingEditorParent.setLayoutData(gd);
569:
570:                fEncodingEditor = new EncodingFieldEditor(
571:                        PREF_SPELLING_USER_DICTIONARY_ENCODING.getName(),
572:                        "", null, fEncodingEditorParent); //$NON-NLS-1$
573:
574:                PreferenceStore store = new PreferenceStore();
575:                String defaultEncoding = ResourcesPlugin.getEncoding();
576:                store.setDefault(PREF_SPELLING_USER_DICTIONARY_ENCODING
577:                        .getName(), defaultEncoding);
578:                String encoding = getValue(PREF_SPELLING_USER_DICTIONARY_ENCODING);
579:                if (encoding != null && encoding.length() > 0)
580:                    store.setValue(PREF_SPELLING_USER_DICTIONARY_ENCODING
581:                            .getName(), encoding);
582:
583:                fEncodingEditor.setPreferenceStore(store);
584:
585:                // Redirect status messages from the field editor to the status change listener  
586:                DialogPage fakePage = new DialogPage() {
587:                    public void createControl(Composite c) {
588:                    }
589:
590:                    public void setErrorMessage(String newMessage) {
591:                        StatusInfo status = new StatusInfo();
592:                        if (newMessage != null)
593:                            status.setError(newMessage);
594:                        fEncodingFieldEditorStatus = status;
595:                        fContext.statusChanged(StatusUtil
596:                                .getMostSevere(new IStatus[] {
597:                                        fThresholdStatus, fFileStatus,
598:                                        fEncodingFieldEditorStatus }));
599:                    }
600:                };
601:                fEncodingEditor.setPage(fakePage);
602:
603:                fEncodingEditor.load();
604:
605:                if (encoding == null || encoding.equals(defaultEncoding)
606:                        || encoding.length() == 0)
607:                    fEncodingEditor.loadDefault();
608:
609:            }
610:
611:            private static Key[] getAllKeys() {
612:                if (SUPPORT_CONTENT_ASSIST_PROPOSALS)
613:                    return new Key[] { PREF_SPELLING_USER_DICTIONARY,
614:                            PREF_SPELLING_USER_DICTIONARY_ENCODING,
615:                            PREF_SPELLING_IGNORE_DIGITS,
616:                            PREF_SPELLING_IGNORE_MIXED,
617:                            PREF_SPELLING_IGNORE_SENTENCE,
618:                            PREF_SPELLING_IGNORE_UPPER,
619:                            PREF_SPELLING_IGNORE_URLS,
620:                            PREF_SPELLING_IGNORE_AMPERSAND_IN_PROPERTIES,
621:                            PREF_SPELLING_IGNORE_NON_LETTERS,
622:                            PREF_SPELLING_IGNORE_SINGLE_LETTERS,
623:                            PREF_SPELLING_LOCALE,
624:                            PREF_SPELLING_PROPOSAL_THRESHOLD,
625:                            PREF_SPELLING_PROBLEMS_THRESHOLD,
626:                            PREF_SPELLING_ENABLE_CONTENTASSIST,
627:                            PREF_SPELLING_IGNORE_JAVA_STRINGS };
628:                else
629:                    return new Key[] { PREF_SPELLING_USER_DICTIONARY,
630:                            PREF_SPELLING_USER_DICTIONARY_ENCODING,
631:                            PREF_SPELLING_IGNORE_DIGITS,
632:                            PREF_SPELLING_IGNORE_MIXED,
633:                            PREF_SPELLING_IGNORE_SENTENCE,
634:                            PREF_SPELLING_IGNORE_UPPER,
635:                            PREF_SPELLING_IGNORE_URLS,
636:                            PREF_SPELLING_IGNORE_AMPERSAND_IN_PROPERTIES,
637:                            PREF_SPELLING_IGNORE_NON_LETTERS,
638:                            PREF_SPELLING_IGNORE_SINGLE_LETTERS,
639:                            PREF_SPELLING_LOCALE,
640:                            PREF_SPELLING_PROPOSAL_THRESHOLD,
641:                            PREF_SPELLING_PROBLEMS_THRESHOLD,
642:                            PREF_SPELLING_IGNORE_JAVA_STRINGS };
643:            }
644:
645:            /*
646:             * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#getFullBuildDialogStrings(boolean)
647:             */
648:            protected final String[] getFullBuildDialogStrings(
649:                    final boolean workspace) {
650:                return null;
651:            }
652:
653:            /*
654:             * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#performOk()
655:             * @since 3.3
656:             */
657:            public boolean performOk() {
658:                fEncodingEditor.store();
659:                if (fEncodingEditor.presentsDefaultValue())
660:                    setValue(PREF_SPELLING_USER_DICTIONARY_ENCODING, ""); //$NON-NLS-1$
661:                else
662:                    setValue(PREF_SPELLING_USER_DICTIONARY_ENCODING,
663:                            fEncodingEditor.getPreferenceStore().getString(
664:                                    PREF_SPELLING_USER_DICTIONARY_ENCODING
665:                                            .getName()));
666:                return super .performOk();
667:            }
668:
669:            /*
670:             * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#performApply()
671:             * @since 3.3
672:             */
673:            public boolean performApply() {
674:                fEncodingEditor.store();
675:                if (fEncodingEditor.presentsDefaultValue())
676:                    setValue(PREF_SPELLING_USER_DICTIONARY_ENCODING, ""); //$NON-NLS-1$
677:                else
678:                    setValue(PREF_SPELLING_USER_DICTIONARY_ENCODING,
679:                            fEncodingEditor.getPreferenceStore().getString(
680:                                    PREF_SPELLING_USER_DICTIONARY_ENCODING
681:                                            .getName()));
682:                return super .performApply();
683:            }
684:
685:            /*
686:             * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#performDefaults()
687:             * @since 3.3
688:             */
689:            public void performDefaults() {
690:                super .performDefaults();
691:
692:                setValue(PREF_SPELLING_USER_DICTIONARY_ENCODING, ""); //$NON-NLS-1$
693:
694:                fEncodingEditor.getPreferenceStore().setValue(
695:                        fEncodingEditor.getPreferenceName(),
696:                        ResourcesPlugin.getEncoding());
697:                fEncodingEditor.load();
698:
699:                fEncodingEditor.loadDefault();
700:            }
701:
702:            protected void handleVariablesButtonSelected() {
703:                StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(
704:                        fDictionaryPath.getShell());
705:                if (dialog.open() == Window.OK)
706:                    fDictionaryPath.setText(fDictionaryPath.getText()
707:                            + dialog.getVariableExpression());
708:            }
709:
710:            /**
711:             * Handles selections of the browse button.
712:             */
713:            protected void handleBrowseButtonSelected() {
714:                final FileDialog dialog = new FileDialog(fDictionaryPath
715:                        .getShell(), SWT.OPEN);
716:                dialog
717:                        .setText(PreferencesMessages.SpellingPreferencePage_filedialog_title);
718:                dialog.setFilterPath(fDictionaryPath.getText());
719:
720:                final String path = dialog.open();
721:                if (path != null)
722:                    fDictionaryPath.setText(path);
723:            }
724:
725:            /*
726:             * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#validateSettings(java.lang.String,java.lang.String)
727:             */
728:            protected void validateSettings(final Key key,
729:                    final String oldValue, final String newValue) {
730:                if (key == null || PREF_SPELLING_PROPOSAL_THRESHOLD.equals(key))
731:                    fThresholdStatus = validatePositiveNumber(getValue(PREF_SPELLING_PROPOSAL_THRESHOLD));
732:                else
733:                    fThresholdStatus = new StatusInfo();
734:
735:                if (key == null || PREF_SPELLING_PROBLEMS_THRESHOLD.equals(key)) {
736:                    IStatus status = validatePositiveNumber(getValue(PREF_SPELLING_PROBLEMS_THRESHOLD));
737:                    fThresholdStatus = StatusUtil.getMostSevere(new IStatus[] {
738:                            fThresholdStatus, status });
739:                }
740:
741:                if (key == null || PREF_SPELLING_USER_DICTIONARY.equals(key))
742:                    fFileStatus = validateAbsoluteFilePath(getValue(PREF_SPELLING_USER_DICTIONARY));
743:
744:                fContext.statusChanged(StatusUtil.getMostSevere(new IStatus[] {
745:                        fThresholdStatus, fFileStatus,
746:                        fEncodingFieldEditorStatus }));
747:            }
748:
749:            /*
750:             * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#updateCheckBox(org.eclipse.swt.widgets.Button)
751:             * @since 3.1
752:             */
753:            protected void updateCheckBox(Button curr) {
754:                super .updateCheckBox(curr);
755:                Event event = new Event();
756:                event.type = SWT.Selection;
757:                event.display = curr.getDisplay();
758:                event.widget = curr;
759:                curr.notifyListeners(SWT.Selection, event);
760:            }
761:
762:            /**
763:             * Sets the enabled state.
764:             * 
765:             * @param enabled the new state
766:             * @since 3.1
767:             */
768:            protected void setEnabled(boolean enabled) {
769:                fEncodingEditor.setEnabled(enabled, fEncodingEditorParent);
770:
771:                if (enabled && fEnabledControls != null) {
772:                    for (int i = fEnabledControls.length - 1; i >= 0; i--)
773:                        fEnabledControls[i].setEnabled(true);
774:                    fEnabledControls = null;
775:                }
776:                if (!enabled && fEnabledControls == null) {
777:                    List enabledControls = new ArrayList();
778:                    for (int i = fAllControls.length - 1; i >= 0; i--) {
779:                        Control control = fAllControls[i];
780:                        if (control.isEnabled()) {
781:                            enabledControls.add(control);
782:                            control.setEnabled(false);
783:                        }
784:                    }
785:                    fEnabledControls = (Control[]) enabledControls
786:                            .toArray(new Control[enabledControls.size()]);
787:                }
788:            }
789:
790:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.