]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/ui/org/eclipse/jdt/ui/wizards/NewJavaProjectWizardPageOne.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / ui / wizards / NewJavaProjectWizardPageOne.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2012 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.ui.wizards;
12
13 import java.io.File;
14 import java.io.IOException;
15 import java.net.URI;
16 import java.util.ArrayList;
17 import java.util.Arrays;
18 import java.util.HashMap;
19 import java.util.Iterator;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Observable;
23 import java.util.Observer;
24
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.events.SelectionEvent;
27 import org.eclipse.swt.events.SelectionListener;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.layout.GridLayout;
30 import org.eclipse.swt.widgets.Combo;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.swt.widgets.Control;
33 import org.eclipse.swt.widgets.DirectoryDialog;
34 import org.eclipse.swt.widgets.Group;
35 import org.eclipse.swt.widgets.Label;
36 import org.eclipse.swt.widgets.Link;
37
38 import org.eclipse.core.filesystem.URIUtil;
39
40 import org.eclipse.core.runtime.CoreException;
41 import org.eclipse.core.runtime.IPath;
42 import org.eclipse.core.runtime.IProgressMonitor;
43 import org.eclipse.core.runtime.IStatus;
44 import org.eclipse.core.runtime.NullProgressMonitor;
45 import org.eclipse.core.runtime.OperationCanceledException;
46 import org.eclipse.core.runtime.Path;
47 import org.eclipse.core.runtime.Platform;
48 import org.eclipse.core.runtime.SubProgressMonitor;
49
50 import org.eclipse.core.resources.IFolder;
51 import org.eclipse.core.resources.IProject;
52 import org.eclipse.core.resources.IResource;
53 import org.eclipse.core.resources.IWorkspace;
54 import org.eclipse.core.resources.IWorkspaceRoot;
55 import org.eclipse.core.resources.ResourcesPlugin;
56
57 import org.eclipse.jface.dialogs.Dialog;
58 import org.eclipse.jface.dialogs.IDialogConstants;
59 import org.eclipse.jface.dialogs.IDialogSettings;
60 import org.eclipse.jface.viewers.IStructuredSelection;
61 import org.eclipse.jface.viewers.ITreeSelection;
62 import org.eclipse.jface.viewers.TreePath;
63 import org.eclipse.jface.wizard.WizardPage;
64
65 import org.eclipse.ui.IWorkbenchPart;
66 import org.eclipse.ui.IWorkingSet;
67 import org.eclipse.ui.PlatformUI;
68 import org.eclipse.ui.dialogs.PreferencesUtil;
69 import org.eclipse.ui.dialogs.WorkingSetConfigurationBlock;
70
71 import org.eclipse.jdt.core.IClasspathEntry;
72 import org.eclipse.jdt.core.IJavaProject;
73 import org.eclipse.jdt.core.JavaCore;
74
75 import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
76 import org.eclipse.jdt.internal.corext.util.Messages;
77
78 import org.eclipse.jdt.launching.IVMInstall;
79 import org.eclipse.jdt.launching.IVMInstall2;
80 import org.eclipse.jdt.launching.IVMInstallType;
81 import org.eclipse.jdt.launching.JavaRuntime;
82 import org.eclipse.jdt.launching.VMStandin;
83 import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
84
85 import org.eclipse.jdt.ui.JavaUI;
86 import org.eclipse.jdt.ui.PreferenceConstants;
87
88 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
89 import org.eclipse.jdt.internal.ui.JavaPlugin;
90 import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart;
91 import org.eclipse.jdt.internal.ui.preferences.CompliancePreferencePage;
92 import org.eclipse.jdt.internal.ui.preferences.NewJavaProjectPreferencePage;
93 import org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage;
94 import org.eclipse.jdt.internal.ui.util.CoreUtility;
95 import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels;
96 import org.eclipse.jdt.internal.ui.wizards.ClassPathDetector;
97 import org.eclipse.jdt.internal.ui.wizards.JavaProjectWizard;
98 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
99 import org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathSupport;
100 import org.eclipse.jdt.internal.ui.wizards.dialogfields.ComboDialogField;
101 import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
102 import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
103 import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
104 import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
105 import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
106 import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
107 import org.eclipse.jdt.internal.ui.workingsets.IWorkingSetIDs;
108
109 /**
110  * The first page of the New Java Project wizard. This page is typically used in combination with
111  * {@link NewJavaProjectWizardPageTwo}. Clients can extend this page to modify the UI: Add, remove
112  * or reorder sections.
113  *
114  * <p>
115  * Clients may instantiate or subclass.
116  * </p>
117  *
118  * @since 3.4
119  */
120 public class NewJavaProjectWizardPageOne extends WizardPage {
121
122         /**
123          * Request a project name. Fires an event whenever the text field is
124          * changed, regardless of its content.
125          */
126         public final class NameGroup extends Observable implements IDialogFieldListener {
127
128                 public final StringDialogField fNameField;
129
130                 public NameGroup() {
131                         // text field for project name
132                         fNameField= new StringDialogField();
133                         fNameField.generated_3193238318253913111(this);
134                 }
135
136                 public Control createControl(Composite composite) {
137                         Composite nameComposite= new Composite(composite, SWT.NONE);
138                         nameComposite.setFont(composite.getFont());
139                         return fNameField.generated_253327009741664144(nameComposite);
140                 }
141
142                 protected void fireEvent() {
143                         setChanged();
144                         notifyObservers();
145                 }
146
147                 public String getName() {
148                         return fNameField.getText().trim();
149                 }
150
151                 public void postSetFocus() {
152                         fNameField.postSetFocusOnDialogField(getShell().getDisplay());
153                 }
154
155                 public void setName(String name) {
156                         fNameField.setText(name);
157                 }
158
159                 /* (non-Javadoc)
160                  * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener#dialogFieldChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)
161                  */
162                 public void dialogFieldChanged(DialogField field) {
163                         fireEvent();
164                 }
165         }
166
167         /**
168          * Request a location. Fires an event whenever the checkbox or the location
169          * field is changed, regardless of whether the change originates from the
170          * user or has been invoked programmatically.
171          */
172         public final class LocationGroup extends Observable implements Observer, IStringButtonAdapter, IDialogFieldListener {
173
174                 public final SelectionButtonDialogField fUseDefaults;
175                 public final StringButtonDialogField fLocation;
176
177                 public String fPreviousExternalLocation;
178
179                 private static final String DIALOGSTORE_LAST_EXTERNAL_LOC= JavaUI.ID_PLUGIN + ".last.external.project"; //$NON-NLS-1$
180
181                 public LocationGroup() {
182                         fUseDefaults= new SelectionButtonDialogField(SWT.CHECK);
183                         fUseDefaults.setDialogFieldListener(this);
184                         fUseDefaults.setLabelText(NewWizardMessages.NewJavaProjectWizardPageOne_LocationGroup_location_desc);
185
186                         fLocation= new StringButtonDialogField(this);
187                         fLocation.generated_5234504517016112488(this);
188
189                         fPreviousExternalLocation= ""; //$NON-NLS-1$
190                 }
191
192                 public Control createControl(Composite composite) {
193                         final int numColumns= 4;
194
195                         final Composite locationComposite= new Composite(composite, SWT.NONE);
196                         fLocation.generated_643901326608760342(this, numColumns, locationComposite);
197
198                         return locationComposite;
199                 }
200
201                 protected void fireEvent() {
202                         setChanged();
203                         notifyObservers();
204                 }
205
206                 protected String getDefaultPath(String name) {
207                         final IPath path= Platform.getLocation().append(name);
208                         return path.toOSString();
209                 }
210
211                 /* (non-Javadoc)
212                  * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
213                  */
214                 public void update(Observable o, Object arg) {
215                         if (isUseDefaultSelected()) {
216                                 fLocation.setText(getDefaultPath(fNameGroup.getName()));
217                         }
218                         fireEvent();
219                 }
220
221                 public IPath getLocation() {
222                         if (isUseDefaultSelected()) {
223                                 return Platform.getLocation();
224                         }
225                         return Path.fromOSString(fLocation.getText().trim());
226                 }
227
228                 public boolean isUseDefaultSelected() {
229                         return fUseDefaults.isSelected();
230                 }
231
232                 public void setLocation(IPath path) {
233                         fUseDefaults.setSelection(path == null);
234                         if (path != null) {
235                                 fLocation.setText(path.toOSString());
236                         } else {
237                                 fLocation.setText(getDefaultPath(fNameGroup.getName()));
238                         }
239                         fireEvent();
240                 }
241
242                 /* (non-Javadoc)
243                  * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter#changeControlPressed(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)
244                  */
245                 public void changeControlPressed(DialogField field) {
246                         final DirectoryDialog dialog= new DirectoryDialog(getShell());
247                         dialog.setMessage(NewWizardMessages.NewJavaProjectWizardPageOne_directory_message);
248                         String directoryName = fLocation.getText().trim();
249                         if (directoryName.length() == 0) {
250                                 String prevLocation= JavaPlugin.getDefault().getDialogSettings().get(DIALOGSTORE_LAST_EXTERNAL_LOC);
251                                 if (prevLocation != null) {
252                                         directoryName= prevLocation;
253                                 }
254                         }
255
256                         if (directoryName.length() > 0) {
257                                 final File path = new File(directoryName);
258                                 if (path.exists())
259                                         dialog.setFilterPath(directoryName);
260                         }
261                         final String selectedDirectory = dialog.open();
262                         if (selectedDirectory != null) {
263                                 String oldDirectory= fLocation.generated_6444432378694638790(selectedDirectory);
264                                 String lastSegment= new Path(selectedDirectory).lastSegment();
265                                 if (lastSegment != null && (fNameGroup.getName().length() == 0 || fNameGroup.getName().equals(oldDirectory))) {
266                                         fNameGroup.setName(lastSegment);
267                                 }
268                                 JavaPlugin.getDefault().getDialogSettings().put(DIALOGSTORE_LAST_EXTERNAL_LOC, selectedDirectory);
269                         }
270                 }
271
272                 /* (non-Javadoc)
273                  * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener#dialogFieldChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)
274                  */
275                 public void dialogFieldChanged(DialogField field) {
276                         if (field == fUseDefaults) {
277                                 final boolean checked= fUseDefaults.isSelected();
278                                 if (checked) {
279                                         fPreviousExternalLocation= fLocation.getText();
280                                         fLocation.setText(getDefaultPath(fNameGroup.getName()));
281                                         fLocation.setEnabled(false);
282                                 } else {
283                                         fLocation.generated_3726504999918786352(this);
284                                 }
285                         }
286                         fireEvent();
287                 }
288
289                 public URI generated_4065803390293803522() {
290                         if (isUseDefaultSelected()) {
291                                 return null;
292                         }
293                         return URIUtil.toURI(getLocation());
294                 }
295         }
296
297         /**
298          * Request a project layout.
299          */
300         public final class LayoutGroup implements Observer, SelectionListener {
301
302                 public final SelectionButtonDialogField fStdRadio;
303                 public final SelectionButtonDialogField fSrcBinRadio;
304                 public Group fGroup;
305                 public Link fPreferenceLink;
306
307                 public LayoutGroup() {
308                         fStdRadio= new SelectionButtonDialogField(SWT.RADIO);
309                         fStdRadio.setLabelText(NewWizardMessages.NewJavaProjectWizardPageOne_LayoutGroup_option_oneFolder);
310
311                         fSrcBinRadio= new SelectionButtonDialogField(SWT.RADIO);
312                         fSrcBinRadio.generated_2986520533270641386(this);
313                 }
314
315
316                 public Control createContent(Composite composite) {
317                         fGroup= new Group(composite, SWT.NONE);
318                         fGroup.setFont(composite.getFont());
319                         fGroup.setLayout(initGridLayout(new GridLayout(3, false), true));
320                         fGroup.setText(NewWizardMessages.NewJavaProjectWizardPageOne_LayoutGroup_title);
321
322                         return fStdRadio.generated_8796833943613112164(this);
323                 }
324
325
326                 /* (non-Javadoc)
327                  * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
328                  */
329                 public void update(Observable o, Object arg) {
330                         updateEnableState();
331                 }
332
333                 public void updateEnableState() {
334                         if (fDetectGroup == null)
335                                 return;
336                         
337                         final boolean detect= fDetectGroup.mustDetect();
338                         fStdRadio.setEnabled(!detect);
339                         fSrcBinRadio.setEnabled(!detect);
340                         if (fPreferenceLink != null) {
341                                 fPreferenceLink.setEnabled(!detect);
342                         }
343                         if (fGroup != null) {
344                                 fGroup.setEnabled(!detect);
345                         }
346                 }
347
348                 /**
349                  * Return <code>true</code> if the user specified to create 'source' and 'bin' folders.
350                  *
351                  * @return returns <code>true</code> if the user specified to create 'source' and 'bin' folders.
352                  */
353                 public boolean isSrcBin() {
354                         return fSrcBinRadio.isSelected();
355                 }
356
357                 /* (non-Javadoc)
358                  * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
359                  */
360                 public void widgetSelected(SelectionEvent e) {
361                         widgetDefaultSelected(e);
362                 }
363
364                 /* (non-Javadoc)
365                  * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
366                  */
367                 public void widgetDefaultSelected(SelectionEvent e) {
368                         String id= NewJavaProjectPreferencePage.ID;
369                         PreferencesUtil.createPreferenceDialogOn(getShell(), id, new String[] { id }, null).open();
370                         fDetectGroup.handlePossibleJVMChange();
371                         fJREGroup.handlePossibleJVMChange();
372                 }
373         }
374
375         public final class JREGroup implements Observer, SelectionListener, IDialogFieldListener {
376
377                 private static final String LAST_SELECTED_EE_SETTINGS_KEY= JavaUI.ID_PLUGIN + ".last.selected.execution.enviroment"; //$NON-NLS-1$
378                 private static final String LAST_SELECTED_JRE_SETTINGS_KEY= JavaUI.ID_PLUGIN + ".last.selected.project.jre"; //$NON-NLS-1$
379 //              private static final String LAST_SELECTED_JRE_KIND= JavaUI.ID_PLUGIN + ".last.selected.jre.kind"; // used before EE became default
380                 public static final String LAST_SELECTED_JRE_KIND2= JavaUI.ID_PLUGIN + ".last.selected.jre.kind2"; //$NON-NLS-1$
381
382                 private static final int DEFAULT_JRE= 0;
383                 public static final int PROJECT_JRE= 1;
384                 public static final int EE_JRE= 2;
385
386                 public final SelectionButtonDialogField fUseDefaultJRE;
387                 public final SelectionButtonDialogField fUseProjectJRE;
388                 public final SelectionButtonDialogField fUseEEJRE;
389                 public final ComboDialogField fJRECombo;
390                 public final ComboDialogField fEECombo;
391                 private Group fGroup;
392                 public Link fPreferenceLink;
393                 public IVMInstall[] fInstalledJVMs;
394                 public String[] fJRECompliance;
395                 public IExecutionEnvironment[] fInstalledEEs;
396                 public String[] fEECompliance;
397
398                 public JREGroup() {
399                         fUseDefaultJRE= new SelectionButtonDialogField(SWT.RADIO);
400                         fUseDefaultJRE.setLabelText(getDefaultJVMLabel());
401
402                         fUseProjectJRE= new SelectionButtonDialogField(SWT.RADIO);
403                         fUseProjectJRE.setLabelText(NewWizardMessages.NewJavaProjectWizardPageOne_JREGroup_specific_compliance);
404
405                         fJRECombo= new ComboDialogField(SWT.READ_ONLY);
406                         fillInstalledJREs(fJRECombo);
407                         fJRECombo.setDialogFieldListener(this);
408
409                         fUseEEJRE= new SelectionButtonDialogField(SWT.RADIO);
410                         fUseEEJRE.setLabelText(NewWizardMessages.NewJavaProjectWizardPageOne_JREGroup_specific_EE);
411
412                         fEECombo= new ComboDialogField(SWT.READ_ONLY);
413                         fillExecutionEnvironments(fEECombo);
414                         fEECombo.setDialogFieldListener(this);
415
416                         switch (getLastSelectedJREKind()) {
417                                 case DEFAULT_JRE:
418                                         fUseDefaultJRE.setSelection(true);
419                                         break;
420                                 case PROJECT_JRE:
421                                         fUseProjectJRE.setSelection(true);
422                                         break;
423                                 case EE_JRE:
424                                         fUseEEJRE.setSelection(true);
425                                         break;
426                         }
427
428                         fUseProjectJRE.generated_1822827867514341499(this);
429                         fUseEEJRE.setDialogFieldListener(this);
430                 }
431
432                 public Control createControl(Composite composite) {
433                         fGroup= new Group(composite, SWT.NONE);
434                         fGroup.setFont(composite.getFont());
435                         fGroup.setLayout(initGridLayout(new GridLayout(2, false), true));
436                         fGroup.setText(NewWizardMessages.NewJavaProjectWizardPageOne_JREGroup_title);
437
438                         fUseEEJRE.doFillIntoGrid(fGroup, 1);
439                         Combo eeComboControl= fEECombo.getComboControl(fGroup);
440                         eeComboControl.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
441                         
442                         fUseProjectJRE.doFillIntoGrid(fGroup, 1);
443                         Combo comboControl= fJRECombo.getComboControl(fGroup);
444                         comboControl.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
445
446                         fUseDefaultJRE.doFillIntoGrid(fGroup, 1);
447
448                         fPreferenceLink= new Link(fGroup, SWT.NONE);
449                         fPreferenceLink.setFont(fGroup.getFont());
450                         fPreferenceLink.setText(NewWizardMessages.NewJavaProjectWizardPageOne_JREGroup_link_description);
451                         fPreferenceLink.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
452                         fPreferenceLink.addSelectionListener(this);
453
454                         updateEnableState();
455                         return fGroup;
456                 }
457
458
459                 private void fillInstalledJREs(ComboDialogField comboField) {
460                         String selectedItem= getLastSelectedJRE();
461                         int selectionIndex= -1;
462                         comboField.generated_14267488333256409(JREGroup.this, selectedItem);
463                 }
464
465                 private void fillExecutionEnvironments(ComboDialogField comboField) {
466                         comboField.generated_5411689368033140336(JREGroup.this);
467                 }
468
469                 public IVMInstall[] getWorkspaceJREs() {
470                         List<VMStandin> standins = new ArrayList<VMStandin>();
471                         IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
472                         for (int i = 0; i < types.length; i++) {
473                                 IVMInstallType type = types[i];
474                                 IVMInstall[] installs = type.getVMInstalls();
475                                 for (int j = 0; j < installs.length; j++) {
476                                         IVMInstall install = installs[j];
477                                         standins.add(new VMStandin(install));
478                                 }
479                         }
480                         return standins.toArray(new IVMInstall[standins.size()]);
481                 }
482
483                 public String getDefaultJVMName() {
484                         IVMInstall install= JavaRuntime.getDefaultVMInstall();
485                         if (install != null) {
486                                 return install.getName();
487                         } else {
488                                 return NewWizardMessages.NewJavaProjectWizardPageOne_UnknownDefaultJRE_name;
489                         }
490                 }
491
492                 public String getDefaultEEName() {
493                         IVMInstall defaultVM= JavaRuntime.getDefaultVMInstall();
494
495                         IExecutionEnvironment[] environments= JavaRuntime.getExecutionEnvironmentsManager().getExecutionEnvironments();
496                         if (defaultVM != null) {
497                                 for (int i= 0; i < environments.length; i++) {
498                                         IVMInstall eeDefaultVM= environments[i].getDefaultVM();
499                                         if (eeDefaultVM != null && defaultVM.getId().equals(eeDefaultVM.getId()))
500                                                 return environments[i].getId();
501                                 }
502                         }
503
504                         String defaultCC;
505                         if (defaultVM instanceof IVMInstall2) {
506                                 defaultCC= JavaModelUtil.getCompilerCompliance((IVMInstall2)defaultVM, JavaCore.VERSION_1_4);
507                         } else {
508                                 defaultCC= JavaCore.VERSION_1_4;
509                         }
510
511                         for (int i= 0; i < environments.length; i++) {
512                                 String eeCompliance= JavaModelUtil.getExecutionEnvironmentCompliance(environments[i]);
513                                 if (defaultCC.endsWith(eeCompliance))
514                                         return environments[i].getId();
515                         }
516
517                         return "JavaSE-1.6"; //$NON-NLS-1$
518                 }
519
520                 private String getDefaultJVMLabel() {
521                         return Messages.format(NewWizardMessages.NewJavaProjectWizardPageOne_JREGroup_default_compliance, getDefaultJVMName());
522                 }
523
524                 public void update(Observable o, Object arg) {
525                         updateEnableState();
526                 }
527
528                 private void updateEnableState() {
529                         final boolean detect= fDetectGroup.mustDetect();
530                         fUseDefaultJRE.setEnabled(!detect);
531                         fUseProjectJRE.setEnabled(!detect);
532                         fUseEEJRE.generated_7787109378699083042(this, detect);
533                         if (fGroup != null) {
534                                 fGroup.setEnabled(!detect);
535                         }
536                 }
537
538                 /* (non-Javadoc)
539                  * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
540                  */
541                 public void widgetSelected(SelectionEvent e) {
542                         widgetDefaultSelected(e);
543                 }
544
545                 /* (non-Javadoc)
546                  * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
547                  */
548                 public void widgetDefaultSelected(SelectionEvent e) {
549                         String jreID= BuildPathSupport.JRE_PREF_PAGE_ID;
550                         String eeID= BuildPathSupport.EE_PREF_PAGE_ID;
551                         String complianceId= CompliancePreferencePage.PREF_ID;
552                         Map<String, Boolean> data= new HashMap<String, Boolean>();
553                         data.put(PropertyAndPreferencePage.DATA_NO_LINK, Boolean.TRUE);
554                         PreferencesUtil.createPreferenceDialogOn(getShell(), jreID, new String[] { jreID, complianceId , eeID }, data).open();
555
556                         handlePossibleJVMChange();
557                         fDetectGroup.handlePossibleJVMChange();
558                 }
559
560                 public void handlePossibleJVMChange() {
561                         fUseDefaultJRE.setLabelText(getDefaultJVMLabel());
562                         fillInstalledJREs(fJRECombo);
563                         fillExecutionEnvironments(fEECombo);
564                 }
565
566                 /* (non-Javadoc)
567                  * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener#dialogFieldChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)
568                  */
569                 public void dialogFieldChanged(DialogField field) {
570                         updateEnableState();
571                         fDetectGroup.handlePossibleJVMChange();
572                         if (field == fJRECombo) {
573                                 if (fUseProjectJRE.isSelected()) {
574                                         storeSelectionValue(fJRECombo, LAST_SELECTED_JRE_SETTINGS_KEY);
575                                 }
576                         } else if (field == fEECombo) {
577                                 if (fUseEEJRE.isSelected()) {
578                                         storeSelectionValue(fEECombo, LAST_SELECTED_EE_SETTINGS_KEY);
579                                 }
580                         } else if (field == fUseDefaultJRE) {
581                                 if (fUseDefaultJRE.isSelected()) {
582                                         JavaPlugin.getDefault().getDialogSettings().put(LAST_SELECTED_JRE_KIND2, DEFAULT_JRE);
583                                         fUseProjectJRE.setSelection(false);
584                                         fUseEEJRE.setSelection(false);
585                                 }
586                         } else
587                                 fUseDefaultJRE.generated_8694771703323010156(this, field);
588                 }
589
590                 private void storeSelectionValue(ComboDialogField combo, String preferenceKey) {
591                         combo.generated_3376758848531533062(preferenceKey);
592                 }
593
594                 private int getLastSelectedJREKind() {
595                         IDialogSettings settings= JavaPlugin.getDefault().getDialogSettings();
596                         if (settings.get(LAST_SELECTED_JRE_KIND2) == null)
597                                 return EE_JRE;
598
599                         return settings.getInt(LAST_SELECTED_JRE_KIND2);
600                 }
601
602                 public String getLastSelectedEE() {
603                         IDialogSettings settings= JavaPlugin.getDefault().getDialogSettings();
604                         return settings.get(LAST_SELECTED_EE_SETTINGS_KEY);
605                 }
606
607                 private String getLastSelectedJRE() {
608                         IDialogSettings settings= JavaPlugin.getDefault().getDialogSettings();
609                         return settings.get(LAST_SELECTED_JRE_SETTINGS_KEY);
610                 }
611
612                 public IVMInstall getSelectedJVM() {
613                         if (fUseProjectJRE.isSelected()) {
614                                 int index= fJRECombo.getSelectionIndex();
615                                 if (index >= 0 && index < fInstalledJVMs.length) { // paranoia
616                                         return fInstalledJVMs[index];
617                                 }
618                         } else if (fUseEEJRE.isSelected()) {
619
620                         }
621                         return null;
622                 }
623
624                 public IPath getJREContainerPath() {
625                         if (fUseProjectJRE.isSelected()) {
626                                 int index= fJRECombo.getSelectionIndex();
627                                 if (index >= 0 && index < fInstalledJVMs.length) { // paranoia
628                                         return JavaRuntime.newJREContainerPath(fInstalledJVMs[index]);
629                                 }
630                         } else if (fUseEEJRE.isSelected()) {
631                                 int index= fEECombo.getSelectionIndex();
632                                 if (index >= 0 && index < fInstalledEEs.length) { // paranoia
633                                         return JavaRuntime.newJREContainerPath(fInstalledEEs[index]);
634                                 }
635                         }
636                         return null;
637                 }
638
639                 public String getSelectedCompilerCompliance() {
640                         if (fUseProjectJRE.isSelected()) {
641                                 int index= fJRECombo.getSelectionIndex();
642                                 if (index >= 0 && index < fJRECompliance.length) { // paranoia
643                                         return fJRECompliance[index];
644                                 }
645                         } else if (fUseEEJRE.isSelected()) {
646                                 int index= fEECombo.getSelectionIndex();
647                                 if (index >= 0 && index < fEECompliance.length) { // paranoia
648                                         return fEECompliance[index];
649                                 }
650                         }
651                         return null;
652                 }
653         }
654
655         private final class WorkingSetGroup {
656
657                 private WorkingSetConfigurationBlock fWorkingSetBlock;
658
659                 public WorkingSetGroup() {
660                         String[] workingSetIds= new String[] { IWorkingSetIDs.JAVA, IWorkingSetIDs.RESOURCE };
661                         fWorkingSetBlock= new WorkingSetConfigurationBlock(workingSetIds, JavaPlugin.getDefault().getDialogSettings());
662                         //fWorkingSetBlock.setDialogMessage(NewWizardMessages.NewJavaProjectWizardPageOne_WorkingSetSelection_message);
663                 }
664
665                 public Control createControl(Composite composite) {
666                         Group workingSetGroup= new Group(composite, SWT.NONE);
667                         workingSetGroup.setFont(composite.getFont());
668                         workingSetGroup.setText(NewWizardMessages.NewJavaProjectWizardPageOne_WorkingSets_group);
669                         workingSetGroup.setLayout(new GridLayout(1, false));
670
671                         fWorkingSetBlock.createContent(workingSetGroup);
672
673                         return workingSetGroup;
674                 }
675
676
677                 public void setWorkingSets(IWorkingSet[] workingSets) {
678                         fWorkingSetBlock.setWorkingSets(workingSets);
679                 }
680
681                 public IWorkingSet[] getSelectedWorkingSets() {
682                         return fWorkingSetBlock.getSelectedWorkingSets();
683                 }
684         }
685
686         /**
687          * Show a warning when the project location contains files.
688          */
689         private final class DetectGroup extends Observable implements Observer, SelectionListener {
690
691                 private Link fHintText;
692                 private Label fIcon;
693                 private boolean fDetect;
694
695                 public DetectGroup() {
696                         fDetect= false;
697                 }
698
699                 public Control createControl(Composite parent) {
700
701                         Composite composite= new Composite(parent, SWT.NONE);
702                         composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
703                         GridLayout layout= new GridLayout(2, false);
704                         layout.horizontalSpacing= 10;
705                         composite.setLayout(layout);
706
707                         fIcon= new Label(composite, SWT.LEFT);
708                         fIcon.setImage(Dialog.getImage(Dialog.DLG_IMG_MESSAGE_WARNING));
709                         GridData gridData= new GridData(SWT.LEFT, SWT.TOP, false, false);
710                         fIcon.setLayoutData(gridData);
711
712                         fHintText= new Link(composite, SWT.WRAP);
713                         fHintText.setFont(composite.getFont());
714                         fHintText.addSelectionListener(this);
715                         gridData= new GridData(GridData.FILL, SWT.FILL, true, true);
716                         gridData.widthHint= convertWidthInCharsToPixels(50);
717                         gridData.heightHint= convertHeightInCharsToPixels(3);
718                         fHintText.setLayoutData(gridData);
719
720                         handlePossibleJVMChange();
721                         return composite;
722                 }
723
724                 public void handlePossibleJVMChange() {
725
726                         if (JavaRuntime.getDefaultVMInstall() == null) {
727                                 fHintText.setText(NewWizardMessages.NewJavaProjectWizardPageOne_NoJREFound_link);
728                                 fHintText.setVisible(true);
729                                 fIcon.setImage(Dialog.getImage(Dialog.DLG_IMG_MESSAGE_WARNING));
730                                 fIcon.setVisible(true);
731                                 return;
732                         }
733
734                         String selectedCompliance= fJREGroup.getSelectedCompilerCompliance();
735                         if (selectedCompliance != null) {
736                                 String defaultCompliance= JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE);
737                                 if (selectedCompliance.equals(defaultCompliance)) {
738                                         fHintText.setVisible(false);
739                                         fIcon.setVisible(false);
740                                 } else {
741                                         fHintText.setText(Messages.format(NewWizardMessages.NewJavaProjectWizardPageOne_DetectGroup_differendWorkspaceCC_message, new String[] {  BasicElementLabels.getVersionName(defaultCompliance), BasicElementLabels.getVersionName(selectedCompliance)}));
742                                         fHintText.setVisible(true);
743                                         fIcon.setImage(Dialog.getImage(Dialog.DLG_IMG_MESSAGE_INFO));
744                                         fIcon.setVisible(true);
745                                 }
746                                 return;
747                         }
748
749                         selectedCompliance= JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE);
750                         IVMInstall selectedJVM= fJREGroup.getSelectedJVM();
751                         if (selectedJVM == null) {
752                                 selectedJVM= JavaRuntime.getDefaultVMInstall();
753                         }
754                         String jvmCompliance= JavaCore.VERSION_1_4;
755                         if (selectedJVM instanceof IVMInstall2) {
756                                 jvmCompliance= JavaModelUtil.getCompilerCompliance((IVMInstall2) selectedJVM, JavaCore.VERSION_1_4);
757                         }
758                         if (!selectedCompliance.equals(jvmCompliance) && (JavaModelUtil.is50OrHigher(selectedCompliance) || JavaModelUtil.is50OrHigher(jvmCompliance))) {
759                                 fHintText.setText(Messages.format(NewWizardMessages.NewJavaProjectWizardPageOne_DetectGroup_jre_message, new String[] {BasicElementLabels.getVersionName(selectedCompliance), BasicElementLabels.getVersionName(jvmCompliance)}));
760                                 fHintText.setVisible(true);
761                                 fIcon.setImage(Dialog.getImage(Dialog.DLG_IMG_MESSAGE_WARNING));
762                                 fIcon.setVisible(true);
763                         } else {
764                                 fHintText.setVisible(false);
765                                 fIcon.setVisible(false);
766                         }
767
768                 }
769
770                 private boolean computeDetectState() {
771                         if (fLocationGroup.isUseDefaultSelected()) {
772                                 String name= fNameGroup.getName();
773                                 if (name.length() == 0 || JavaPlugin.getWorkspace().getRoot().findMember(name) != null) {
774                                         return false;
775                                 } else {
776                                         final File directory= fLocationGroup.getLocation().append(name).toFile();
777                                         return directory.isDirectory();
778                                 }
779                         } else {
780                                 final File directory= fLocationGroup.getLocation().toFile();
781                                 return directory.isDirectory();
782                         }
783                 }
784
785                 public void update(Observable o, Object arg) {
786                         if (o instanceof LocationGroup) {
787                                 boolean oldDetectState= fDetect;
788                                 fDetect= computeDetectState();
789
790                                 if (oldDetectState != fDetect) {
791                                         setChanged();
792                                         notifyObservers();
793
794                                         if (fDetect) {
795                                                 fHintText.setVisible(true);
796                                                 fHintText.setText(NewWizardMessages.NewJavaProjectWizardPageOne_DetectGroup_message);
797                                                 fIcon.setImage(Dialog.getImage(Dialog.DLG_IMG_MESSAGE_INFO));
798                                                 fIcon.setVisible(true);
799                                         } else {
800                                                 handlePossibleJVMChange();
801                                         }
802                                 }
803                         }
804                 }
805
806                 public boolean mustDetect() {
807                         return fDetect;
808                 }
809
810                 /* (non-Javadoc)
811                  * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
812                  */
813                 public void widgetSelected(SelectionEvent e) {
814                         widgetDefaultSelected(e);
815                 }
816
817                 /* (non-Javadoc)
818                  * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
819                  */
820                 public void widgetDefaultSelected(SelectionEvent e) {
821                         String jreID= BuildPathSupport.JRE_PREF_PAGE_ID;
822                         String eeID= BuildPathSupport.EE_PREF_PAGE_ID;
823                         String complianceId= CompliancePreferencePage.PREF_ID;
824                         Map<String, Boolean> data= new HashMap<String, Boolean>();
825                         data.put(PropertyAndPreferencePage.DATA_NO_LINK, Boolean.TRUE);
826                         String id= "JRE".equals(e.text) ? jreID : complianceId; //$NON-NLS-1$
827                         PreferencesUtil.createPreferenceDialogOn(getShell(), id, new String[] { jreID, complianceId, eeID  }, data).open();
828
829                         fJREGroup.handlePossibleJVMChange();
830                         handlePossibleJVMChange();
831                 }
832
833                 public void generated_6722163234981482426(NewJavaProjectWizardPageOne newjavaprojectwizardpageone) {
834                         addObserver(newjavaprojectwizardpageone.fLayoutGroup);
835                         addObserver(newjavaprojectwizardpageone.fJREGroup);
836                         newjavaprojectwizardpageone.fLocationGroup.addObserver(this);
837                 }
838         }
839
840         /**
841          * Validate this page and show appropriate warnings and error NewWizardMessages.
842          */
843         private final class Validator implements Observer {
844
845                 public void update(Observable o, Object arg) {
846
847                         final IWorkspace workspace= JavaPlugin.getWorkspace();
848
849                         final String name= fNameGroup.getName();
850
851                         // check whether the project name field is empty
852                         if (name.length() == 0) {
853                                 setErrorMessage(null);
854                                 setMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_enterProjectName);
855                                 setPageComplete(false);
856                                 return;
857                         }
858
859                         // check whether the project name is valid
860                         final IStatus nameStatus= workspace.validateName(name, IResource.PROJECT);
861                         if (!nameStatus.isOK()) {
862                                 setErrorMessage(nameStatus.getMessage());
863                                 setPageComplete(false);
864                                 return;
865                         }
866
867                         // check whether project already exists
868                         final IProject handle= workspace.getRoot().getProject(name);
869                         if (handle.exists()) {
870                                 setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_projectAlreadyExists);
871                                 setPageComplete(false);
872                                 return;
873                         }
874
875                         IPath projectLocation= ResourcesPlugin.getWorkspace().getRoot().getLocation().append(name);
876                         if (projectLocation.toFile().exists()) {
877                                 try {
878                                         //correct casing
879                                         String canonicalPath= projectLocation.toFile().getCanonicalPath();
880                                         projectLocation= new Path(canonicalPath);
881                                 } catch (IOException e) {
882                                         JavaPlugin.log(e);
883                                 }
884
885                                 String existingName= projectLocation.lastSegment();
886                                 if (!existingName.equals(fNameGroup.getName())) {
887                                         setErrorMessage(Messages.format(NewWizardMessages.NewJavaProjectWizardPageOne_Message_invalidProjectNameForWorkspaceRoot, BasicElementLabels.getResourceName(existingName)));
888                                         setPageComplete(false);
889                                         return;
890                                 }
891
892                         }
893
894                         final String location= fLocationGroup.getLocation().toOSString();
895
896                         // check whether location is empty
897                         if (location.length() == 0) {
898                                 setErrorMessage(null);
899                                 setMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_enterLocation);
900                                 setPageComplete(false);
901                                 return;
902                         }
903
904                         // check whether the location is a syntactically correct path
905                         if (!Path.EMPTY.isValidPath(location)) {
906                                 setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_invalidDirectory);
907                                 setPageComplete(false);
908                                 return;
909                         }
910
911                         IPath projectPath= null;
912                         if (!fLocationGroup.isUseDefaultSelected()) {
913                                 projectPath= Path.fromOSString(location);
914                                 if (!projectPath.toFile().exists()) {
915                                         // check non-existing external location
916                                         if (!canCreate(projectPath.toFile())) {
917                                                 setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_cannotCreateAtExternalLocation);
918                                                 setPageComplete(false);
919                                                 return;
920                                         }
921                                 }
922                         }
923                         
924                         // validate the location
925                         final IStatus locationStatus= workspace.validateProjectLocation(handle, projectPath);
926                         if (!locationStatus.isOK()) {
927                                 setErrorMessage(locationStatus.getMessage());
928                                 setPageComplete(false);
929                                 return;
930                         }
931
932                         setPageComplete(true);
933
934                         setErrorMessage(null);
935                         setMessage(null);
936                 }
937
938                 private boolean canCreate(File file) {
939                         while (!file.exists()) {
940                                 file= file.getParentFile();
941                                 if (file == null)
942                                         return false;
943                         }
944
945                         return file.canWrite();
946                 }
947         }
948
949         private static final String PAGE_NAME= "NewJavaProjectWizardPageOne"; //$NON-NLS-1$
950
951         private final NameGroup fNameGroup;
952         private final LocationGroup fLocationGroup;
953         private final LayoutGroup fLayoutGroup;
954         private final JREGroup fJREGroup;
955         private final DetectGroup fDetectGroup;
956         private final Validator fValidator;
957         private final WorkingSetGroup fWorkingSetGroup;
958
959         /**
960          * Creates a new {@link NewJavaProjectWizardPageOne}.
961          */
962         public NewJavaProjectWizardPageOne() {
963                 super(PAGE_NAME);
964                 setPageComplete(false);
965                 setTitle(NewWizardMessages.NewJavaProjectWizardPageOne_page_title);
966                 setDescription(NewWizardMessages.NewJavaProjectWizardPageOne_page_description);
967
968                 fNameGroup= new NameGroup();
969                 fLocationGroup= new LocationGroup();
970                 fJREGroup= new JREGroup();
971                 fLayoutGroup= new LayoutGroup();
972                 fWorkingSetGroup= new WorkingSetGroup();
973                 fDetectGroup= new DetectGroup();
974
975                 // establish connections
976                 fNameGroup.addObserver(fLocationGroup);
977                 fDetectGroup.generated_6722163234981482426(this);
978
979                 // initialize all elements
980                 fNameGroup.notifyObservers();
981
982                 // create and connect validator
983                 fValidator= new Validator();
984                 fNameGroup.addObserver(fValidator);
985                 fLocationGroup.addObserver(fValidator);
986
987                 // initialize defaults
988                 setProjectName(""); //$NON-NLS-1$
989                 setProjectLocationURI(null);
990                 setWorkingSets(new IWorkingSet[0]);
991
992                 initializeDefaultVM();
993         }
994
995         /**
996          * The wizard owning this page can call this method to initialize the fields from the
997          * current selection and active part.
998          *
999          * @param selection used to initialize the fields
1000          * @param activePart the (typically active) part to initialize the fields or <code>null</code>
1001          */
1002         public void init(IStructuredSelection selection, IWorkbenchPart activePart) {
1003                 setWorkingSets(getSelectedWorkingSet(selection, activePart));
1004         }
1005
1006         private void initializeDefaultVM() {
1007                 JavaRuntime.getDefaultVMInstall();
1008         }
1009
1010         /* (non-Javadoc)
1011          * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
1012          */
1013         public void createControl(Composite parent) {
1014                 initializeDialogUnits(parent);
1015
1016                 final Composite composite= new Composite(parent, SWT.NULL);
1017                 composite.setFont(parent.getFont());
1018                 composite.setLayout(initGridLayout(new GridLayout(1, false), true));
1019                 composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
1020
1021                 // create UI elements
1022                 Control nameControl= createNameControl(composite);
1023                 nameControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
1024
1025                 Control locationControl= createLocationControl(composite);
1026                 locationControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
1027
1028                 Control jreControl= createJRESelectionControl(composite);
1029                 jreControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
1030
1031                 Control layoutControl= createProjectLayoutControl(composite);
1032                 layoutControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
1033
1034                 Control workingSetControl= createWorkingSetControl(composite);
1035                 workingSetControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
1036
1037                 Control infoControl= createInfoControl(composite);
1038                 infoControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
1039
1040                 setControl(composite);
1041         }
1042
1043         @Override
1044         protected void setControl(Control newControl) {
1045                 Dialog.applyDialogFont(newControl);
1046
1047                 PlatformUI.getWorkbench().getHelpSystem().setHelp(newControl, IJavaHelpContextIds.NEW_JAVAPROJECT_WIZARD_PAGE);
1048
1049                 super.setControl(newControl);
1050         }
1051
1052
1053         /**
1054          * Creates the controls for the name field.
1055          *
1056          * @param composite the parent composite
1057          * @return the created control
1058          */
1059         protected Control createNameControl(Composite composite) {
1060                 return fNameGroup.createControl(composite);
1061         }
1062
1063         /**
1064          * Creates the controls for the location field.
1065          *
1066          * @param composite the parent composite
1067          * @return the created control
1068          */
1069         protected Control createLocationControl(Composite composite) {
1070                 return fLocationGroup.createControl(composite);
1071         }
1072
1073         /**
1074          * Creates the controls for the JRE selection
1075          *
1076          * @param composite the parent composite
1077          * @return the created control
1078          */
1079         protected Control createJRESelectionControl(Composite composite) {
1080                 return fJREGroup.createControl(composite);
1081         }
1082
1083         /**
1084          * Creates the controls for the project layout selection.
1085          *
1086          * @param composite the parent composite
1087          * @return the created control
1088          */
1089         protected Control createProjectLayoutControl(Composite composite) {
1090                 return fLayoutGroup.createContent(composite);
1091         }
1092
1093         /**
1094          * Creates the controls for the working set selection.
1095          *
1096          * @param composite the parent composite
1097          * @return the created control
1098          */
1099         protected Control createWorkingSetControl(Composite composite) {
1100                 return fWorkingSetGroup.createControl(composite);
1101         }
1102
1103         /**
1104          * Creates the controls for the info section.
1105          *
1106          * @param composite the parent composite
1107          * @return the created control
1108          */
1109         protected Control createInfoControl(Composite composite) {
1110                 return fDetectGroup.createControl(composite);
1111         }
1112
1113         /**
1114          * Gets a project name for the new project.
1115          *
1116          * @return the new project resource handle
1117          */
1118         public String getProjectName() {
1119                 return fNameGroup.getName();
1120         }
1121
1122         /**
1123          * Sets the name of the new project
1124          *
1125          * @param name the new name
1126          */
1127         public void setProjectName(String name) {
1128                 if (name == null)
1129                         throw new IllegalArgumentException();
1130
1131                 fNameGroup.setName(name);
1132         }
1133
1134         /**
1135          * Returns the current project location path as entered by the user, or <code>null</code>
1136          * if the project should be created in the workspace.
1137
1138          * @return the project location path or its anticipated initial value.
1139          */
1140         public URI getProjectLocationURI() {
1141                 return fLocationGroup.generated_4065803390293803522();
1142         }
1143
1144         /**
1145          * Sets the project location of the new project or <code>null</code> if the project
1146          * should be created in the workspace
1147          *
1148          * @param uri the new project location
1149          */
1150         public void setProjectLocationURI(URI uri) {
1151                 IPath path= uri != null ? URIUtil.toPath(uri) : null;
1152                 fLocationGroup.setLocation(path);
1153         }
1154
1155         /**
1156          * Returns the compiler compliance to be used for the project, or <code>null</code> to use the workspace
1157          * compiler compliance.
1158          *
1159          * @return compiler compliance to be used for the project or <code>null</code>
1160          */
1161         public String getCompilerCompliance() {
1162                 return fJREGroup.getSelectedCompilerCompliance();
1163         }
1164
1165         /**
1166          * Returns the default class path entries to be added on new projects. By default this is the JRE container as
1167          * selected by the user.
1168          *
1169          * @return returns the default class path entries
1170          */
1171         public IClasspathEntry[] getDefaultClasspathEntries() {
1172                 IPath newPath= fJREGroup.getJREContainerPath();
1173                 if (newPath != null) {
1174                         return new IClasspathEntry[] { JavaCore.newContainerEntry(newPath) };
1175                 }
1176                 return PreferenceConstants.getDefaultJRELibrary();
1177         }
1178
1179         /**
1180          * Returns the source class path entries to be added on new projects.
1181          * The underlying resources may not exist. All entries that are returned must be of kind
1182          * {@link IClasspathEntry#CPE_SOURCE}.
1183          *
1184          * @return returns the source class path entries for the new project
1185          */
1186         public IClasspathEntry[] getSourceClasspathEntries() {
1187                 IPath sourceFolderPath= new Path(getProjectName()).makeAbsolute();
1188
1189                 if (fLayoutGroup.isSrcBin()) {
1190                         IPath srcPath= new Path(PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_SRCNAME));
1191                         if (srcPath.segmentCount() > 0) {
1192                                 sourceFolderPath= sourceFolderPath.append(srcPath);
1193                         }
1194                 }
1195                 return new IClasspathEntry[] {  JavaCore.newSourceEntry(sourceFolderPath) };
1196         }
1197
1198         /**
1199          * Returns the source class path entries to be added on new projects.
1200          * The underlying resource may not exist.
1201          *
1202          * @return returns the default class path entries
1203          */
1204         public IPath getOutputLocation() {
1205                 IPath outputLocationPath= new Path(getProjectName()).makeAbsolute();
1206                 if (fLayoutGroup.isSrcBin()) {
1207                         IPath binPath= new Path(PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME));
1208                         if (binPath.segmentCount() > 0) {
1209                                 outputLocationPath= outputLocationPath.append(binPath);
1210                         }
1211                 }
1212                 return outputLocationPath;
1213         }
1214
1215         /**
1216          * Returns the working sets to which the new project should be added.
1217          *
1218          * @return the selected working sets to which the new project should be added
1219          */
1220         public IWorkingSet[] getWorkingSets() {
1221                 return fWorkingSetGroup.getSelectedWorkingSets();
1222         }
1223
1224         /**
1225          * Sets the working sets to which the new project should be added.
1226          *
1227          * @param workingSets the initial selected working sets
1228          */
1229         public void setWorkingSets(IWorkingSet[] workingSets) {
1230                 if (workingSets == null) {
1231                         throw new IllegalArgumentException();
1232                 }
1233                 fWorkingSetGroup.setWorkingSets(workingSets);
1234         }
1235
1236         /* (non-Javadoc)
1237          * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
1238          */
1239         @Override
1240         public void setVisible(boolean visible) {
1241                 super.setVisible(visible);
1242                 if (visible) {
1243                         fNameGroup.postSetFocus();
1244                 }
1245         }
1246
1247         private GridLayout initGridLayout(GridLayout layout, boolean margins) {
1248                 layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
1249                 layout.verticalSpacing= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
1250                 if (margins) {
1251                         layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
1252                         layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
1253                 } else {
1254                         layout.marginWidth= 0;
1255                         layout.marginHeight= 0;
1256                 }
1257                 return layout;
1258         }
1259
1260         public static final IWorkingSet[] EMPTY_WORKING_SET_ARRAY = new IWorkingSet[0];
1261
1262         private IWorkingSet[] getSelectedWorkingSet(IStructuredSelection selection, IWorkbenchPart activePart) {
1263                 IWorkingSet[] selected= getSelectedWorkingSet(selection);
1264                 if (selected != null && selected.length > 0) {
1265                         for (int i= 0; i < selected.length; i++) {
1266                                 if (!isValidWorkingSet(selected[i]))
1267                                         return EMPTY_WORKING_SET_ARRAY;
1268                         }
1269                         return selected;
1270                 }
1271
1272                 if (!(activePart instanceof PackageExplorerPart))
1273                         return EMPTY_WORKING_SET_ARRAY;
1274
1275                 PackageExplorerPart explorerPart= (PackageExplorerPart) activePart;
1276                 return explorerPart.generated_8214304763819303281();
1277         }
1278
1279         private IWorkingSet[] getSelectedWorkingSet(IStructuredSelection selection) {
1280                 if (!(selection instanceof ITreeSelection))
1281                         return EMPTY_WORKING_SET_ARRAY;
1282
1283                 ITreeSelection treeSelection= (ITreeSelection) selection;
1284                 if (treeSelection.isEmpty())
1285                         return EMPTY_WORKING_SET_ARRAY;
1286
1287                 List<?> elements= treeSelection.toList();
1288                 if (elements.size() == 1) {
1289                         Object element= elements.get(0);
1290                         TreePath[] paths= treeSelection.getPathsFor(element);
1291                         if (paths.length != 1)
1292                                 return EMPTY_WORKING_SET_ARRAY;
1293
1294                         TreePath path= paths[0];
1295                         if (path.getSegmentCount() == 0)
1296                                 return EMPTY_WORKING_SET_ARRAY;
1297
1298                         Object candidate= path.getSegment(0);
1299                         if (!(candidate instanceof IWorkingSet))
1300                                 return EMPTY_WORKING_SET_ARRAY;
1301
1302                         IWorkingSet workingSetCandidate= (IWorkingSet) candidate;
1303                         if (isValidWorkingSet(workingSetCandidate))
1304                                 return new IWorkingSet[] { workingSetCandidate };
1305
1306                         return EMPTY_WORKING_SET_ARRAY;
1307                 }
1308
1309                 ArrayList<IWorkingSet> result= new ArrayList<IWorkingSet>();
1310                 for (Iterator<?> iterator= elements.iterator(); iterator.hasNext();) {
1311                         Object element= iterator.next();
1312                         if (element instanceof IWorkingSet && isValidWorkingSet((IWorkingSet) element)) {
1313                                 result.add((IWorkingSet) element);
1314                         }
1315                 }
1316                 return result.toArray(new IWorkingSet[result.size()]);
1317         }
1318
1319
1320         public void generated_2259057468813127729(JavaProjectWizard javaprojectwizard) {
1321                 javaprojectwizard.addPage(this);
1322         
1323                 if (javaprojectwizard.fSecondPage == null)
1324                         javaprojectwizard.fSecondPage= new NewJavaProjectWizardPageTwo(this);
1325                 javaprojectwizard.addPage(javaprojectwizard.fSecondPage);
1326         
1327                 init(javaprojectwizard.getSelection(), javaprojectwizard.getActivePart());
1328         }
1329
1330         public URI generated_1111648697931151717(NewJavaProjectWizardPageTwo newjavaprojectwizardpagetwo) {
1331                 String projectName= getProjectName();
1332         
1333                 newjavaprojectwizardpagetwo.fCurrProject= ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
1334                 newjavaprojectwizardpagetwo.fCurrProjectLocation= getProjectLocationURI();
1335         
1336                 URI realLocation= NewJavaProjectWizardPageTwo.getRealLocation(projectName, newjavaprojectwizardpagetwo.fCurrProjectLocation);
1337                 return realLocation;
1338         }
1339
1340         public void generated_7636879016446437051(NewJavaProjectWizardPageTwo newjavaprojectwizardpagetwo, IJavaProject javaProject, IProgressMonitor monitor) throws CoreException {
1341                 if (monitor == null) {
1342                         monitor= new NullProgressMonitor();
1343                 }
1344                 monitor.beginTask(NewWizardMessages.NewJavaProjectWizardPageTwo_monitor_init_build_path, 2);
1345         
1346                 try {
1347                         IClasspathEntry[] entries= null;
1348                         IPath outputLocation= null;
1349                         IProject project= javaProject.getProject();
1350         
1351                         if (newjavaprojectwizardpagetwo.fKeepContent) {
1352                                 if (!project.getFile(NewJavaProjectWizardPageTwo.FILENAME_CLASSPATH).exists()) {
1353                                         final ClassPathDetector detector= new ClassPathDetector(newjavaprojectwizardpagetwo.fCurrProject, new SubProgressMonitor(monitor, 2));
1354                                         entries= detector.getClasspath();
1355                                         outputLocation= detector.getOutputLocation();
1356                                         if (entries.length == 0)
1357                                                 entries= null;
1358                                 } else {
1359                                         monitor.worked(2);
1360                                 }
1361                         } else {
1362                                 List<IClasspathEntry> cpEntries= new ArrayList<IClasspathEntry>();
1363                                 IWorkspaceRoot root= project.getWorkspace().getRoot();
1364         
1365                                 IClasspathEntry[] sourceClasspathEntries= getSourceClasspathEntries();
1366                                 for (int i= 0; i < sourceClasspathEntries.length; i++) {
1367                                         IPath path= sourceClasspathEntries[i].getPath();
1368                                         if (path.segmentCount() > 1) {
1369                                                 IFolder folder= root.getFolder(path);
1370                                                 CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 1));
1371                                         }
1372                                         cpEntries.add(sourceClasspathEntries[i]);
1373                                 }
1374         
1375                                 cpEntries.addAll(Arrays.asList(getDefaultClasspathEntries()));
1376         
1377                                 entries= cpEntries.toArray(new IClasspathEntry[cpEntries.size()]);
1378         
1379                                 outputLocation= getOutputLocation();
1380                                 if (outputLocation.segmentCount() > 1) {
1381                                         IFolder folder= root.getFolder(outputLocation);
1382                                         CoreUtility.createDerivedFolder(folder, true, true, new SubProgressMonitor(monitor, 1));
1383                                 }
1384                         }
1385                         if (monitor.isCanceled()) {
1386                                 throw new OperationCanceledException();
1387                         }
1388         
1389                         newjavaprojectwizardpagetwo.init(javaProject, outputLocation, entries, false);
1390                 } finally {
1391                         monitor.done();
1392                 }
1393         }
1394
1395         public static boolean isValidWorkingSet(IWorkingSet workingSet) {
1396                 String id= workingSet.getId();
1397                 if (!IWorkingSetIDs.JAVA.equals(id) && !IWorkingSetIDs.RESOURCE.equals(id))
1398                         return false;
1399
1400                 if (workingSet.isAggregateWorkingSet())
1401                         return false;
1402
1403                 return true;
1404         }
1405
1406
1407 }