Source Code Cross Referenced for NewJavaProjectWizardPageOne.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » ui » wizards » 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.ui.wizards 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*******************************************************************************
0002:         * Copyright (c) 2000, 2007 IBM Corporation and others.
0003:         * All rights reserved. This program and the accompanying materials
0004:         * are made available under the terms of the Eclipse Public License v1.0
0005:         * which accompanies this distribution, and is available at
0006:         * http://www.eclipse.org/legal/epl-v10.html
0007:         *
0008:         * Contributors:
0009:         *     IBM Corporation - initial API and implementation
0010:         *******************************************************************************/package org.eclipse.jdt.ui.wizards;
0011:
0012:        import java.io.File;
0013:        import java.io.IOException;
0014:        import java.net.URI;
0015:        import java.util.ArrayList;
0016:        import java.util.Arrays;
0017:        import java.util.Comparator;
0018:        import java.util.HashMap;
0019:        import java.util.List;
0020:        import java.util.Map;
0021:        import java.util.Observable;
0022:        import java.util.Observer;
0023:
0024:        import org.eclipse.core.filesystem.URIUtil;
0025:
0026:        import org.eclipse.core.runtime.IPath;
0027:        import org.eclipse.core.runtime.IStatus;
0028:        import org.eclipse.core.runtime.Path;
0029:        import org.eclipse.core.runtime.Platform;
0030:
0031:        import org.eclipse.core.resources.IProject;
0032:        import org.eclipse.core.resources.IResource;
0033:        import org.eclipse.core.resources.IWorkspace;
0034:        import org.eclipse.core.resources.ResourcesPlugin;
0035:
0036:        import org.eclipse.swt.SWT;
0037:        import org.eclipse.swt.events.SelectionEvent;
0038:        import org.eclipse.swt.events.SelectionListener;
0039:        import org.eclipse.swt.layout.GridData;
0040:        import org.eclipse.swt.layout.GridLayout;
0041:        import org.eclipse.swt.widgets.Combo;
0042:        import org.eclipse.swt.widgets.Composite;
0043:        import org.eclipse.swt.widgets.Control;
0044:        import org.eclipse.swt.widgets.DirectoryDialog;
0045:        import org.eclipse.swt.widgets.Group;
0046:        import org.eclipse.swt.widgets.Label;
0047:        import org.eclipse.swt.widgets.Link;
0048:
0049:        import org.eclipse.jface.dialogs.Dialog;
0050:        import org.eclipse.jface.dialogs.IDialogConstants;
0051:        import org.eclipse.jface.dialogs.IDialogSettings;
0052:        import org.eclipse.jface.util.Policy;
0053:        import org.eclipse.jface.viewers.TreePath;
0054:        import org.eclipse.jface.viewers.TreeSelection;
0055:        import org.eclipse.jface.wizard.WizardPage;
0056:
0057:        import org.eclipse.ui.IWorkingSet;
0058:        import org.eclipse.ui.PlatformUI;
0059:        import org.eclipse.ui.dialogs.PreferencesUtil;
0060:        import org.eclipse.ui.dialogs.WorkingSetConfigurationBlock;
0061:
0062:        import org.eclipse.jdt.core.IClasspathEntry;
0063:        import org.eclipse.jdt.core.JavaCore;
0064:
0065:        import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
0066:        import org.eclipse.jdt.internal.corext.util.Messages;
0067:
0068:        import org.eclipse.jdt.launching.IVMInstall;
0069:        import org.eclipse.jdt.launching.IVMInstall2;
0070:        import org.eclipse.jdt.launching.IVMInstallType;
0071:        import org.eclipse.jdt.launching.JavaRuntime;
0072:        import org.eclipse.jdt.launching.VMStandin;
0073:        import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
0074:
0075:        import org.eclipse.jdt.ui.JavaUI;
0076:        import org.eclipse.jdt.ui.PreferenceConstants;
0077:
0078:        import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
0079:        import org.eclipse.jdt.internal.ui.JavaPlugin;
0080:        import org.eclipse.jdt.internal.ui.preferences.CompliancePreferencePage;
0081:        import org.eclipse.jdt.internal.ui.preferences.NewJavaProjectPreferencePage;
0082:        import org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage;
0083:        import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
0084:        import org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathSupport;
0085:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.ComboDialogField;
0086:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
0087:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
0088:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
0089:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
0090:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
0091:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
0092:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
0093:        import org.eclipse.jdt.internal.ui.workingsets.JavaWorkingSetUpdater;
0094:
0095:        /**
0096:         * The first page of the New Java Project wizard. This page is typically used in combination with
0097:         * {@link NewJavaProjectWizardPageTwo}. Clients can extend this page to modify the UI: Add, remove
0098:         * or reorder sections.
0099:         * 
0100:         * <p>
0101:         * Clients may instantiate or subclass.
0102:         * </p>
0103:         * <p>
0104:         * <strong>EXPERIMENTAL</strong> This class or interface has been added as part
0105:         * of a work in progress. This API is under review and may still change when finalized. Please send your 
0106:         * comments to bug 160985.
0107:         * </p>
0108:         * @since 3.4
0109:         */
0110:        public class NewJavaProjectWizardPageOne extends WizardPage {
0111:
0112:            /**
0113:             * Request a project name. Fires an event whenever the text field is
0114:             * changed, regardless of its content.
0115:             */
0116:            private final class NameGroup extends Observable implements 
0117:                    IDialogFieldListener {
0118:
0119:                protected final StringDialogField fNameField;
0120:
0121:                public NameGroup() {
0122:                    // text field for project name
0123:                    fNameField = new StringDialogField();
0124:                    fNameField
0125:                            .setLabelText(NewWizardMessages.NewJavaProjectWizardPageOne_NameGroup_label_text);
0126:                    fNameField.setDialogFieldListener(this );
0127:                }
0128:
0129:                public Control createControl(Composite composite) {
0130:                    Composite nameComposite = new Composite(composite, SWT.NONE);
0131:                    nameComposite.setFont(composite.getFont());
0132:                    nameComposite.setLayout(initGridLayout(new GridLayout(2,
0133:                            false), false));
0134:
0135:                    fNameField.doFillIntoGrid(nameComposite, 2);
0136:                    LayoutUtil.setHorizontalGrabbing(fNameField
0137:                            .getTextControl(null));
0138:
0139:                    return nameComposite;
0140:                }
0141:
0142:                protected void fireEvent() {
0143:                    setChanged();
0144:                    notifyObservers();
0145:                }
0146:
0147:                public String getName() {
0148:                    return fNameField.getText().trim();
0149:                }
0150:
0151:                public void postSetFocus() {
0152:                    fNameField.postSetFocusOnDialogField(getShell()
0153:                            .getDisplay());
0154:                }
0155:
0156:                public void setName(String name) {
0157:                    fNameField.setText(name);
0158:                }
0159:
0160:                /* (non-Javadoc)
0161:                 * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener#dialogFieldChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)
0162:                 */
0163:                public void dialogFieldChanged(DialogField field) {
0164:                    fireEvent();
0165:                }
0166:            }
0167:
0168:            /**
0169:             * Request a location. Fires an event whenever the checkbox or the location
0170:             * field is changed, regardless of whether the change originates from the
0171:             * user or has been invoked programmatically.
0172:             */
0173:            private final class LocationGroup extends Observable implements 
0174:                    Observer, IStringButtonAdapter, IDialogFieldListener {
0175:
0176:                protected final SelectionButtonDialogField fWorkspaceRadio;
0177:                protected final SelectionButtonDialogField fExternalRadio;
0178:                protected final StringButtonDialogField fLocation;
0179:
0180:                private String fPreviousExternalLocation;
0181:
0182:                private static final String DIALOGSTORE_LAST_EXTERNAL_LOC = JavaUI.ID_PLUGIN
0183:                        + ".last.external.project"; //$NON-NLS-1$
0184:
0185:                public LocationGroup() {
0186:                    fWorkspaceRadio = new SelectionButtonDialogField(SWT.RADIO);
0187:                    fWorkspaceRadio.setDialogFieldListener(this );
0188:                    fWorkspaceRadio
0189:                            .setLabelText(NewWizardMessages.NewJavaProjectWizardPageOne_LocationGroup_workspace_desc);
0190:
0191:                    fExternalRadio = new SelectionButtonDialogField(SWT.RADIO);
0192:                    fExternalRadio
0193:                            .setLabelText(NewWizardMessages.NewJavaProjectWizardPageOne_LocationGroup_external_desc);
0194:
0195:                    fLocation = new StringButtonDialogField(this );
0196:                    fLocation.setDialogFieldListener(this );
0197:                    fLocation
0198:                            .setLabelText(NewWizardMessages.NewJavaProjectWizardPageOne_LocationGroup_locationLabel_desc);
0199:                    fLocation
0200:                            .setButtonLabel(NewWizardMessages.NewJavaProjectWizardPageOne_LocationGroup_browseButton_desc);
0201:
0202:                    fExternalRadio.attachDialogField(fLocation);
0203:
0204:                    fWorkspaceRadio.setSelection(true);
0205:                    fExternalRadio.setSelection(false);
0206:
0207:                    fPreviousExternalLocation = ""; //$NON-NLS-1$
0208:                }
0209:
0210:                public Control createControl(Composite composite) {
0211:                    final int numColumns = 3;
0212:
0213:                    final Group group = new Group(composite, SWT.NONE);
0214:                    group.setLayout(initGridLayout(new GridLayout(numColumns,
0215:                            false), true));
0216:                    group
0217:                            .setText(NewWizardMessages.NewJavaProjectWizardPageOne_LocationGroup_title);
0218:
0219:                    fWorkspaceRadio.doFillIntoGrid(group, numColumns);
0220:                    fExternalRadio.doFillIntoGrid(group, numColumns);
0221:                    fLocation.doFillIntoGrid(group, numColumns);
0222:                    LayoutUtil.setHorizontalGrabbing(fLocation
0223:                            .getTextControl(null));
0224:
0225:                    return group;
0226:                }
0227:
0228:                protected void fireEvent() {
0229:                    setChanged();
0230:                    notifyObservers();
0231:                }
0232:
0233:                protected String getDefaultPath(String name) {
0234:                    final IPath path = Platform.getLocation().append(name);
0235:                    return path.toOSString();
0236:                }
0237:
0238:                /* (non-Javadoc)
0239:                 * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
0240:                 */
0241:                public void update(Observable o, Object arg) {
0242:                    if (isWorkspaceRadioSelected()) {
0243:                        fLocation.setText(getDefaultPath(fNameGroup.getName()));
0244:                    }
0245:                    fireEvent();
0246:                }
0247:
0248:                public IPath getLocation() {
0249:                    if (isWorkspaceRadioSelected()) {
0250:                        return Platform.getLocation();
0251:                    }
0252:                    return Path.fromOSString(fLocation.getText().trim());
0253:                }
0254:
0255:                public boolean isWorkspaceRadioSelected() {
0256:                    return fWorkspaceRadio.isSelected();
0257:                }
0258:
0259:                /**
0260:                 * Returns <code>true</code> if the location is in the workspace
0261:                 * 
0262:                 * @return <code>true</code> if the location is in the workspace
0263:                 */
0264:                public boolean isLocationInWorkspace() {
0265:                    final String location = fLocationGroup.getLocation()
0266:                            .toOSString();
0267:                    IPath projectPath = Path.fromOSString(location);
0268:                    return Platform.getLocation().isPrefixOf(projectPath);
0269:                }
0270:
0271:                public void setLocation(IPath path) {
0272:                    fWorkspaceRadio.setSelection(path == null);
0273:                    if (path != null) {
0274:                        fLocation.setText(path.toOSString());
0275:                    } else {
0276:                        fLocation.setText(getDefaultPath(fNameGroup.getName()));
0277:                    }
0278:                    fireEvent();
0279:                }
0280:
0281:                /* (non-Javadoc)
0282:                 * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter#changeControlPressed(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)
0283:                 */
0284:                public void changeControlPressed(DialogField field) {
0285:                    final DirectoryDialog dialog = new DirectoryDialog(
0286:                            getShell());
0287:                    dialog
0288:                            .setMessage(NewWizardMessages.NewJavaProjectWizardPageOne_directory_message);
0289:                    String directoryName = fLocation.getText().trim();
0290:                    if (directoryName.length() == 0) {
0291:                        String prevLocation = JavaPlugin.getDefault()
0292:                                .getDialogSettings().get(
0293:                                        DIALOGSTORE_LAST_EXTERNAL_LOC);
0294:                        if (prevLocation != null) {
0295:                            directoryName = prevLocation;
0296:                        }
0297:                    }
0298:
0299:                    if (directoryName.length() > 0) {
0300:                        final File path = new File(directoryName);
0301:                        if (path.exists())
0302:                            dialog.setFilterPath(directoryName);
0303:                    }
0304:                    final String selectedDirectory = dialog.open();
0305:                    if (selectedDirectory != null) {
0306:                        fLocation.setText(selectedDirectory);
0307:                        JavaPlugin.getDefault().getDialogSettings().put(
0308:                                DIALOGSTORE_LAST_EXTERNAL_LOC,
0309:                                selectedDirectory);
0310:                    }
0311:                }
0312:
0313:                /* (non-Javadoc)
0314:                 * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener#dialogFieldChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)
0315:                 */
0316:                public void dialogFieldChanged(DialogField field) {
0317:                    if (field == fWorkspaceRadio) {
0318:                        final boolean checked = fWorkspaceRadio.isSelected();
0319:                        if (checked) {
0320:                            fPreviousExternalLocation = fLocation.getText();
0321:                            fLocation.setText(getDefaultPath(fNameGroup
0322:                                    .getName()));
0323:                        } else {
0324:                            fLocation.setText(fPreviousExternalLocation);
0325:                        }
0326:                    }
0327:                    fireEvent();
0328:                }
0329:            }
0330:
0331:            /**
0332:             * Request a project layout.
0333:             */
0334:            private final class LayoutGroup implements  Observer,
0335:                    SelectionListener {
0336:
0337:                private final SelectionButtonDialogField fStdRadio,
0338:                        fSrcBinRadio;
0339:                private Group fGroup;
0340:                private Link fPreferenceLink;
0341:
0342:                public LayoutGroup() {
0343:                    fStdRadio = new SelectionButtonDialogField(SWT.RADIO);
0344:                    fStdRadio
0345:                            .setLabelText(NewWizardMessages.NewJavaProjectWizardPageOne_LayoutGroup_option_oneFolder);
0346:
0347:                    fSrcBinRadio = new SelectionButtonDialogField(SWT.RADIO);
0348:                    fSrcBinRadio
0349:                            .setLabelText(NewWizardMessages.NewJavaProjectWizardPageOne_LayoutGroup_option_separateFolders);
0350:
0351:                    boolean useSrcBin = PreferenceConstants
0352:                            .getPreferenceStore()
0353:                            .getBoolean(
0354:                                    PreferenceConstants.SRCBIN_FOLDERS_IN_NEWPROJ);
0355:                    fSrcBinRadio.setSelection(useSrcBin);
0356:                    fStdRadio.setSelection(!useSrcBin);
0357:                }
0358:
0359:                public Control createContent(Composite composite) {
0360:                    fGroup = new Group(composite, SWT.NONE);
0361:                    fGroup.setFont(composite.getFont());
0362:                    fGroup.setLayout(initGridLayout(new GridLayout(3, false),
0363:                            true));
0364:                    fGroup
0365:                            .setText(NewWizardMessages.NewJavaProjectWizardPageOne_LayoutGroup_title);
0366:
0367:                    fStdRadio.doFillIntoGrid(fGroup, 3);
0368:                    LayoutUtil.setHorizontalGrabbing(fStdRadio
0369:                            .getSelectionButton(null));
0370:
0371:                    fSrcBinRadio.doFillIntoGrid(fGroup, 2);
0372:
0373:                    fPreferenceLink = new Link(fGroup, SWT.NONE);
0374:                    fPreferenceLink
0375:                            .setText(NewWizardMessages.NewJavaProjectWizardPageOne_LayoutGroup_link_description);
0376:                    fPreferenceLink.setLayoutData(new GridData(GridData.END,
0377:                            GridData.END, false, false));
0378:                    fPreferenceLink.addSelectionListener(this );
0379:
0380:                    updateEnableState();
0381:                    return fGroup;
0382:                }
0383:
0384:                /* (non-Javadoc)
0385:                 * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
0386:                 */
0387:                public void update(Observable o, Object arg) {
0388:                    updateEnableState();
0389:                }
0390:
0391:                private void updateEnableState() {
0392:                    final boolean detect = fDetectGroup.mustDetect();
0393:                    fStdRadio.setEnabled(!detect);
0394:                    fSrcBinRadio.setEnabled(!detect);
0395:                    if (fPreferenceLink != null) {
0396:                        fPreferenceLink.setEnabled(!detect);
0397:                    }
0398:                    if (fGroup != null) {
0399:                        fGroup.setEnabled(!detect);
0400:                    }
0401:                }
0402:
0403:                /**
0404:                 * Return <code>true</code> if the user specified to create 'source' and 'bin' folders.
0405:                 * 
0406:                 * @return returns <code>true</code> if the user specified to create 'source' and 'bin' folders.
0407:                 */
0408:                public boolean isSrcBin() {
0409:                    return fSrcBinRadio.isSelected();
0410:                }
0411:
0412:                /* (non-Javadoc)
0413:                 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
0414:                 */
0415:                public void widgetSelected(SelectionEvent e) {
0416:                    widgetDefaultSelected(e);
0417:                }
0418:
0419:                /* (non-Javadoc)
0420:                 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
0421:                 */
0422:                public void widgetDefaultSelected(SelectionEvent e) {
0423:                    String id = NewJavaProjectPreferencePage.ID;
0424:                    PreferencesUtil.createPreferenceDialogOn(getShell(), id,
0425:                            new String[] { id }, null).open();
0426:                    fDetectGroup.handlePossibleJVMChange();
0427:                    fJREGroup.handlePossibleJVMChange();
0428:                }
0429:            }
0430:
0431:            private final class JREGroup implements  Observer,
0432:                    SelectionListener, IDialogFieldListener {
0433:
0434:                private static final String LAST_SELECTED_EE_SETTINGS_KEY = JavaUI.ID_PLUGIN
0435:                        + ".last.selected.execution.enviroment"; //$NON-NLS-1$
0436:                private static final String LAST_SELECTED_JRE_SETTINGS_KEY = JavaUI.ID_PLUGIN
0437:                        + ".last.selected.project.jre"; //$NON-NLS-1$
0438:                private static final String LAST_SELECTED_JRE_KIND = JavaUI.ID_PLUGIN
0439:                        + ".last.selected.jre.kind"; //$NON-NLS-1$
0440:
0441:                private static final int DEFAULT_JRE = 0;
0442:                private static final int PROJECT_JRE = 1;
0443:                private static final int EE_JRE = 2;
0444:
0445:                private final SelectionButtonDialogField fUseDefaultJRE,
0446:                        fUseProjectJRE, fUseEEJRE;
0447:                private final ComboDialogField fJRECombo;
0448:                private final ComboDialogField fEECombo;
0449:                private Group fGroup;
0450:                private Link fPreferenceLink;
0451:                private IVMInstall[] fInstalledJVMs;
0452:                private String[] fJRECompliance;
0453:                private IExecutionEnvironment[] fInstalledEEs;
0454:                private String[] fEECompliance;
0455:
0456:                public JREGroup() {
0457:                    fUseDefaultJRE = new SelectionButtonDialogField(SWT.RADIO);
0458:                    fUseDefaultJRE.setLabelText(getDefaultJVMLabel());
0459:
0460:                    fUseProjectJRE = new SelectionButtonDialogField(SWT.RADIO);
0461:                    fUseProjectJRE
0462:                            .setLabelText(NewWizardMessages.NewJavaProjectWizardPageOne_JREGroup_specific_compliance);
0463:
0464:                    fJRECombo = new ComboDialogField(SWT.READ_ONLY);
0465:                    fillInstalledJREs(fJRECombo);
0466:                    fJRECombo.setDialogFieldListener(this );
0467:
0468:                    fUseEEJRE = new SelectionButtonDialogField(SWT.RADIO);
0469:                    fUseEEJRE
0470:                            .setLabelText(NewWizardMessages.NewJavaProjectWizardPageOne_JREGroup_specific_EE);
0471:
0472:                    fEECombo = new ComboDialogField(SWT.READ_ONLY);
0473:                    fillExecutionEnvironments(fEECombo);
0474:                    fEECombo.setDialogFieldListener(this );
0475:
0476:                    switch (getLastSelectedJREKind()) {
0477:                    case DEFAULT_JRE:
0478:                        fUseDefaultJRE.setSelection(true);
0479:                        break;
0480:                    case PROJECT_JRE:
0481:                        fUseProjectJRE.setSelection(true);
0482:                        break;
0483:                    case EE_JRE:
0484:                        fUseEEJRE.setSelection(true);
0485:                        break;
0486:                    }
0487:
0488:                    fJRECombo.setEnabled(fUseProjectJRE.isSelected());
0489:                    fEECombo.setEnabled(fUseEEJRE.isSelected());
0490:
0491:                    fUseDefaultJRE.setDialogFieldListener(this );
0492:                    fUseProjectJRE.setDialogFieldListener(this );
0493:                    fUseEEJRE.setDialogFieldListener(this );
0494:                }
0495:
0496:                public Control createControl(Composite composite) {
0497:                    fGroup = new Group(composite, SWT.NONE);
0498:                    fGroup.setFont(composite.getFont());
0499:                    fGroup.setLayout(initGridLayout(new GridLayout(3, false),
0500:                            true));
0501:                    fGroup
0502:                            .setText(NewWizardMessages.NewJavaProjectWizardPageOne_JREGroup_title);
0503:
0504:                    fUseDefaultJRE.doFillIntoGrid(fGroup, 2);
0505:
0506:                    fPreferenceLink = new Link(fGroup, SWT.NONE);
0507:                    fPreferenceLink.setFont(fGroup.getFont());
0508:                    fPreferenceLink
0509:                            .setText(NewWizardMessages.NewJavaProjectWizardPageOne_JREGroup_link_description);
0510:                    fPreferenceLink.setLayoutData(new GridData(GridData.END,
0511:                            GridData.CENTER, false, false));
0512:                    fPreferenceLink.addSelectionListener(this );
0513:
0514:                    fUseProjectJRE.doFillIntoGrid(fGroup, 1);
0515:
0516:                    Combo comboControl = fJRECombo.getComboControl(fGroup);
0517:                    comboControl.setLayoutData(new GridData(GridData.FILL,
0518:                            GridData.CENTER, true, false)); // make sure column 2 is grabbing (but no fill)
0519:                    comboControl.setVisibleItemCount(30);
0520:
0521:                    DialogField.createEmptySpace(fGroup);
0522:
0523:                    fUseEEJRE.doFillIntoGrid(fGroup, 1);
0524:
0525:                    Combo eeComboControl = fEECombo.getComboControl(fGroup);
0526:                    eeComboControl.setLayoutData(new GridData(GridData.FILL,
0527:                            GridData.CENTER, true, false)); // make sure column 2 is grabbing (but no fill)
0528:                    eeComboControl.setVisibleItemCount(30);
0529:
0530:                    DialogField.createEmptySpace(fGroup);
0531:
0532:                    updateEnableState();
0533:                    return fGroup;
0534:                }
0535:
0536:                private void fillInstalledJREs(ComboDialogField comboField) {
0537:                    String selectedItem = getLastSelectedJRE();
0538:                    int selectionIndex = -1;
0539:                    if (fUseProjectJRE.isSelected()) {
0540:                        selectionIndex = comboField.getSelectionIndex();
0541:                        if (selectionIndex != -1) {//paranoia
0542:                            selectedItem = comboField.getItems()[selectionIndex];
0543:                        }
0544:                    }
0545:
0546:                    fInstalledJVMs = getWorkspaceJREs();
0547:                    Arrays.sort(fInstalledJVMs, new Comparator() {
0548:
0549:                        public int compare(Object arg0, Object arg1) {
0550:                            IVMInstall i0 = (IVMInstall) arg0;
0551:                            IVMInstall i1 = (IVMInstall) arg1;
0552:                            if (i1 instanceof  IVMInstall2
0553:                                    && i0 instanceof  IVMInstall2) {
0554:                                String cc0 = JavaModelUtil
0555:                                        .getCompilerCompliance(
0556:                                                (IVMInstall2) i0,
0557:                                                JavaCore.VERSION_1_4);
0558:                                String cc1 = JavaModelUtil
0559:                                        .getCompilerCompliance(
0560:                                                (IVMInstall2) i1,
0561:                                                JavaCore.VERSION_1_4);
0562:                                int result = cc1.compareTo(cc0);
0563:                                if (result != 0)
0564:                                    return result;
0565:                            }
0566:                            return Policy.getComparator().compare(i0.getName(),
0567:                                    i1.getName());
0568:                        }
0569:
0570:                    });
0571:                    selectionIndex = -1;//find new index
0572:                    String[] jreLabels = new String[fInstalledJVMs.length];
0573:                    fJRECompliance = new String[fInstalledJVMs.length];
0574:                    for (int i = 0; i < fInstalledJVMs.length; i++) {
0575:                        jreLabels[i] = fInstalledJVMs[i].getName();
0576:                        if (selectedItem != null
0577:                                && jreLabels[i].equals(selectedItem)) {
0578:                            selectionIndex = i;
0579:                        }
0580:                        if (fInstalledJVMs[i] instanceof  IVMInstall2) {
0581:                            fJRECompliance[i] = JavaModelUtil
0582:                                    .getCompilerCompliance(
0583:                                            (IVMInstall2) fInstalledJVMs[i],
0584:                                            JavaCore.VERSION_1_4);
0585:                        } else {
0586:                            fJRECompliance[i] = JavaCore.VERSION_1_4;
0587:                        }
0588:                    }
0589:                    comboField.setItems(jreLabels);
0590:                    if (selectionIndex == -1) {
0591:                        comboField.selectItem(getDefaultJVMName());
0592:                    } else {
0593:                        comboField.selectItem(selectedItem);
0594:                    }
0595:                }
0596:
0597:                private void fillExecutionEnvironments(
0598:                        ComboDialogField comboField) {
0599:                    String selectedItem = getLastSelectedEE();
0600:                    int selectionIndex = -1;
0601:                    if (fUseEEJRE.isSelected()) {
0602:                        selectionIndex = comboField.getSelectionIndex();
0603:                        if (selectionIndex != -1) {// paranoia
0604:                            selectedItem = comboField.getItems()[selectionIndex];
0605:                        }
0606:                    }
0607:
0608:                    fInstalledEEs = JavaRuntime
0609:                            .getExecutionEnvironmentsManager()
0610:                            .getExecutionEnvironments();
0611:                    Arrays.sort(fInstalledEEs, new Comparator() {
0612:                        public int compare(Object arg0, Object arg1) {
0613:                            return Policy.getComparator().compare(
0614:                                    ((IExecutionEnvironment) arg0).getId(),
0615:                                    ((IExecutionEnvironment) arg1).getId());
0616:                        }
0617:                    });
0618:                    selectionIndex = -1;//find new index
0619:                    String[] eeLabels = new String[fInstalledEEs.length];
0620:                    fEECompliance = new String[fInstalledEEs.length];
0621:                    for (int i = 0; i < fInstalledEEs.length; i++) {
0622:                        eeLabels[i] = fInstalledEEs[i].getId();
0623:                        if (selectedItem != null
0624:                                && eeLabels[i].equals(selectedItem)) {
0625:                            selectionIndex = i;
0626:                        }
0627:                        fEECompliance[i] = JavaModelUtil
0628:                                .getExecutionEnvironmentCompliance(fInstalledEEs[i]);
0629:                    }
0630:                    comboField.setItems(eeLabels);
0631:                    if (selectionIndex == -1) {
0632:                        comboField.selectItem(getDefaultEEName());
0633:                    } else {
0634:                        comboField.selectItem(selectedItem);
0635:                    }
0636:                }
0637:
0638:                private IVMInstall[] getWorkspaceJREs() {
0639:                    List standins = new ArrayList();
0640:                    IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
0641:                    for (int i = 0; i < types.length; i++) {
0642:                        IVMInstallType type = types[i];
0643:                        IVMInstall[] installs = type.getVMInstalls();
0644:                        for (int j = 0; j < installs.length; j++) {
0645:                            IVMInstall install = installs[j];
0646:                            standins.add(new VMStandin(install));
0647:                        }
0648:                    }
0649:                    return ((IVMInstall[]) standins
0650:                            .toArray(new IVMInstall[standins.size()]));
0651:                }
0652:
0653:                private String getDefaultJVMName() {
0654:                    IVMInstall install = JavaRuntime.getDefaultVMInstall();
0655:                    if (install != null) {
0656:                        return install.getName();
0657:                    } else {
0658:                        return NewWizardMessages.NewJavaProjectWizardPageOne_UnknownDefaultJRE_name;
0659:                    }
0660:                }
0661:
0662:                private String getDefaultEEName() {
0663:                    IVMInstall defaultVM = JavaRuntime.getDefaultVMInstall();
0664:
0665:                    IExecutionEnvironment[] environments = JavaRuntime
0666:                            .getExecutionEnvironmentsManager()
0667:                            .getExecutionEnvironments();
0668:                    if (defaultVM != null) {
0669:                        for (int i = 0; i < environments.length; i++) {
0670:                            IVMInstall eeDefaultVM = environments[i]
0671:                                    .getDefaultVM();
0672:                            if (eeDefaultVM != null
0673:                                    && defaultVM.getId().equals(
0674:                                            eeDefaultVM.getId()))
0675:                                return environments[i].getId();
0676:                        }
0677:                    }
0678:
0679:                    String defaultCC;
0680:                    if (defaultVM instanceof  IVMInstall2) {
0681:                        defaultCC = JavaModelUtil.getCompilerCompliance(
0682:                                (IVMInstall2) defaultVM, JavaCore.VERSION_1_4);
0683:                    } else {
0684:                        defaultCC = JavaCore.VERSION_1_4;
0685:                    }
0686:
0687:                    for (int i = 0; i < environments.length; i++) {
0688:                        String eeCompliance = JavaModelUtil
0689:                                .getExecutionEnvironmentCompliance(environments[i]);
0690:                        if (defaultCC.endsWith(eeCompliance))
0691:                            return environments[i].getId();
0692:                    }
0693:
0694:                    return "J2SE-1.5"; //$NON-NLS-1$
0695:                }
0696:
0697:                private String getDefaultJVMLabel() {
0698:                    return Messages
0699:                            .format(
0700:                                    NewWizardMessages.NewJavaProjectWizardPageOne_JREGroup_default_compliance,
0701:                                    getDefaultJVMName());
0702:                }
0703:
0704:                public void update(Observable o, Object arg) {
0705:                    updateEnableState();
0706:                }
0707:
0708:                private void updateEnableState() {
0709:                    final boolean detect = fDetectGroup.mustDetect();
0710:                    fUseDefaultJRE.setEnabled(!detect);
0711:                    fUseProjectJRE.setEnabled(!detect);
0712:                    fUseEEJRE.setEnabled(!detect);
0713:                    fJRECombo
0714:                            .setEnabled(!detect && fUseProjectJRE.isSelected());
0715:                    fEECombo.setEnabled(!detect && fUseEEJRE.isSelected());
0716:                    if (fPreferenceLink != null) {
0717:                        fPreferenceLink.setEnabled(!detect);
0718:                    }
0719:                    if (fGroup != null) {
0720:                        fGroup.setEnabled(!detect);
0721:                    }
0722:                }
0723:
0724:                /* (non-Javadoc)
0725:                 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
0726:                 */
0727:                public void widgetSelected(SelectionEvent e) {
0728:                    widgetDefaultSelected(e);
0729:                }
0730:
0731:                /* (non-Javadoc)
0732:                 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
0733:                 */
0734:                public void widgetDefaultSelected(SelectionEvent e) {
0735:                    String jreID = BuildPathSupport.JRE_PREF_PAGE_ID;
0736:                    String complianceId = CompliancePreferencePage.PREF_ID;
0737:                    Map data = new HashMap();
0738:                    data.put(PropertyAndPreferencePage.DATA_NO_LINK,
0739:                            Boolean.TRUE);
0740:                    PreferencesUtil.createPreferenceDialogOn(getShell(), jreID,
0741:                            new String[] { jreID, complianceId }, data).open();
0742:
0743:                    handlePossibleJVMChange();
0744:                    fDetectGroup.handlePossibleJVMChange();
0745:                }
0746:
0747:                public void handlePossibleJVMChange() {
0748:                    fUseDefaultJRE.setLabelText(getDefaultJVMLabel());
0749:                    fillInstalledJREs(fJRECombo);
0750:                    fillExecutionEnvironments(fEECombo);
0751:                }
0752:
0753:                /* (non-Javadoc)
0754:                 * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener#dialogFieldChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)
0755:                 */
0756:                public void dialogFieldChanged(DialogField field) {
0757:                    updateEnableState();
0758:                    fDetectGroup.handlePossibleJVMChange();
0759:                    if (field == fJRECombo) {
0760:                        if (fUseProjectJRE.isSelected()) {
0761:                            storeSelectionValue(fJRECombo,
0762:                                    LAST_SELECTED_JRE_SETTINGS_KEY);
0763:                        }
0764:                    } else if (field == fEECombo) {
0765:                        if (fUseEEJRE.isSelected()) {
0766:                            storeSelectionValue(fEECombo,
0767:                                    LAST_SELECTED_EE_SETTINGS_KEY);
0768:                        }
0769:                    } else if (field == fUseDefaultJRE) {
0770:                        if (fUseDefaultJRE.isSelected()) {
0771:                            JavaPlugin.getDefault().getDialogSettings().put(
0772:                                    LAST_SELECTED_JRE_KIND, DEFAULT_JRE);
0773:                        }
0774:                    } else if (field == fUseProjectJRE) {
0775:                        if (fUseProjectJRE.isSelected()) {
0776:                            JavaPlugin.getDefault().getDialogSettings().put(
0777:                                    LAST_SELECTED_JRE_KIND, PROJECT_JRE);
0778:                        }
0779:                    } else if (field == fUseEEJRE) {
0780:                        if (fUseEEJRE.isSelected()) {
0781:                            JavaPlugin.getDefault().getDialogSettings().put(
0782:                                    LAST_SELECTED_JRE_KIND, EE_JRE);
0783:                        }
0784:                    }
0785:                }
0786:
0787:                private void storeSelectionValue(ComboDialogField combo,
0788:                        String preferenceKey) {
0789:                    int index = combo.getSelectionIndex();
0790:                    if (index == -1)
0791:                        return;
0792:
0793:                    String item = combo.getItems()[index];
0794:                    JavaPlugin.getDefault().getDialogSettings().put(
0795:                            preferenceKey, item);
0796:                }
0797:
0798:                private int getLastSelectedJREKind() {
0799:                    IDialogSettings settings = JavaPlugin.getDefault()
0800:                            .getDialogSettings();
0801:                    if (settings.get(LAST_SELECTED_JRE_KIND) == null)
0802:                        return DEFAULT_JRE;
0803:
0804:                    return settings.getInt(LAST_SELECTED_JRE_KIND);
0805:                }
0806:
0807:                private String getLastSelectedEE() {
0808:                    IDialogSettings settings = JavaPlugin.getDefault()
0809:                            .getDialogSettings();
0810:                    return settings.get(LAST_SELECTED_EE_SETTINGS_KEY);
0811:                }
0812:
0813:                private String getLastSelectedJRE() {
0814:                    IDialogSettings settings = JavaPlugin.getDefault()
0815:                            .getDialogSettings();
0816:                    return settings.get(LAST_SELECTED_JRE_SETTINGS_KEY);
0817:                }
0818:
0819:                public IVMInstall getSelectedJVM() {
0820:                    if (fUseProjectJRE.isSelected()) {
0821:                        int index = fJRECombo.getSelectionIndex();
0822:                        if (index >= 0 && index < fInstalledJVMs.length) { // paranoia
0823:                            return fInstalledJVMs[index];
0824:                        }
0825:                    } else if (fUseEEJRE.isSelected()) {
0826:
0827:                    }
0828:                    return null;
0829:                }
0830:
0831:                public IPath getJREContainerPath() {
0832:                    if (fUseProjectJRE.isSelected()) {
0833:                        int index = fJRECombo.getSelectionIndex();
0834:                        if (index >= 0 && index < fInstalledJVMs.length) { // paranoia
0835:                            return JavaRuntime
0836:                                    .newJREContainerPath(fInstalledJVMs[index]);
0837:                        }
0838:                    } else if (fUseEEJRE.isSelected()) {
0839:                        int index = fEECombo.getSelectionIndex();
0840:                        if (index >= 0 && index < fInstalledEEs.length) { // paranoia
0841:                            return JavaRuntime
0842:                                    .newJREContainerPath(fInstalledEEs[index]);
0843:                        }
0844:                    }
0845:                    return null;
0846:                }
0847:
0848:                public String getSelectedCompilerCompliance() {
0849:                    if (fUseProjectJRE.isSelected()) {
0850:                        int index = fJRECombo.getSelectionIndex();
0851:                        if (index >= 0 && index < fJRECompliance.length) { // paranoia
0852:                            return fJRECompliance[index];
0853:                        }
0854:                    } else if (fUseEEJRE.isSelected()) {
0855:                        int index = fEECombo.getSelectionIndex();
0856:                        if (index >= 0 && index < fEECompliance.length) { // paranoia
0857:                            return fEECompliance[index];
0858:                        }
0859:                    }
0860:                    return null;
0861:                }
0862:            }
0863:
0864:            private final class WorkingSetGroup {
0865:
0866:                private WorkingSetConfigurationBlock fWorkingSetBlock;
0867:
0868:                public WorkingSetGroup() {
0869:                    String[] workingSetIds = new String[] {
0870:                            JavaWorkingSetUpdater.ID,
0871:                            "org.eclipse.ui.resourceWorkingSetPage" }; //$NON-NLS-1$
0872:                    fWorkingSetBlock = new WorkingSetConfigurationBlock(
0873:                            workingSetIds, JavaPlugin.getDefault()
0874:                                    .getDialogSettings());
0875:                    //fWorkingSetBlock.setDialogMessage(NewWizardMessages.NewJavaProjectWizardPageOne_WorkingSetSelection_message);
0876:                }
0877:
0878:                public Control createControl(Composite composite) {
0879:                    Group workingSetGroup = new Group(composite, SWT.NONE);
0880:                    workingSetGroup.setFont(composite.getFont());
0881:                    workingSetGroup
0882:                            .setText(NewWizardMessages.NewJavaProjectWizardPageOne_WorkingSets_group);
0883:                    workingSetGroup.setLayout(new GridLayout(1, false));
0884:
0885:                    fWorkingSetBlock.createContent(workingSetGroup);
0886:
0887:                    return workingSetGroup;
0888:                }
0889:
0890:                public void setWorkingSets(IWorkingSet[] workingSets) {
0891:                    TreePath[] paths = new TreePath[workingSets.length];
0892:                    for (int i = 0; i < paths.length; i++) {
0893:                        paths[i] = new TreePath(new Object[] { workingSets[i] });
0894:                    }
0895:                    fWorkingSetBlock.setSelection(new TreeSelection(paths));
0896:                }
0897:
0898:                public IWorkingSet[] getSelectedWorkingSets() {
0899:                    return fWorkingSetBlock.getSelectedWorkingSets();
0900:                }
0901:            }
0902:
0903:            /**
0904:             * Show a warning when the project location contains files.
0905:             */
0906:            private final class DetectGroup extends Observable implements 
0907:                    Observer, SelectionListener {
0908:
0909:                private Link fHintText;
0910:                private Label fIcon;
0911:                private boolean fDetect;
0912:
0913:                public DetectGroup() {
0914:                    fDetect = false;
0915:                }
0916:
0917:                public Control createControl(Composite parent) {
0918:
0919:                    Composite composite = new Composite(parent, SWT.NONE);
0920:                    composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP,
0921:                            true, false));
0922:                    GridLayout layout = new GridLayout(2, false);
0923:                    layout.horizontalSpacing = 10;
0924:                    composite.setLayout(layout);
0925:
0926:                    fIcon = new Label(composite, SWT.LEFT);
0927:                    fIcon.setImage(Dialog
0928:                            .getImage(Dialog.DLG_IMG_MESSAGE_WARNING));
0929:                    GridData gridData = new GridData(SWT.LEFT, SWT.CENTER,
0930:                            false, false);
0931:                    fIcon.setLayoutData(gridData);
0932:
0933:                    fHintText = new Link(composite, SWT.WRAP);
0934:                    fHintText.setFont(composite.getFont());
0935:                    fHintText.addSelectionListener(this );
0936:                    gridData = new GridData(GridData.FILL, SWT.FILL, true, true);
0937:                    gridData.widthHint = convertWidthInCharsToPixels(50);
0938:                    gridData.heightHint = convertHeightInCharsToPixels(3);
0939:                    fHintText.setLayoutData(gridData);
0940:
0941:                    handlePossibleJVMChange();
0942:                    return composite;
0943:                }
0944:
0945:                public void handlePossibleJVMChange() {
0946:
0947:                    if (JavaRuntime.getDefaultVMInstall() == null) {
0948:                        fHintText
0949:                                .setText(NewWizardMessages.NewJavaProjectWizardPageOne_NoJREFound_link);
0950:                        fHintText.setVisible(true);
0951:                        fIcon.setImage(Dialog
0952:                                .getImage(Dialog.DLG_IMG_MESSAGE_WARNING));
0953:                        fIcon.setVisible(true);
0954:                        return;
0955:                    }
0956:
0957:                    String selectedCompliance = fJREGroup
0958:                            .getSelectedCompilerCompliance();
0959:                    if (selectedCompliance != null) {
0960:                        String defaultCompliance = JavaCore
0961:                                .getOption(JavaCore.COMPILER_COMPLIANCE);
0962:                        if (selectedCompliance.equals(defaultCompliance)) {
0963:                            fHintText.setVisible(false);
0964:                            fIcon.setVisible(false);
0965:                        } else {
0966:                            fHintText
0967:                                    .setText(Messages
0968:                                            .format(
0969:                                                    NewWizardMessages.NewJavaProjectWizardPageOne_DetectGroup_differendWorkspaceCC_message,
0970:                                                    new String[] {
0971:                                                            defaultCompliance,
0972:                                                            selectedCompliance }));
0973:                            fHintText.setVisible(true);
0974:                            fIcon.setImage(Dialog
0975:                                    .getImage(Dialog.DLG_IMG_MESSAGE_INFO));
0976:                            fIcon.setVisible(true);
0977:                        }
0978:                        return;
0979:                    }
0980:
0981:                    selectedCompliance = JavaCore
0982:                            .getOption(JavaCore.COMPILER_COMPLIANCE);
0983:                    IVMInstall selectedJVM = fJREGroup.getSelectedJVM();
0984:                    if (selectedJVM == null) {
0985:                        selectedJVM = JavaRuntime.getDefaultVMInstall();
0986:                    }
0987:                    String jvmCompliance = JavaCore.VERSION_1_4;
0988:                    if (selectedJVM instanceof  IVMInstall2) {
0989:                        jvmCompliance = JavaModelUtil
0990:                                .getCompilerCompliance(
0991:                                        (IVMInstall2) selectedJVM,
0992:                                        JavaCore.VERSION_1_4);
0993:                    }
0994:                    if (!selectedCompliance.equals(jvmCompliance)
0995:                            && (JavaModelUtil.is50OrHigher(selectedCompliance) || JavaModelUtil
0996:                                    .is50OrHigher(jvmCompliance))) {
0997:                        if (selectedCompliance.equals(JavaCore.VERSION_1_5))
0998:                            selectedCompliance = "5.0"; //$NON-NLS-1$
0999:                        else if (selectedCompliance
1000:                                .equals(JavaCore.VERSION_1_6))
1001:                            selectedCompliance = "6.0"; //$NON-NLS-1$
1002:
1003:                        fHintText
1004:                                .setText(Messages
1005:                                        .format(
1006:                                                NewWizardMessages.NewJavaProjectWizardPageOne_DetectGroup_jre_message,
1007:                                                new String[] {
1008:                                                        selectedCompliance,
1009:                                                        jvmCompliance }));
1010:                        fHintText.setVisible(true);
1011:                        fIcon.setImage(Dialog
1012:                                .getImage(Dialog.DLG_IMG_MESSAGE_WARNING));
1013:                        fIcon.setVisible(true);
1014:                    } else {
1015:                        fHintText.setVisible(false);
1016:                        fIcon.setVisible(false);
1017:                    }
1018:                }
1019:
1020:                private boolean computeDetectState() {
1021:                    if (fLocationGroup.isWorkspaceRadioSelected()) {
1022:                        String name = fNameGroup.getName();
1023:                        if (name.length() == 0
1024:                                || JavaPlugin.getWorkspace().getRoot()
1025:                                        .findMember(name) != null) {
1026:                            return false;
1027:                        } else {
1028:                            final File directory = fLocationGroup.getLocation()
1029:                                    .append(name).toFile();
1030:                            return directory.isDirectory();
1031:                        }
1032:                    } else {
1033:                        final File directory = fLocationGroup.getLocation()
1034:                                .toFile();
1035:                        return directory.isDirectory();
1036:                    }
1037:                }
1038:
1039:                public void update(Observable o, Object arg) {
1040:                    if (o instanceof  LocationGroup) {
1041:                        boolean oldDetectState = fDetect;
1042:                        fDetect = computeDetectState();
1043:
1044:                        if (oldDetectState != fDetect) {
1045:                            setChanged();
1046:                            notifyObservers();
1047:
1048:                            if (fDetect) {
1049:                                fHintText.setVisible(true);
1050:                                fHintText
1051:                                        .setText(NewWizardMessages.NewJavaProjectWizardPageOne_DetectGroup_message);
1052:                                fIcon.setImage(Dialog
1053:                                        .getImage(Dialog.DLG_IMG_MESSAGE_INFO));
1054:                                fIcon.setVisible(true);
1055:                            } else {
1056:                                handlePossibleJVMChange();
1057:                            }
1058:                        }
1059:                    }
1060:                }
1061:
1062:                public boolean mustDetect() {
1063:                    return fDetect;
1064:                }
1065:
1066:                /* (non-Javadoc)
1067:                 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
1068:                 */
1069:                public void widgetSelected(SelectionEvent e) {
1070:                    widgetDefaultSelected(e);
1071:                }
1072:
1073:                /* (non-Javadoc)
1074:                 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
1075:                 */
1076:                public void widgetDefaultSelected(SelectionEvent e) {
1077:                    String jreID = BuildPathSupport.JRE_PREF_PAGE_ID;
1078:                    String complianceId = CompliancePreferencePage.PREF_ID;
1079:                    Map data = new HashMap();
1080:                    data.put(PropertyAndPreferencePage.DATA_NO_LINK,
1081:                            Boolean.TRUE);
1082:                    String id = "JRE".equals(e.text) ? jreID : complianceId; //$NON-NLS-1$
1083:                    PreferencesUtil.createPreferenceDialogOn(getShell(), id,
1084:                            new String[] { jreID, complianceId }, data).open();
1085:
1086:                    fJREGroup.handlePossibleJVMChange();
1087:                    handlePossibleJVMChange();
1088:                }
1089:            }
1090:
1091:            /**
1092:             * Validate this page and show appropriate warnings and error NewWizardMessages.
1093:             */
1094:            private final class Validator implements  Observer {
1095:
1096:                public void update(Observable o, Object arg) {
1097:
1098:                    final IWorkspace workspace = JavaPlugin.getWorkspace();
1099:
1100:                    final String name = fNameGroup.getName();
1101:
1102:                    // check whether the project name field is empty
1103:                    if (name.length() == 0) {
1104:                        setErrorMessage(null);
1105:                        setMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_enterProjectName);
1106:                        setPageComplete(false);
1107:                        return;
1108:                    }
1109:
1110:                    // check whether the project name is valid
1111:                    final IStatus nameStatus = workspace.validateName(name,
1112:                            IResource.PROJECT);
1113:                    if (!nameStatus.isOK()) {
1114:                        setErrorMessage(nameStatus.getMessage());
1115:                        setPageComplete(false);
1116:                        return;
1117:                    }
1118:
1119:                    // check whether project already exists
1120:                    final IProject handle = workspace.getRoot()
1121:                            .getProject(name);
1122:                    if (handle.exists()) {
1123:                        setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_projectAlreadyExists);
1124:                        setPageComplete(false);
1125:                        return;
1126:                    }
1127:
1128:                    IPath projectLocation = ResourcesPlugin.getWorkspace()
1129:                            .getRoot().getLocation().append(name);
1130:                    if (projectLocation.toFile().exists()) {
1131:                        try {
1132:                            //correct casing
1133:                            String canonicalPath = projectLocation.toFile()
1134:                                    .getCanonicalPath();
1135:                            projectLocation = new Path(canonicalPath);
1136:                        } catch (IOException e) {
1137:                            JavaPlugin.log(e);
1138:                        }
1139:
1140:                        String existingName = projectLocation.lastSegment();
1141:                        if (!existingName.equals(fNameGroup.getName())) {
1142:                            setErrorMessage(Messages
1143:                                    .format(
1144:                                            NewWizardMessages.NewJavaProjectWizardPageOne_Message_invalidProjectNameForWorkspaceRoot,
1145:                                            existingName));
1146:                            setPageComplete(false);
1147:                            return;
1148:                        }
1149:
1150:                    }
1151:
1152:                    final String location = fLocationGroup.getLocation()
1153:                            .toOSString();
1154:
1155:                    // check whether location is empty
1156:                    if (location.length() == 0) {
1157:                        setErrorMessage(null);
1158:                        setMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_enterLocation);
1159:                        setPageComplete(false);
1160:                        return;
1161:                    }
1162:
1163:                    // check whether the location is a syntactically correct path
1164:                    if (!Path.EMPTY.isValidPath(location)) {
1165:                        setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_invalidDirectory);
1166:                        setPageComplete(false);
1167:                        return;
1168:                    }
1169:
1170:                    IPath projectPath = Path.fromOSString(location);
1171:
1172:                    if (fLocationGroup.isWorkspaceRadioSelected())
1173:                        projectPath = projectPath.append(fNameGroup.getName());
1174:
1175:                    if (projectPath.toFile().exists()) {//create from existing source			
1176:                        if (Platform.getLocation().isPrefixOf(projectPath)) { //create from existing source in workspace
1177:                            if (!Platform.getLocation().equals(
1178:                                    projectPath.removeLastSegments(1))) {
1179:                                setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_notOnWorkspaceRoot);
1180:                                setPageComplete(false);
1181:                                return;
1182:                            }
1183:
1184:                            if (!projectPath.toFile().exists()) {
1185:                                setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_notExisingProjectOnWorkspaceRoot);
1186:                                setPageComplete(false);
1187:                                return;
1188:                            }
1189:                        }
1190:                    } else if (!fLocationGroup.isWorkspaceRadioSelected()) {//create at non existing external location
1191:                        if (!canCreate(projectPath.toFile())) {
1192:                            setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_cannotCreateAtExternalLocation);
1193:                            setPageComplete(false);
1194:                            return;
1195:                        }
1196:
1197:                        // If we do not place the contents in the workspace validate the
1198:                        // location.
1199:                        final IStatus locationStatus = workspace
1200:                                .validateProjectLocation(handle, projectPath);
1201:                        if (!locationStatus.isOK()) {
1202:                            setErrorMessage(locationStatus.getMessage());
1203:                            setPageComplete(false);
1204:                            return;
1205:                        }
1206:                    }
1207:
1208:                    setPageComplete(true);
1209:
1210:                    setErrorMessage(null);
1211:                    setMessage(null);
1212:                }
1213:
1214:                private boolean canCreate(File file) {
1215:                    while (!file.exists()) {
1216:                        file = file.getParentFile();
1217:                        if (file == null)
1218:                            return false;
1219:                    }
1220:
1221:                    return file.canWrite();
1222:                }
1223:            }
1224:
1225:            private static final String PAGE_NAME = "NewJavaProjectWizardPageOne"; //$NON-NLS-1$
1226:
1227:            private final NameGroup fNameGroup;
1228:            private final LocationGroup fLocationGroup;
1229:            private final LayoutGroup fLayoutGroup;
1230:            private final JREGroup fJREGroup;
1231:            private final DetectGroup fDetectGroup;
1232:            private final Validator fValidator;
1233:            private final WorkingSetGroup fWorkingSetGroup;
1234:
1235:            /**
1236:             * Creates a new {@link NewJavaProjectWizardPageOne}.
1237:             */
1238:            public NewJavaProjectWizardPageOne() {
1239:                super (PAGE_NAME);
1240:                setPageComplete(false);
1241:                setTitle(NewWizardMessages.NewJavaProjectWizardPageOne_page_title);
1242:                setDescription(NewWizardMessages.NewJavaProjectWizardPageOne_page_description);
1243:
1244:                fNameGroup = new NameGroup();
1245:                fLocationGroup = new LocationGroup();
1246:                fJREGroup = new JREGroup();
1247:                fLayoutGroup = new LayoutGroup();
1248:                fWorkingSetGroup = new WorkingSetGroup();
1249:                fDetectGroup = new DetectGroup();
1250:
1251:                // establish connections
1252:                fNameGroup.addObserver(fLocationGroup);
1253:                fDetectGroup.addObserver(fLayoutGroup);
1254:                fDetectGroup.addObserver(fJREGroup);
1255:                fLocationGroup.addObserver(fDetectGroup);
1256:
1257:                // initialize all elements
1258:                fNameGroup.notifyObservers();
1259:
1260:                // create and connect validator
1261:                fValidator = new Validator();
1262:                fNameGroup.addObserver(fValidator);
1263:                fLocationGroup.addObserver(fValidator);
1264:
1265:                // initialize defaults
1266:                setProjectName(""); //$NON-NLS-1$
1267:                setProjectLocationURI(null);
1268:                setWorkingSets(new IWorkingSet[0]);
1269:
1270:                initializeDefaultVM();
1271:            }
1272:
1273:            private void initializeDefaultVM() {
1274:                JavaRuntime.getDefaultVMInstall();
1275:            }
1276:
1277:            /* (non-Javadoc)
1278:             * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
1279:             */
1280:            public void createControl(Composite parent) {
1281:                initializeDialogUnits(parent);
1282:
1283:                final Composite composite = new Composite(parent, SWT.NULL);
1284:                composite.setFont(parent.getFont());
1285:                composite.setLayout(initGridLayout(new GridLayout(1, false),
1286:                        true));
1287:                composite.setLayoutData(new GridData(
1288:                        GridData.HORIZONTAL_ALIGN_FILL));
1289:
1290:                // create UI elements
1291:                Control nameControl = createNameControl(composite);
1292:                nameControl
1293:                        .setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
1294:
1295:                Control locationControl = createLocationControl(composite);
1296:                locationControl.setLayoutData(new GridData(
1297:                        GridData.FILL_HORIZONTAL));
1298:
1299:                Control jreControl = createJRESelectionControl(composite);
1300:                jreControl
1301:                        .setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
1302:
1303:                Control layoutControl = createProjectLayoutControl(composite);
1304:                layoutControl.setLayoutData(new GridData(
1305:                        GridData.FILL_HORIZONTAL));
1306:
1307:                Control workingSetControl = createWorkingSetControl(composite);
1308:                workingSetControl.setLayoutData(new GridData(
1309:                        GridData.FILL_HORIZONTAL));
1310:
1311:                Control infoControl = createInfoControl(composite);
1312:                infoControl
1313:                        .setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
1314:
1315:                setControl(composite);
1316:            }
1317:
1318:            protected void setControl(Control newControl) {
1319:                Dialog.applyDialogFont(newControl);
1320:
1321:                PlatformUI.getWorkbench().getHelpSystem().setHelp(newControl,
1322:                        IJavaHelpContextIds.NEW_JAVAPROJECT_WIZARD_PAGE);
1323:
1324:                super .setControl(newControl);
1325:            }
1326:
1327:            /**
1328:             * Creates the controls for the name field. 
1329:             *  
1330:             * @param composite the parent composite
1331:             * @return the created control
1332:             */
1333:            protected Control createNameControl(Composite composite) {
1334:                return fNameGroup.createControl(composite);
1335:            }
1336:
1337:            /**
1338:             * Creates the controls for the location field. 
1339:             *  
1340:             * @param composite the parent composite
1341:             * @return the created control
1342:             */
1343:            protected Control createLocationControl(Composite composite) {
1344:                return fLocationGroup.createControl(composite);
1345:            }
1346:
1347:            /**
1348:             * Creates the controls for the JRE selection
1349:             *  
1350:             * @param composite the parent composite
1351:             * @return the created control
1352:             */
1353:            protected Control createJRESelectionControl(Composite composite) {
1354:                return fJREGroup.createControl(composite);
1355:            }
1356:
1357:            /**
1358:             * Creates the controls for the project layout selection.
1359:             *  
1360:             * @param composite the parent composite
1361:             * @return the created control
1362:             */
1363:            protected Control createProjectLayoutControl(Composite composite) {
1364:                return fLayoutGroup.createContent(composite);
1365:            }
1366:
1367:            /**
1368:             * Creates the controls for the working set selection. 
1369:             *  
1370:             * @param composite the parent composite
1371:             * @return the created control
1372:             */
1373:            protected Control createWorkingSetControl(Composite composite) {
1374:                return fWorkingSetGroup.createControl(composite);
1375:            }
1376:
1377:            /**
1378:             * Creates the controls for the info section. 
1379:             *  
1380:             * @param composite the parent composite
1381:             * @return the created control
1382:             */
1383:            protected Control createInfoControl(Composite composite) {
1384:                return fDetectGroup.createControl(composite);
1385:            }
1386:
1387:            /**
1388:             * Gets a project name for the new project.
1389:             * 
1390:             * @return the new project resource handle
1391:             */
1392:            public String getProjectName() {
1393:                return fNameGroup.getName();
1394:            }
1395:
1396:            /**
1397:             * Sets the name of the new project
1398:             * 
1399:             * @param name the new name
1400:             */
1401:            public void setProjectName(String name) {
1402:                if (name == null)
1403:                    throw new IllegalArgumentException();
1404:
1405:                fNameGroup.setName(name);
1406:            }
1407:
1408:            /**
1409:             * Returns the current project location path as entered by the user, or <code>null</code>
1410:             * if the project should be created in the workspace. 
1411:
1412:             * @return the project location path or its anticipated initial value.
1413:             */
1414:            public URI getProjectLocationURI() {
1415:                if (fLocationGroup.isLocationInWorkspace()) {
1416:                    return null;
1417:                }
1418:                return URIUtil.toURI(fLocationGroup.getLocation());
1419:            }
1420:
1421:            /**
1422:             * Sets the project location of the new project or <code>null</code> if the project
1423:             * should be created in the workspace
1424:             * 
1425:             * @param uri the new project location
1426:             */
1427:            public void setProjectLocationURI(URI uri) {
1428:                IPath path = uri != null ? URIUtil.toPath(uri) : null;
1429:                fLocationGroup.setLocation(path);
1430:            }
1431:
1432:            /**
1433:             * Returns the compiler compliance to be used for the project, or <code>null</code> to use the workspace
1434:             * compiler compliance.
1435:             * 
1436:             * @return compiler compliance to be used for the project or <code>null</code>
1437:             */
1438:            public String getCompilerCompliance() {
1439:                return fJREGroup.getSelectedCompilerCompliance();
1440:            }
1441:
1442:            /**
1443:             * Returns the default class path entries to be added on new projects. By default this is the JRE container as
1444:             * selected by the user.
1445:             * 
1446:             * @return returns the default class path entries
1447:             */
1448:            public IClasspathEntry[] getDefaultClasspathEntries() {
1449:                IClasspathEntry[] defaultJRELibrary = PreferenceConstants
1450:                        .getDefaultJRELibrary();
1451:                String compliance = getCompilerCompliance();
1452:                IPath jreContainerPath = new Path(JavaRuntime.JRE_CONTAINER);
1453:                if (compliance == null
1454:                        || defaultJRELibrary.length > 1
1455:                        || !jreContainerPath.isPrefixOf(defaultJRELibrary[0]
1456:                                .getPath())) {
1457:                    // use default
1458:                    return defaultJRELibrary;
1459:                }
1460:                IPath newPath = fJREGroup.getJREContainerPath();
1461:                if (newPath != null) {
1462:                    return new IClasspathEntry[] { JavaCore
1463:                            .newContainerEntry(newPath) };
1464:                }
1465:                return defaultJRELibrary;
1466:            }
1467:
1468:            /**
1469:             * Returns the source class path entries to be added on new projects.
1470:             * The underlying resources may not exist. All entries that are returned must be of kind
1471:             * {@link IClasspathEntry#CPE_SOURCE}.
1472:             * 
1473:             * @return returns the source class path entries for the new project
1474:             */
1475:            public IClasspathEntry[] getSourceClasspathEntries() {
1476:                IPath sourceFolderPath = new Path(getProjectName())
1477:                        .makeAbsolute();
1478:
1479:                if (fLayoutGroup.isSrcBin()) {
1480:                    IPath srcPath = new Path(PreferenceConstants
1481:                            .getPreferenceStore().getString(
1482:                                    PreferenceConstants.SRCBIN_SRCNAME));
1483:                    if (srcPath.segmentCount() > 0) {
1484:                        sourceFolderPath = sourceFolderPath.append(srcPath);
1485:                    }
1486:                }
1487:                return new IClasspathEntry[] { JavaCore
1488:                        .newSourceEntry(sourceFolderPath) };
1489:            }
1490:
1491:            /**
1492:             * Returns the source class path entries to be added on new projects.
1493:             * The underlying resource may not exist.
1494:             * 
1495:             * @return returns the default class path entries
1496:             */
1497:            public IPath getOutputLocation() {
1498:                IPath outputLocationPath = new Path(getProjectName())
1499:                        .makeAbsolute();
1500:                if (fLayoutGroup.isSrcBin()) {
1501:                    IPath binPath = new Path(PreferenceConstants
1502:                            .getPreferenceStore().getString(
1503:                                    PreferenceConstants.SRCBIN_BINNAME));
1504:                    if (binPath.segmentCount() > 0) {
1505:                        outputLocationPath = outputLocationPath.append(binPath);
1506:                    }
1507:                }
1508:                return outputLocationPath;
1509:            }
1510:
1511:            /**
1512:             * Returns the working sets to which the new project should be added.
1513:             * 
1514:             * @return the selected working sets to which the new project should be added
1515:             */
1516:            public IWorkingSet[] getWorkingSets() {
1517:                return fWorkingSetGroup.getSelectedWorkingSets();
1518:            }
1519:
1520:            /**
1521:             * Sets the working sets to which the new project should be added.
1522:             * 
1523:             * @param workingSets the initial selected working sets
1524:             */
1525:            public void setWorkingSets(IWorkingSet[] workingSets) {
1526:                if (workingSets == null) {
1527:                    throw new IllegalArgumentException();
1528:                }
1529:                fWorkingSetGroup.setWorkingSets(workingSets);
1530:            }
1531:
1532:            /* (non-Javadoc)
1533:             * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
1534:             */
1535:            public void setVisible(boolean visible) {
1536:                super .setVisible(visible);
1537:                if (visible) {
1538:                    fNameGroup.postSetFocus();
1539:                }
1540:            }
1541:
1542:            private GridLayout initGridLayout(GridLayout layout, boolean margins) {
1543:                layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
1544:                layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
1545:                if (margins) {
1546:                    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
1547:                    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
1548:                } else {
1549:                    layout.marginWidth = 0;
1550:                    layout.marginHeight = 0;
1551:                }
1552:                return layout;
1553:            }
1554:
1555:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.