Source Code Cross Referenced for ComplianceConfigurationBlock.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.Arrays;
014:        import java.util.HashMap;
015:        import java.util.Map;
016:
017:        import org.eclipse.core.runtime.CoreException;
018:        import org.eclipse.core.runtime.IStatus;
019:
020:        import org.eclipse.core.resources.IProject;
021:
022:        import org.eclipse.swt.SWT;
023:        import org.eclipse.swt.events.SelectionEvent;
024:        import org.eclipse.swt.events.SelectionListener;
025:        import org.eclipse.swt.layout.GridData;
026:        import org.eclipse.swt.layout.GridLayout;
027:        import org.eclipse.swt.widgets.Button;
028:        import org.eclipse.swt.widgets.Combo;
029:        import org.eclipse.swt.widgets.Composite;
030:        import org.eclipse.swt.widgets.Control;
031:        import org.eclipse.swt.widgets.Group;
032:        import org.eclipse.swt.widgets.Link;
033:
034:        import org.eclipse.jface.dialogs.ControlEnableState;
035:
036:        import org.eclipse.ui.dialogs.PreferencesUtil;
037:        import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
038:
039:        import org.eclipse.jdt.core.JavaCore;
040:
041:        import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
042:        import org.eclipse.jdt.internal.corext.util.Messages;
043:
044:        import org.eclipse.jdt.launching.IVMInstall;
045:        import org.eclipse.jdt.launching.IVMInstall2;
046:        import org.eclipse.jdt.launching.JavaRuntime;
047:
048:        import org.eclipse.jdt.internal.ui.JavaPlugin;
049:        import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
050:        import org.eclipse.jdt.internal.ui.util.PixelConverter;
051:        import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener;
052:        import org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathSupport;
053:
054:        /**
055:         */
056:        public class ComplianceConfigurationBlock extends
057:                OptionsConfigurationBlock {
058:
059:            // Preference store keys, see JavaCore.getOptions
060:            private static final Key PREF_LOCAL_VARIABLE_ATTR = getJDTCoreKey(JavaCore.COMPILER_LOCAL_VARIABLE_ATTR);
061:            private static final Key PREF_LINE_NUMBER_ATTR = getJDTCoreKey(JavaCore.COMPILER_LINE_NUMBER_ATTR);
062:            private static final Key PREF_SOURCE_FILE_ATTR = getJDTCoreKey(JavaCore.COMPILER_SOURCE_FILE_ATTR);
063:            private static final Key PREF_CODEGEN_UNUSED_LOCAL = getJDTCoreKey(JavaCore.COMPILER_CODEGEN_UNUSED_LOCAL);
064:            private static final Key PREF_CODEGEN_TARGET_PLATFORM = getJDTCoreKey(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM);
065:            private static final Key PREF_CODEGEN_INLINE_JSR_BYTECODE = getJDTCoreKey(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE);
066:
067:            private static final Key PREF_SOURCE_COMPATIBILITY = getJDTCoreKey(JavaCore.COMPILER_SOURCE);
068:            private static final Key PREF_COMPLIANCE = getJDTCoreKey(JavaCore.COMPILER_COMPLIANCE);
069:            private static final Key PREF_PB_ASSERT_AS_IDENTIFIER = getJDTCoreKey(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER);
070:            private static final Key PREF_PB_ENUM_AS_IDENTIFIER = getJDTCoreKey(JavaCore.COMPILER_PB_ENUM_IDENTIFIER);
071:
072:            private static final Key INTR_DEFAULT_COMPLIANCE = getJDTUIKey("internal.default.compliance"); //$NON-NLS-1$
073:
074:            // values
075:            private static final String GENERATE = JavaCore.GENERATE;
076:            private static final String DO_NOT_GENERATE = JavaCore.DO_NOT_GENERATE;
077:
078:            private static final String PRESERVE = JavaCore.PRESERVE;
079:            private static final String OPTIMIZE_OUT = JavaCore.OPTIMIZE_OUT;
080:
081:            private static final String VERSION_1_1 = JavaCore.VERSION_1_1;
082:            private static final String VERSION_1_2 = JavaCore.VERSION_1_2;
083:            private static final String VERSION_1_3 = JavaCore.VERSION_1_3;
084:            private static final String VERSION_1_4 = JavaCore.VERSION_1_4;
085:            private static final String VERSION_1_5 = JavaCore.VERSION_1_5;
086:            private static final String VERSION_1_6 = JavaCore.VERSION_1_6;
087:
088:            private static final String ERROR = JavaCore.ERROR;
089:            private static final String WARNING = JavaCore.WARNING;
090:            private static final String IGNORE = JavaCore.IGNORE;
091:
092:            private static final String ENABLED = JavaCore.ENABLED;
093:            private static final String DISABLED = JavaCore.DISABLED;
094:
095:            private static final String DEFAULT_CONF = "default"; //$NON-NLS-1$
096:            private static final String USER_CONF = "user"; //$NON-NLS-1$
097:
098:            private ArrayList fComplianceControls;
099:            private PixelConverter fPixelConverter;
100:
101:            private String[] fRememberedUserCompliance;
102:
103:            private static final int IDX_ASSERT_AS_IDENTIFIER = 0;
104:            private static final int IDX_ENUM_AS_IDENTIFIER = 1;
105:            private static final int IDX_SOURCE_COMPATIBILITY = 2;
106:            private static final int IDX_CODEGEN_TARGET_PLATFORM = 3;
107:            private static final int IDX_COMPLIANCE = 4;
108:            private static final int IDX_INLINE_JSR_BYTECODE = 5;
109:
110:            private IStatus fComplianceStatus;
111:
112:            private Link fJRE50InfoText;
113:            private Composite fControlsComposite;
114:            private ControlEnableState fBlockEnableState;
115:
116:            public ComplianceConfigurationBlock(IStatusChangeListener context,
117:                    IProject project, IWorkbenchPreferenceContainer container) {
118:                super (context, project, getKeys(), container);
119:
120:                fBlockEnableState = null;
121:                fComplianceControls = new ArrayList();
122:
123:                fComplianceStatus = new StatusInfo();
124:
125:                fRememberedUserCompliance = new String[] { // caution: order depends on IDX_* constants
126:                getValue(PREF_PB_ASSERT_AS_IDENTIFIER),
127:                        getValue(PREF_PB_ENUM_AS_IDENTIFIER),
128:                        getValue(PREF_SOURCE_COMPATIBILITY),
129:                        getValue(PREF_CODEGEN_TARGET_PLATFORM),
130:                        getValue(PREF_COMPLIANCE),
131:                        getValue(PREF_CODEGEN_INLINE_JSR_BYTECODE), };
132:            }
133:
134:            private static Key[] getKeys() {
135:                return new Key[] { PREF_LOCAL_VARIABLE_ATTR,
136:                        PREF_LINE_NUMBER_ATTR, PREF_SOURCE_FILE_ATTR,
137:                        PREF_CODEGEN_UNUSED_LOCAL,
138:                        PREF_CODEGEN_INLINE_JSR_BYTECODE, PREF_COMPLIANCE,
139:                        PREF_SOURCE_COMPATIBILITY,
140:                        PREF_CODEGEN_TARGET_PLATFORM,
141:                        PREF_PB_ASSERT_AS_IDENTIFIER,
142:                        PREF_PB_ENUM_AS_IDENTIFIER };
143:            }
144:
145:            /* (non-Javadoc)
146:             * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#settingsUpdated()
147:             */
148:            protected void settingsUpdated() {
149:                setValue(INTR_DEFAULT_COMPLIANCE, getCurrentCompliance());
150:                super .settingsUpdated();
151:            }
152:
153:            /*
154:             * @see org.eclipse.jface.preference.PreferencePage#createContents(Composite)
155:             */
156:            protected Control createContents(Composite parent) {
157:                fPixelConverter = new PixelConverter(parent);
158:                setShell(parent.getShell());
159:
160:                Composite complianceComposite = createComplianceTabContent(parent);
161:
162:                validateSettings(null, null, null);
163:
164:                return complianceComposite;
165:            }
166:
167:            public void enablePreferenceContent(boolean enable) {
168:                if (fControlsComposite != null
169:                        && !fControlsComposite.isDisposed()) {
170:                    if (enable) {
171:                        if (fBlockEnableState != null) {
172:                            fBlockEnableState.restore();
173:                            fBlockEnableState = null;
174:                        }
175:                    } else {
176:                        if (fBlockEnableState == null) {
177:                            fBlockEnableState = ControlEnableState
178:                                    .disable(fControlsComposite);
179:                        }
180:                    }
181:                }
182:            }
183:
184:            private Composite createComplianceTabContent(Composite folder) {
185:
186:                String[] values3456 = new String[] { VERSION_1_3, VERSION_1_4,
187:                        VERSION_1_5, VERSION_1_6 };
188:                String[] values3456Labels = new String[] {
189:                        PreferencesMessages.ComplianceConfigurationBlock_version13,
190:                        PreferencesMessages.ComplianceConfigurationBlock_version14,
191:                        PreferencesMessages.ComplianceConfigurationBlock_version15,
192:                        PreferencesMessages.ComplianceConfigurationBlock_version16 };
193:
194:                final ScrolledPageContent sc1 = new ScrolledPageContent(folder);
195:                Composite composite = sc1.getBody();
196:                GridLayout layout = new GridLayout();
197:                layout.marginHeight = 0;
198:                layout.marginWidth = 0;
199:                composite.setLayout(layout);
200:
201:                fControlsComposite = new Composite(composite, SWT.NONE);
202:                fControlsComposite.setFont(composite.getFont());
203:                fControlsComposite.setLayoutData(new GridData(GridData.FILL,
204:                        GridData.FILL, true, false));
205:
206:                layout = new GridLayout();
207:                layout.marginHeight = 0;
208:                layout.marginWidth = 0;
209:                layout.numColumns = 1;
210:                fControlsComposite.setLayout(layout);
211:
212:                int nColumns = 3;
213:
214:                layout = new GridLayout();
215:                layout.numColumns = nColumns;
216:
217:                Group group = new Group(fControlsComposite, SWT.NONE);
218:                group.setFont(fControlsComposite.getFont());
219:                group
220:                        .setText(PreferencesMessages.ComplianceConfigurationBlock_compliance_group_label);
221:                group.setLayoutData(new GridData(GridData.FILL, GridData.FILL,
222:                        true, false));
223:                group.setLayout(layout);
224:
225:                String label = PreferencesMessages.ComplianceConfigurationBlock_compiler_compliance_label;
226:                addComboBox(group, label, PREF_COMPLIANCE, values3456,
227:                        values3456Labels, 0);
228:
229:                label = PreferencesMessages.ComplianceConfigurationBlock_default_settings_label;
230:                addCheckBox(group, label, INTR_DEFAULT_COMPLIANCE,
231:                        new String[] { DEFAULT_CONF, USER_CONF }, 0);
232:
233:                int indent = fPixelConverter.convertWidthInCharsToPixels(2);
234:                Control[] otherChildren = group.getChildren();
235:
236:                String[] versions = new String[] { VERSION_1_1, VERSION_1_2,
237:                        VERSION_1_3, VERSION_1_4, VERSION_1_5, VERSION_1_6 };
238:                String[] versionsLabels = new String[] {
239:                        PreferencesMessages.ComplianceConfigurationBlock_version11,
240:                        PreferencesMessages.ComplianceConfigurationBlock_version12,
241:                        PreferencesMessages.ComplianceConfigurationBlock_version13,
242:                        PreferencesMessages.ComplianceConfigurationBlock_version14,
243:                        PreferencesMessages.ComplianceConfigurationBlock_version15,
244:                        PreferencesMessages.ComplianceConfigurationBlock_version16 };
245:
246:                label = PreferencesMessages.ComplianceConfigurationBlock_codegen_targetplatform_label;
247:                addComboBox(group, label, PREF_CODEGEN_TARGET_PLATFORM,
248:                        versions, versionsLabels, indent);
249:
250:                label = PreferencesMessages.ComplianceConfigurationBlock_source_compatibility_label;
251:                addComboBox(group, label, PREF_SOURCE_COMPATIBILITY,
252:                        values3456, values3456Labels, indent);
253:
254:                String[] errorWarningIgnore = new String[] { ERROR, WARNING,
255:                        IGNORE };
256:
257:                String[] errorWarningIgnoreLabels = new String[] {
258:                        PreferencesMessages.ComplianceConfigurationBlock_error,
259:                        PreferencesMessages.ComplianceConfigurationBlock_warning,
260:                        PreferencesMessages.ComplianceConfigurationBlock_ignore };
261:
262:                label = PreferencesMessages.ComplianceConfigurationBlock_pb_assert_as_identifier_label;
263:                addComboBox(group, label, PREF_PB_ASSERT_AS_IDENTIFIER,
264:                        errorWarningIgnore, errorWarningIgnoreLabels, indent);
265:
266:                label = PreferencesMessages.ComplianceConfigurationBlock_pb_enum_as_identifier_label;
267:                addComboBox(group, label, PREF_PB_ENUM_AS_IDENTIFIER,
268:                        errorWarningIgnore, errorWarningIgnoreLabels, indent);
269:
270:                Control[] allChildren = group.getChildren();
271:                fComplianceControls.addAll(Arrays.asList(allChildren));
272:                fComplianceControls.removeAll(Arrays.asList(otherChildren));
273:
274:                layout = new GridLayout();
275:                layout.numColumns = nColumns;
276:
277:                group = new Group(fControlsComposite, SWT.NONE);
278:                group.setFont(fControlsComposite.getFont());
279:                group
280:                        .setText(PreferencesMessages.ComplianceConfigurationBlock_classfiles_group_label);
281:                group.setLayoutData(new GridData(GridData.FILL, GridData.FILL,
282:                        true, false));
283:                group.setLayout(layout);
284:
285:                String[] generateValues = new String[] { GENERATE,
286:                        DO_NOT_GENERATE };
287:                String[] enableDisableValues = new String[] { ENABLED, DISABLED };
288:
289:                label = PreferencesMessages.ComplianceConfigurationBlock_variable_attr_label;
290:                addCheckBox(group, label, PREF_LOCAL_VARIABLE_ATTR,
291:                        generateValues, 0);
292:
293:                label = PreferencesMessages.ComplianceConfigurationBlock_line_number_attr_label;
294:                addCheckBox(group, label, PREF_LINE_NUMBER_ATTR,
295:                        generateValues, 0);
296:
297:                label = PreferencesMessages.ComplianceConfigurationBlock_source_file_attr_label;
298:                addCheckBox(group, label, PREF_SOURCE_FILE_ATTR,
299:                        generateValues, 0);
300:
301:                label = PreferencesMessages.ComplianceConfigurationBlock_codegen_unused_local_label;
302:                addCheckBox(group, label, PREF_CODEGEN_UNUSED_LOCAL,
303:                        new String[] { PRESERVE, OPTIMIZE_OUT }, 0);
304:
305:                label = PreferencesMessages.ComplianceConfigurationBlock_codegen_inline_jsr_bytecode_label;
306:                addCheckBox(group, label, PREF_CODEGEN_INLINE_JSR_BYTECODE,
307:                        enableDisableValues, 0);
308:
309:                fJRE50InfoText = new Link(composite, SWT.WRAP);
310:                fJRE50InfoText.setFont(composite.getFont());
311:                // set a text: not the real one, just for layouting
312:                fJRE50InfoText
313:                        .setText(Messages
314:                                .format(
315:                                        PreferencesMessages.ComplianceConfigurationBlock_jrecompliance_info_project,
316:                                        new String[] { VERSION_1_3, VERSION_1_3 }));
317:                fJRE50InfoText.setVisible(false);
318:                fJRE50InfoText.addSelectionListener(new SelectionListener() {
319:                    public void widgetDefaultSelected(SelectionEvent e) {
320:                        if ("1".equals(e.text)) { //$NON-NLS-1$
321:                            openJREInstallPreferencePage();
322:                        } else {
323:                            openBuildPathPropertyPage();
324:                        }
325:                    }
326:
327:                    public void widgetSelected(SelectionEvent e) {
328:                        widgetDefaultSelected(e);
329:                    }
330:                });
331:                GridData gd = new GridData(GridData.FILL, GridData.FILL, true,
332:                        true);
333:                gd.widthHint = fPixelConverter.convertWidthInCharsToPixels(50);
334:                fJRE50InfoText.setLayoutData(gd);
335:                validateComplianceStatus();
336:
337:                return sc1;
338:            }
339:
340:            protected final void openBuildPathPropertyPage() {
341:                if (getPreferenceContainer() != null) {
342:                    Map data = new HashMap();
343:                    data.put(BuildPathsPropertyPage.DATA_REVEAL_ENTRY,
344:                            JavaRuntime.getDefaultJREContainerEntry());
345:                    getPreferenceContainer().openPage(
346:                            BuildPathsPropertyPage.PROP_ID, data);
347:                }
348:                validateComplianceStatus();
349:            }
350:
351:            protected final void openJREInstallPreferencePage() {
352:                String jreID = BuildPathSupport.JRE_PREF_PAGE_ID;
353:                if (fProject == null && getPreferenceContainer() != null) {
354:                    getPreferenceContainer().openPage(jreID, null);
355:                } else {
356:                    PreferencesUtil.createPreferenceDialogOn(getShell(), jreID,
357:                            new String[] { jreID }, null).open();
358:                }
359:                validateComplianceStatus();
360:            }
361:
362:            /* (non-javadoc)
363:             * Update fields and validate.
364:             * @param changedKey Key that changed, or null, if all changed.
365:             */
366:            protected void validateSettings(Key changedKey, String oldValue,
367:                    String newValue) {
368:                if (!areSettingsEnabled()) {
369:                    return;
370:                }
371:                if (changedKey != null) {
372:                    if (INTR_DEFAULT_COMPLIANCE.equals(changedKey)) {
373:                        updateComplianceEnableState();
374:                        updateComplianceDefaultSettings(true, null);
375:                        fComplianceStatus = validateCompliance();
376:                    } else if (PREF_COMPLIANCE.equals(changedKey)) {
377:                        // set compliance settings to default
378:                        Object oldDefault = setValue(INTR_DEFAULT_COMPLIANCE,
379:                                DEFAULT_CONF);
380:                        updateComplianceEnableState();
381:                        updateComplianceDefaultSettings(USER_CONF
382:                                .equals(oldDefault), oldValue);
383:                        fComplianceStatus = validateCompliance();
384:                        validateComplianceStatus();
385:                    } else if (PREF_SOURCE_COMPATIBILITY.equals(changedKey)) {
386:                        updateAssertEnumAsIdentifierEnableState();
387:                        fComplianceStatus = validateCompliance();
388:                    } else if (PREF_CODEGEN_TARGET_PLATFORM.equals(changedKey)) {
389:                        updateInlineJSREnableState();
390:                        fComplianceStatus = validateCompliance();
391:                    } else if (PREF_PB_ENUM_AS_IDENTIFIER.equals(changedKey)
392:                            || PREF_PB_ASSERT_AS_IDENTIFIER.equals(changedKey)) {
393:                        fComplianceStatus = validateCompliance();
394:                    } else {
395:                        return;
396:                    }
397:                } else {
398:                    updateComplianceEnableState();
399:                    updateAssertEnumAsIdentifierEnableState();
400:                    updateInlineJSREnableState();
401:                    fComplianceStatus = validateCompliance();
402:                    validateComplianceStatus();
403:                }
404:                fContext.statusChanged(fComplianceStatus);
405:            }
406:
407:            private void validateComplianceStatus() {
408:                if (fJRE50InfoText != null && !fJRE50InfoText.isDisposed()) {
409:                    boolean isVisible = false;
410:                    String compliance = getStoredValue(PREF_COMPLIANCE); // get actual value
411:                    IVMInstall install = null;
412:                    if (fProject != null) { // project specific settings: only test if a 50 JRE is installed
413:                        try {
414:                            install = JavaRuntime.getVMInstall(JavaCore
415:                                    .create(fProject));
416:                        } catch (CoreException e) {
417:                            JavaPlugin.log(e);
418:                        }
419:                    } else {
420:                        install = JavaRuntime.getDefaultVMInstall();
421:                    }
422:                    if (install instanceof  IVMInstall2) {
423:                        String compilerCompliance = JavaModelUtil
424:                                .getCompilerCompliance((IVMInstall2) install,
425:                                        compliance);
426:                        if (!compilerCompliance.equals(compliance)) { // Discourage using compiler with version other than compliance
427:                            String[] args = { getVersionLabel(compliance),
428:                                    getVersionLabel(compilerCompliance) };
429:                            if (fProject == null) {
430:                                fJRE50InfoText
431:                                        .setText(Messages
432:                                                .format(
433:                                                        PreferencesMessages.ComplianceConfigurationBlock_jrecompliance_info,
434:                                                        args));
435:                            } else {
436:                                fJRE50InfoText
437:                                        .setText(Messages
438:                                                .format(
439:                                                        PreferencesMessages.ComplianceConfigurationBlock_jrecompliance_info_project,
440:                                                        args));
441:                            }
442:                            isVisible = true;
443:                        }
444:                    }
445:                    fJRE50InfoText.setVisible(isVisible);
446:                }
447:            }
448:
449:            private String getVersionLabel(String version) {
450:                if (JavaModelUtil.isVersionLessThan(version, VERSION_1_5)) {
451:                    return version; // for version <= 1.4, we can use the version as is
452:                }
453:                if (VERSION_1_5.equals(version))
454:                    return PreferencesMessages.ComplianceConfigurationBlock_version15;
455:                return PreferencesMessages.ComplianceConfigurationBlock_version16;
456:            }
457:
458:            private IStatus validateCompliance() {
459:                StatusInfo status = new StatusInfo();
460:                String compliance = getValue(PREF_COMPLIANCE);
461:                String source = getValue(PREF_SOURCE_COMPATIBILITY);
462:                String target = getValue(PREF_CODEGEN_TARGET_PLATFORM);
463:
464:                // compliance must not be smaller than source or target
465:                if (JavaModelUtil.isVersionLessThan(compliance, source)) {
466:                    status
467:                            .setError(PreferencesMessages.ComplianceConfigurationBlock_src_greater_compliance);
468:                    return status;
469:                }
470:
471:                if (JavaModelUtil.isVersionLessThan(compliance, target)) {
472:                    status
473:                            .setError(PreferencesMessages.ComplianceConfigurationBlock_classfile_greater_compliance);
474:                    return status;
475:                }
476:
477:                // target must not be smaller than source
478:                if (!VERSION_1_3.equals(source)
479:                        && JavaModelUtil.isVersionLessThan(target, source)) {
480:                    status
481:                            .setError(PreferencesMessages.ComplianceConfigurationBlock_classfile_greater_source);
482:                    return status;
483:                }
484:
485:                return status;
486:            }
487:
488:            /* (non-Javadoc)
489:             * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#useProjectSpecificSettings(boolean)
490:             */
491:            public void useProjectSpecificSettings(boolean enable) {
492:                super .useProjectSpecificSettings(enable);
493:                validateComplianceStatus();
494:            }
495:
496:            /*
497:             * Update the compliance controls' enable state
498:             */
499:            private void updateComplianceEnableState() {
500:                boolean enabled = checkValue(INTR_DEFAULT_COMPLIANCE, USER_CONF);
501:                for (int i = fComplianceControls.size() - 1; i >= 0; i--) {
502:                    Control curr = (Control) fComplianceControls.get(i);
503:                    curr.setEnabled(enabled);
504:                }
505:            }
506:
507:            private void updateAssertEnumAsIdentifierEnableState() {
508:                if (checkValue(INTR_DEFAULT_COMPLIANCE, USER_CONF)) {
509:                    String compatibility = getValue(PREF_SOURCE_COMPATIBILITY);
510:
511:                    boolean isLessThan14 = VERSION_1_3.equals(compatibility);
512:                    updateRememberedComplianceOption(
513:                            PREF_PB_ASSERT_AS_IDENTIFIER,
514:                            IDX_ASSERT_AS_IDENTIFIER, isLessThan14);
515:
516:                    boolean isLessThan15 = isLessThan14
517:                            || VERSION_1_4.equals(compatibility);
518:                    updateRememberedComplianceOption(
519:                            PREF_PB_ENUM_AS_IDENTIFIER, IDX_ENUM_AS_IDENTIFIER,
520:                            isLessThan15);
521:                }
522:            }
523:
524:            private void updateRememberedComplianceOption(Key prefKey, int idx,
525:                    boolean enabled) {
526:                Combo combo = getComboBox(prefKey);
527:                combo.setEnabled(enabled);
528:
529:                if (!enabled) {
530:                    String val = getValue(prefKey);
531:                    if (!ERROR.equals(val)) {
532:                        setValue(prefKey, ERROR);
533:                        updateCombo(combo);
534:                        fRememberedUserCompliance[idx] = val;
535:                    }
536:                } else {
537:                    String val = fRememberedUserCompliance[idx];
538:                    if (!ERROR.equals(val)) {
539:                        setValue(prefKey, val);
540:                        updateCombo(combo);
541:                    }
542:                }
543:            }
544:
545:            private void updateInlineJSREnableState() {
546:                String target = getValue(PREF_CODEGEN_TARGET_PLATFORM);
547:
548:                boolean enabled = JavaModelUtil.isVersionLessThan(target,
549:                        VERSION_1_5);
550:                Button checkBox = getCheckBox(PREF_CODEGEN_INLINE_JSR_BYTECODE);
551:                checkBox.setEnabled(enabled);
552:
553:                if (!enabled) {
554:                    String val = getValue(PREF_CODEGEN_INLINE_JSR_BYTECODE);
555:                    fRememberedUserCompliance[IDX_INLINE_JSR_BYTECODE] = val;
556:
557:                    if (!ENABLED.equals(val)) {
558:                        setValue(PREF_CODEGEN_INLINE_JSR_BYTECODE, ENABLED);
559:                        updateCheckBox(checkBox);
560:                    }
561:                } else {
562:                    String val = fRememberedUserCompliance[IDX_INLINE_JSR_BYTECODE];
563:                    if (!ENABLED.equals(val)) {
564:                        setValue(PREF_CODEGEN_INLINE_JSR_BYTECODE, val);
565:                        updateCheckBox(checkBox);
566:                    }
567:                }
568:            }
569:
570:            /*
571:             * Set the default compliance values derived from the chosen level
572:             */
573:            private void updateComplianceDefaultSettings(boolean rememberOld,
574:                    String oldComplianceLevel) {
575:                String assertAsId, enumAsId, source, target;
576:                boolean isDefault = checkValue(INTR_DEFAULT_COMPLIANCE,
577:                        DEFAULT_CONF);
578:                String complianceLevel = getValue(PREF_COMPLIANCE);
579:
580:                if (isDefault) {
581:                    if (rememberOld) {
582:                        if (oldComplianceLevel == null) {
583:                            oldComplianceLevel = complianceLevel;
584:                        }
585:
586:                        fRememberedUserCompliance[IDX_ASSERT_AS_IDENTIFIER] = getValue(PREF_PB_ASSERT_AS_IDENTIFIER);
587:                        fRememberedUserCompliance[IDX_ENUM_AS_IDENTIFIER] = getValue(PREF_PB_ENUM_AS_IDENTIFIER);
588:                        fRememberedUserCompliance[IDX_SOURCE_COMPATIBILITY] = getValue(PREF_SOURCE_COMPATIBILITY);
589:                        fRememberedUserCompliance[IDX_CODEGEN_TARGET_PLATFORM] = getValue(PREF_CODEGEN_TARGET_PLATFORM);
590:                        fRememberedUserCompliance[IDX_COMPLIANCE] = oldComplianceLevel;
591:                    }
592:
593:                    if (VERSION_1_4.equals(complianceLevel)) {
594:                        assertAsId = WARNING;
595:                        enumAsId = WARNING;
596:                        source = VERSION_1_3;
597:                        target = VERSION_1_2;
598:                    } else if (VERSION_1_5.equals(complianceLevel)) {
599:                        assertAsId = ERROR;
600:                        enumAsId = ERROR;
601:                        source = VERSION_1_5;
602:                        target = VERSION_1_5;
603:                    } else if (VERSION_1_6.equals(complianceLevel)) {
604:                        assertAsId = ERROR;
605:                        enumAsId = ERROR;
606:                        source = VERSION_1_6;
607:                        target = VERSION_1_6;
608:                    } else {
609:                        assertAsId = IGNORE;
610:                        enumAsId = IGNORE;
611:                        source = VERSION_1_3;
612:                        target = VERSION_1_1;
613:                    }
614:                } else {
615:                    if (rememberOld
616:                            && complianceLevel
617:                                    .equals(fRememberedUserCompliance[IDX_COMPLIANCE])) {
618:                        assertAsId = fRememberedUserCompliance[IDX_ASSERT_AS_IDENTIFIER];
619:                        enumAsId = fRememberedUserCompliance[IDX_ENUM_AS_IDENTIFIER];
620:                        source = fRememberedUserCompliance[IDX_SOURCE_COMPATIBILITY];
621:                        target = fRememberedUserCompliance[IDX_CODEGEN_TARGET_PLATFORM];
622:                    } else {
623:                        updateInlineJSREnableState();
624:                        updateAssertEnumAsIdentifierEnableState();
625:                        return;
626:                    }
627:                }
628:                setValue(PREF_PB_ASSERT_AS_IDENTIFIER, assertAsId);
629:                setValue(PREF_PB_ENUM_AS_IDENTIFIER, enumAsId);
630:                setValue(PREF_SOURCE_COMPATIBILITY, source);
631:                setValue(PREF_CODEGEN_TARGET_PLATFORM, target);
632:                updateControls();
633:                updateInlineJSREnableState();
634:                updateAssertEnumAsIdentifierEnableState();
635:            }
636:
637:            /*
638:             * Evaluate if the current compliance setting correspond to a default setting
639:             */
640:            private String getCurrentCompliance() {
641:                Object complianceLevel = getValue(PREF_COMPLIANCE);
642:                if ((VERSION_1_3.equals(complianceLevel)
643:                        && IGNORE
644:                                .equals(getValue(PREF_PB_ASSERT_AS_IDENTIFIER))
645:                        && IGNORE.equals(getValue(PREF_PB_ENUM_AS_IDENTIFIER))
646:                        && VERSION_1_3
647:                                .equals(getValue(PREF_SOURCE_COMPATIBILITY)) && VERSION_1_1
648:                        .equals(getValue(PREF_CODEGEN_TARGET_PLATFORM)))
649:                        || (VERSION_1_4.equals(complianceLevel)
650:                                && WARNING
651:                                        .equals(getValue(PREF_PB_ASSERT_AS_IDENTIFIER))
652:                                && WARNING
653:                                        .equals(getValue(PREF_PB_ENUM_AS_IDENTIFIER))
654:                                && VERSION_1_3
655:                                        .equals(getValue(PREF_SOURCE_COMPATIBILITY)) && VERSION_1_2
656:                                .equals(getValue(PREF_CODEGEN_TARGET_PLATFORM)))
657:                        || (VERSION_1_5.equals(complianceLevel)
658:                                && ERROR
659:                                        .equals(getValue(PREF_PB_ASSERT_AS_IDENTIFIER))
660:                                && ERROR
661:                                        .equals(getValue(PREF_PB_ENUM_AS_IDENTIFIER))
662:                                && VERSION_1_5
663:                                        .equals(getValue(PREF_SOURCE_COMPATIBILITY)) && VERSION_1_5
664:                                .equals(getValue(PREF_CODEGEN_TARGET_PLATFORM)))
665:                        || (VERSION_1_6.equals(complianceLevel)
666:                                && ERROR
667:                                        .equals(getValue(PREF_PB_ASSERT_AS_IDENTIFIER))
668:                                && ERROR
669:                                        .equals(getValue(PREF_PB_ENUM_AS_IDENTIFIER))
670:                                && VERSION_1_6
671:                                        .equals(getValue(PREF_SOURCE_COMPATIBILITY)) && VERSION_1_6
672:                                .equals(getValue(PREF_CODEGEN_TARGET_PLATFORM)))) {
673:                    return DEFAULT_CONF;
674:                }
675:                return USER_CONF;
676:            }
677:
678:            protected String[] getFullBuildDialogStrings(
679:                    boolean workspaceSettings) {
680:                String title = PreferencesMessages.ComplianceConfigurationBlock_needsbuild_title;
681:                String message;
682:                if (workspaceSettings) {
683:                    message = PreferencesMessages.ComplianceConfigurationBlock_needsfullbuild_message;
684:                } else {
685:                    message = PreferencesMessages.ComplianceConfigurationBlock_needsprojectbuild_message;
686:                }
687:                return new String[] { title, message };
688:            }
689:
690:            /* (non-Javadoc)
691:             * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#performOk()
692:             */
693:            public boolean performOk() {
694:                setValue(INTR_DEFAULT_COMPLIANCE, null);
695:                return super .performOk();
696:            }
697:
698:            /* (non-Javadoc)
699:             * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#performApply()
700:             */
701:            public boolean performApply() {
702:                setValue(INTR_DEFAULT_COMPLIANCE, null);
703:                boolean result = super.performApply();
704:                setValue(INTR_DEFAULT_COMPLIANCE, getCurrentCompliance());
705:                return result;
706:            }
707:
708:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.