Source Code Cross Referenced for NameConventionConfigurationBlock.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, 2006 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.util.ArrayList;
013:        import java.util.List;
014:
015:        import org.eclipse.core.runtime.IStatus;
016:
017:        import org.eclipse.core.resources.IProject;
018:
019:        import org.eclipse.swt.SWT;
020:        import org.eclipse.swt.graphics.Image;
021:        import org.eclipse.swt.layout.GridData;
022:        import org.eclipse.swt.layout.GridLayout;
023:        import org.eclipse.swt.widgets.Composite;
024:        import org.eclipse.swt.widgets.Control;
025:        import org.eclipse.swt.widgets.Shell;
026:        import org.eclipse.swt.widgets.Table;
027:
028:        import org.eclipse.jface.dialogs.StatusDialog;
029:        import org.eclipse.jface.viewers.ColumnLayoutData;
030:        import org.eclipse.jface.viewers.ColumnWeightData;
031:        import org.eclipse.jface.viewers.ITableLabelProvider;
032:        import org.eclipse.jface.viewers.LabelProvider;
033:        import org.eclipse.jface.window.Window;
034:
035:        import org.eclipse.ui.PlatformUI;
036:        import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
037:
038:        import org.eclipse.jdt.core.JavaConventions;
039:        import org.eclipse.jdt.core.JavaCore;
040:
041:        import org.eclipse.jdt.internal.corext.util.Messages;
042:        import org.eclipse.jdt.internal.corext.util.Strings;
043:
044:        import org.eclipse.jdt.ui.JavaElementImageDescriptor;
045:        import org.eclipse.jdt.ui.PreferenceConstants;
046:
047:        import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
048:        import org.eclipse.jdt.internal.ui.JavaPlugin;
049:        import org.eclipse.jdt.internal.ui.JavaPluginImages;
050:        import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
051:        import org.eclipse.jdt.internal.ui.dialogs.StatusUtil;
052:        import org.eclipse.jdt.internal.ui.util.SWTUtil;
053:        import org.eclipse.jdt.internal.ui.viewsupport.ImageDescriptorRegistry;
054:        import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
055:        import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener;
056:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
057:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
058:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter;
059:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
060:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField;
061:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
062:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
063:
064:        /*
065:         * The page to configure name conventions
066:         */
067:        public class NameConventionConfigurationBlock extends
068:                OptionsConfigurationBlock {
069:
070:            private final static int FIELD = 1;
071:            private final static int STATIC = 2;
072:            private final static int ARGUMENT = 3;
073:            private final static int LOCAL = 4;
074:
075:            // Preference store keys
076:            private static final Key PREF_FIELD_PREFIXES = getJDTCoreKey(JavaCore.CODEASSIST_FIELD_PREFIXES);
077:            private static final Key PREF_FIELD_SUFFIXES = getJDTCoreKey(JavaCore.CODEASSIST_FIELD_SUFFIXES);
078:            private static final Key PREF_STATIC_FIELD_PREFIXES = getJDTCoreKey(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES);
079:            private static final Key PREF_STATIC_FIELD_SUFFIXES = getJDTCoreKey(JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES);
080:            private static final Key PREF_ARGUMENT_PREFIXES = getJDTCoreKey(JavaCore.CODEASSIST_ARGUMENT_PREFIXES);
081:            private static final Key PREF_ARGUMENT_SUFFIXES = getJDTCoreKey(JavaCore.CODEASSIST_ARGUMENT_SUFFIXES);
082:            private static final Key PREF_LOCAL_PREFIXES = getJDTCoreKey(JavaCore.CODEASSIST_LOCAL_PREFIXES);
083:            private static final Key PREF_LOCAL_SUFFIXES = getJDTCoreKey(JavaCore.CODEASSIST_LOCAL_SUFFIXES);
084:
085:            private static final Key PREF_KEYWORD_THIS = getJDTUIKey(PreferenceConstants.CODEGEN_KEYWORD_THIS);
086:            private static final Key PREF_IS_FOR_GETTERS = getJDTUIKey(PreferenceConstants.CODEGEN_IS_FOR_GETTERS);
087:            private static final Key PREF_EXCEPTION_NAME = getJDTUIKey(PreferenceConstants.CODEGEN_EXCEPTION_VAR_NAME);
088:
089:            private static final Key PREF_USE_OVERRIDE_ANNOT = getJDTUIKey(PreferenceConstants.CODEGEN_USE_OVERRIDE_ANNOTATION);
090:
091:            private static class NameConventionEntry {
092:                public int kind;
093:                public String prefix;
094:                public String suffix;
095:                public Key prefixkey;
096:                public Key suffixkey;
097:            }
098:
099:            private class NameConventionInputDialog extends StatusDialog
100:                    implements  IDialogFieldListener {
101:
102:                private StringDialogField fPrefixField;
103:                private StringDialogField fSuffixField;
104:                private NameConventionEntry fEntry;
105:                private DialogField fMessageField;
106:
107:                public NameConventionInputDialog(Shell parent, String title,
108:                        String message, NameConventionEntry entry) {
109:                    super (parent);
110:                    fEntry = entry;
111:
112:                    setTitle(title);
113:
114:                    fMessageField = new DialogField();
115:                    fMessageField.setLabelText(message);
116:
117:                    fPrefixField = new StringDialogField();
118:                    fPrefixField
119:                            .setLabelText(PreferencesMessages.NameConventionConfigurationBlock_dialog_prefix);
120:                    fPrefixField.setDialogFieldListener(this );
121:
122:                    fSuffixField = new StringDialogField();
123:                    fSuffixField
124:                            .setLabelText(PreferencesMessages.NameConventionConfigurationBlock_dialog_suffix);
125:                    fSuffixField.setDialogFieldListener(this );
126:
127:                    fPrefixField.setText(entry.prefix);
128:                    fSuffixField.setText(entry.suffix);
129:                }
130:
131:                public NameConventionEntry getResult() {
132:                    NameConventionEntry res = new NameConventionEntry();
133:                    res.prefix = Strings.removeTrailingCharacters(fPrefixField
134:                            .getText(), ',');
135:                    res.suffix = Strings.removeTrailingCharacters(fSuffixField
136:                            .getText(), ',');
137:                    res.prefixkey = fEntry.prefixkey;
138:                    res.suffixkey = fEntry.suffixkey;
139:                    res.kind = fEntry.kind;
140:                    return res;
141:                }
142:
143:                protected Control createDialogArea(Composite parent) {
144:                    Composite composite = (Composite) super 
145:                            .createDialogArea(parent);
146:                    Composite inner = new Composite(composite, SWT.NONE);
147:                    inner.setFont(composite.getFont());
148:                    GridLayout layout = new GridLayout();
149:                    layout.marginHeight = 0;
150:                    layout.marginWidth = 0;
151:                    layout.numColumns = 2;
152:                    inner.setLayout(layout);
153:
154:                    fMessageField.doFillIntoGrid(inner, 2);
155:                    fPrefixField.doFillIntoGrid(inner, 2);
156:                    fSuffixField.doFillIntoGrid(inner, 2);
157:
158:                    LayoutUtil.setHorizontalGrabbing(fPrefixField
159:                            .getTextControl(null));
160:                    LayoutUtil.setWidthHint(fPrefixField.getTextControl(null),
161:                            convertWidthInCharsToPixels(45));
162:                    LayoutUtil.setWidthHint(fSuffixField.getTextControl(null),
163:                            convertWidthInCharsToPixels(45));
164:
165:                    fPrefixField.postSetFocusOnDialogField(parent.getDisplay());
166:
167:                    applyDialogFont(composite);
168:
169:                    PlatformUI.getWorkbench().getHelpSystem().setHelp(
170:                            composite,
171:                            IJavaHelpContextIds.CODE_STYLE_EDIT_PREFIX_SUFFIX);
172:
173:                    return composite;
174:                }
175:
176:                /* (non-Javadoc)
177:                 * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener#dialogFieldChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)
178:                 */
179:                public void dialogFieldChanged(DialogField field) {
180:                    // validate
181:                    IStatus prefixStatus = validateIdentifiers(getTokens(
182:                            fPrefixField.getText(), ","), true); //$NON-NLS-1$
183:                    IStatus suffixStatus = validateIdentifiers(getTokens(
184:                            fSuffixField.getText(), ","), false); //$NON-NLS-1$
185:
186:                    updateStatus(StatusUtil.getMoreSevere(suffixStatus,
187:                            prefixStatus));
188:                }
189:
190:                private IStatus validateIdentifiers(String[] values,
191:                        boolean prefix) {
192:                    for (int i = 0; i < values.length; i++) {
193:                        String val = values[i];
194:                        if (val.length() == 0) {
195:                            if (prefix) {
196:                                return new StatusInfo(
197:                                        IStatus.ERROR,
198:                                        PreferencesMessages.NameConventionConfigurationBlock_error_emptyprefix);
199:                            } else {
200:                                return new StatusInfo(
201:                                        IStatus.ERROR,
202:                                        PreferencesMessages.NameConventionConfigurationBlock_error_emptysuffix);
203:                            }
204:                        }
205:                        String name = prefix ? val + "x" : "x" + val; //$NON-NLS-2$ //$NON-NLS-1$
206:                        IStatus status = JavaConventions.validateIdentifier(
207:                                name, JavaCore.VERSION_1_3,
208:                                JavaCore.VERSION_1_3);
209:                        if (status.matches(IStatus.ERROR)) {
210:                            if (prefix) {
211:                                return new StatusInfo(
212:                                        IStatus.ERROR,
213:                                        Messages
214:                                                .format(
215:                                                        PreferencesMessages.NameConventionConfigurationBlock_error_invalidprefix,
216:                                                        val));
217:                            } else {
218:                                return new StatusInfo(
219:                                        IStatus.ERROR,
220:                                        Messages
221:                                                .format(
222:                                                        PreferencesMessages.NameConventionConfigurationBlock_error_invalidsuffix,
223:                                                        val));
224:                            }
225:                        }
226:                    }
227:                    return new StatusInfo();
228:                }
229:
230:                /*
231:                 * @see org.eclipse.jface.window.Window#configureShell(Shell)
232:                 */
233:                protected void configureShell(Shell newShell) {
234:                    super .configureShell(newShell);
235:                    //PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.IMPORT_ORGANIZE_INPUT_DIALOG);
236:                }
237:            }
238:
239:            private static class NameConventionLabelProvider extends
240:                    LabelProvider implements  ITableLabelProvider {
241:
242:                /* (non-Javadoc)
243:                 * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
244:                 */
245:                public Image getImage(Object element) {
246:                    return getColumnImage(element, 0);
247:                }
248:
249:                /* (non-Javadoc)
250:                 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
251:                 */
252:                public String getText(Object element) {
253:                    return getColumnText(element, 0);
254:                }
255:
256:                /* (non-Javadoc)
257:                 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
258:                 */
259:                public Image getColumnImage(Object element, int columnIndex) {
260:                    if (columnIndex != 0) {
261:                        return null;
262:                    }
263:
264:                    NameConventionEntry entry = (NameConventionEntry) element;
265:                    ImageDescriptorRegistry registry = JavaPlugin
266:                            .getImageDescriptorRegistry();
267:                    switch (entry.kind) {
268:                    case FIELD:
269:                        return registry.get(JavaPluginImages.DESC_FIELD_PUBLIC);
270:                    case STATIC:
271:                        return registry.get(new JavaElementImageDescriptor(
272:                                JavaPluginImages.DESC_FIELD_PUBLIC,
273:                                JavaElementImageDescriptor.STATIC,
274:                                JavaElementImageProvider.SMALL_SIZE));
275:                    case ARGUMENT:
276:                        return registry
277:                                .get(JavaPluginImages.DESC_OBJS_LOCAL_VARIABLE);
278:                    default:
279:                        return registry
280:                                .get(JavaPluginImages.DESC_OBJS_LOCAL_VARIABLE);
281:                    }
282:                }
283:
284:                /* (non-Javadoc)
285:                 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
286:                 */
287:                public String getColumnText(Object element, int columnIndex) {
288:                    NameConventionEntry entry = (NameConventionEntry) element;
289:                    if (columnIndex == 0) {
290:                        switch (entry.kind) {
291:                        case FIELD:
292:                            return PreferencesMessages.NameConventionConfigurationBlock_field_label;
293:                        case STATIC:
294:                            return PreferencesMessages.NameConventionConfigurationBlock_static_label;
295:                        case ARGUMENT:
296:                            return PreferencesMessages.NameConventionConfigurationBlock_arg_label;
297:                        default:
298:                            return PreferencesMessages.NameConventionConfigurationBlock_local_label;
299:                        }
300:                    } else if (columnIndex == 1) {
301:                        return entry.prefix;
302:                    } else {
303:                        return entry.suffix;
304:                    }
305:                }
306:            }
307:
308:            private class NameConventionAdapter implements  IListAdapter,
309:                    IDialogFieldListener {
310:
311:                private boolean canEdit(ListDialogField field) {
312:                    return field.getSelectedElements().size() == 1;
313:                }
314:
315:                public void customButtonPressed(ListDialogField field, int index) {
316:                    doEditButtonPressed();
317:                }
318:
319:                public void selectionChanged(ListDialogField field) {
320:                    field.enableButton(0, canEdit(field));
321:                }
322:
323:                public void doubleClicked(ListDialogField field) {
324:                    if (canEdit(field)) {
325:                        doEditButtonPressed();
326:                    }
327:                }
328:
329:                public void dialogFieldChanged(DialogField field) {
330:                    updateModel(field);
331:                }
332:            }
333:
334:            private ListDialogField fNameConventionList;
335:            private SelectionButtonDialogField fUseKeywordThisBox;
336:            private SelectionButtonDialogField fUseIsForBooleanGettersBox;
337:
338:            private StringDialogField fExceptionName;
339:            private SelectionButtonDialogField fUseOverrideAnnotation;
340:
341:            public NameConventionConfigurationBlock(
342:                    IStatusChangeListener context, IProject project,
343:                    IWorkbenchPreferenceContainer container) {
344:                super (context, project, getAllKeys(), container);
345:
346:                NameConventionAdapter adapter = new NameConventionAdapter();
347:                String[] buttons = new String[] { PreferencesMessages.NameConventionConfigurationBlock_list_edit_button };
348:                fNameConventionList = new ListDialogField(adapter, buttons,
349:                        new NameConventionLabelProvider());
350:                fNameConventionList.setDialogFieldListener(adapter);
351:                fNameConventionList
352:                        .setLabelText(PreferencesMessages.NameConventionConfigurationBlock_list_label);
353:
354:                String[] columnsHeaders = new String[] {
355:                        PreferencesMessages.NameConventionConfigurationBlock_list_name_column,
356:                        PreferencesMessages.NameConventionConfigurationBlock_list_prefix_column,
357:                        PreferencesMessages.NameConventionConfigurationBlock_list_suffix_column, };
358:                ColumnLayoutData[] data = new ColumnLayoutData[] {
359:                        new ColumnWeightData(3), new ColumnWeightData(2),
360:                        new ColumnWeightData(2) };
361:
362:                fNameConventionList
363:                        .setTableColumns(new ListDialogField.ColumnsDescription(
364:                                data, columnsHeaders, true));
365:
366:                if (fNameConventionList.getSize() > 0) {
367:                    fNameConventionList.selectFirstElement();
368:                } else {
369:                    fNameConventionList.enableButton(0, false);
370:                }
371:
372:                fExceptionName = new StringDialogField();
373:                fExceptionName.setDialogFieldListener(adapter);
374:                fExceptionName
375:                        .setLabelText(PreferencesMessages.NameConventionConfigurationBlock_exceptionname_label);
376:
377:                fUseKeywordThisBox = new SelectionButtonDialogField(SWT.CHECK
378:                        | SWT.WRAP);
379:                fUseKeywordThisBox.setDialogFieldListener(adapter);
380:                fUseKeywordThisBox
381:                        .setLabelText(PreferencesMessages.NameConventionConfigurationBlock_keywordthis _label);
382:
383:                fUseIsForBooleanGettersBox = new SelectionButtonDialogField(
384:                        SWT.CHECK | SWT.WRAP);
385:                fUseIsForBooleanGettersBox.setDialogFieldListener(adapter);
386:                fUseIsForBooleanGettersBox
387:                        .setLabelText(PreferencesMessages.NameConventionConfigurationBlock_isforbooleangetters_label);
388:
389:                fUseOverrideAnnotation = new SelectionButtonDialogField(
390:                        SWT.CHECK | SWT.WRAP);
391:                fUseOverrideAnnotation.setDialogFieldListener(adapter);
392:                fUseOverrideAnnotation
393:                        .setLabelText(PreferencesMessages.NameConventionConfigurationBlock_use_override_annotation_label);
394:
395:                updateControls();
396:            }
397:
398:            private static Key[] getAllKeys() {
399:                return new Key[] { PREF_FIELD_PREFIXES, PREF_FIELD_SUFFIXES,
400:                        PREF_STATIC_FIELD_PREFIXES, PREF_STATIC_FIELD_SUFFIXES,
401:                        PREF_ARGUMENT_PREFIXES, PREF_ARGUMENT_SUFFIXES,
402:                        PREF_LOCAL_PREFIXES, PREF_LOCAL_SUFFIXES,
403:                        PREF_EXCEPTION_NAME, PREF_KEYWORD_THIS,
404:                        PREF_IS_FOR_GETTERS, PREF_USE_OVERRIDE_ANNOT };
405:            }
406:
407:            protected Control createContents(Composite parent) {
408:                setShell(parent.getShell());
409:
410:                GridLayout layout = new GridLayout();
411:                layout.numColumns = 3;
412:                layout.marginHeight = 0;
413:                layout.marginWidth = 0;
414:
415:                Composite composite = new Composite(parent, SWT.NONE);
416:                composite.setFont(parent.getFont());
417:                composite.setLayout(layout);
418:
419:                fNameConventionList.doFillIntoGrid(composite, 4);
420:                LayoutUtil.setHorizontalSpan(fNameConventionList
421:                        .getLabelControl(null), 2);
422:                Table table = fNameConventionList.getTableViewer().getTable();
423:                GridData data = (GridData) fNameConventionList.getListControl(
424:                        null).getLayoutData();
425:                data.heightHint = SWTUtil.getTableHeightHint(table, 5);
426:                data.grabExcessHorizontalSpace = true;
427:                data.verticalAlignment = GridData.BEGINNING;
428:                data.grabExcessVerticalSpace = false;
429:
430:                data = (GridData) fNameConventionList.getButtonBox(null)
431:                        .getLayoutData();
432:                data.grabExcessVerticalSpace = false;
433:                data.verticalAlignment = GridData.BEGINNING;
434:
435:                fUseKeywordThisBox.doFillIntoGrid(composite, 3);
436:                fUseIsForBooleanGettersBox.doFillIntoGrid(composite, 3);
437:
438:                fUseOverrideAnnotation.doFillIntoGrid(composite, 3);
439:                DialogField.createEmptySpace(composite, 3);
440:
441:                fExceptionName.doFillIntoGrid(composite, 2);
442:
443:                return composite;
444:            }
445:
446:            /* (non-Javadoc)
447:             * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#validateSettings(java.lang.String, java.lang.String)
448:             */
449:            protected void validateSettings(Key changedKey, String oldValue,
450:                    String newValue) {
451:                // no validation here
452:            }
453:
454:            protected final void updateModel(DialogField field) {
455:                if (field == fNameConventionList) {
456:                    for (int i = 0; i < fNameConventionList.getSize(); i++) {
457:                        NameConventionEntry entry = (NameConventionEntry) fNameConventionList
458:                                .getElement(i);
459:                        setValue(entry.suffixkey, entry.suffix);
460:                        setValue(entry.prefixkey, entry.prefix);
461:                    }
462:                } else if (field == fExceptionName) {
463:                    String name = fExceptionName.getText();
464:
465:                    setValue(PREF_EXCEPTION_NAME, name);
466:
467:                    // validation
468:                    IStatus status = JavaConventions.validateIdentifier(name,
469:                            JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
470:                    if (!status.isOK()) {
471:                        fContext.statusChanged(status);
472:                    } else {
473:                        fContext.statusChanged(new StatusInfo());
474:                    }
475:                } else if (field == fUseKeywordThisBox) {
476:                    setValue(PREF_KEYWORD_THIS, fUseKeywordThisBox.isSelected());
477:                } else if (field == fUseIsForBooleanGettersBox) {
478:                    setValue(PREF_IS_FOR_GETTERS, fUseIsForBooleanGettersBox
479:                            .isSelected());
480:                } else if (field == fUseOverrideAnnotation) {
481:                    setValue(PREF_USE_OVERRIDE_ANNOT, fUseOverrideAnnotation
482:                            .isSelected());
483:                }
484:            }
485:
486:            /* (non-Javadoc)
487:             * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#updateControls()
488:             */
489:            protected void updateControls() {
490:                ArrayList list = new ArrayList(4);
491:                createEntry(list, PREF_FIELD_PREFIXES, PREF_FIELD_SUFFIXES,
492:                        FIELD);
493:                createEntry(list, PREF_STATIC_FIELD_PREFIXES,
494:                        PREF_STATIC_FIELD_SUFFIXES, STATIC);
495:                createEntry(list, PREF_ARGUMENT_PREFIXES,
496:                        PREF_ARGUMENT_SUFFIXES, ARGUMENT);
497:                createEntry(list, PREF_LOCAL_PREFIXES, PREF_LOCAL_SUFFIXES,
498:                        LOCAL);
499:                fNameConventionList.setElements(list);
500:
501:                fExceptionName.setText(getValue(PREF_EXCEPTION_NAME));
502:                fUseKeywordThisBox
503:                        .setSelection(getBooleanValue(PREF_KEYWORD_THIS));
504:                fUseIsForBooleanGettersBox
505:                        .setSelection(getBooleanValue(PREF_IS_FOR_GETTERS));
506:                fUseOverrideAnnotation
507:                        .setSelection(getBooleanValue(PREF_USE_OVERRIDE_ANNOT));
508:            }
509:
510:            /* (non-Javadoc)
511:             * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#getFullBuildDialogStrings(boolean)
512:             */
513:            protected String[] getFullBuildDialogStrings(
514:                    boolean workspaceSettings) {
515:                return null; // no build required
516:            }
517:
518:            private void createEntry(List list, Key prefixKey, Key suffixKey,
519:                    int kind) {
520:                NameConventionEntry entry = new NameConventionEntry();
521:                entry.kind = kind;
522:                entry.suffixkey = suffixKey;
523:                entry.prefixkey = prefixKey;
524:                entry.suffix = getPreferenceValue(suffixKey);
525:                entry.prefix = getPreferenceValue(prefixKey);
526:                list.add(entry);
527:            }
528:
529:            private String getPreferenceValue(Key key) {
530:                String value = getValue(key);
531:                if (value == null) {
532:                    value = ""; //$NON-NLS-1$
533:                    JavaPlugin
534:                            .logErrorMessage("JavaCore preference is null. Key:" + key); //$NON-NLS-1$
535:                }
536:                return value;
537:            }
538:
539:            private void doEditButtonPressed() {
540:                NameConventionEntry entry = (NameConventionEntry) fNameConventionList
541:                        .getSelectedElements().get(0);
542:
543:                String title;
544:                String message;
545:                switch (entry.kind) {
546:                case FIELD:
547:                    title = PreferencesMessages.NameConventionConfigurationBlock_field_dialog_title;
548:                    message = PreferencesMessages.NameConventionConfigurationBlock_field_dialog_message;
549:                    break;
550:                case STATIC:
551:                    title = PreferencesMessages.NameConventionConfigurationBlock_static_dialog_title;
552:                    message = PreferencesMessages.NameConventionConfigurationBlock_static_dialog_message;
553:                    break;
554:                case ARGUMENT:
555:                    title = PreferencesMessages.NameConventionConfigurationBlock_arg_dialog_title;
556:                    message = PreferencesMessages.NameConventionConfigurationBlock_arg_dialog_message;
557:                    break;
558:                default:
559:                    title = PreferencesMessages.NameConventionConfigurationBlock_local_dialog_title;
560:                    message = PreferencesMessages.NameConventionConfigurationBlock_local_dialog_message;
561:                }
562:
563:                NameConventionInputDialog dialog = new NameConventionInputDialog(
564:                        getShell(), title, message, entry);
565:                if (dialog.open() == Window.OK) {
566:                    fNameConventionList.replaceElement(entry, dialog
567:                            .getResult());
568:                    updateModel(fNameConventionList);
569:                }
570:            }
571:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.