1515import java .io .FileNotFoundException ;
1616import java .io .FileOutputStream ;
1717import java .io .IOException ;
18- import java .util .Iterator ;
19- import java .util .List ;
18+ import java .lang .reflect .InvocationTargetException ;
2019import java .util .Properties ;
20+
2121import net .sf .j2s .core .Java2ScriptProjectNature ;
2222import net .sf .j2s .ui .classpath .IRuntimeClasspathEntry ;
2323import net .sf .j2s .ui .classpath .Resource ;
2424import net .sf .j2s .ui .launching .JavaRuntime ;
2525import net .sf .j2s .ui .property .FileUtil ;
2626import net .sf .j2s .ui .property .J2SClasspathModel ;
2727import net .sf .j2s .ui .resources .ExternalResources ;
28+
2829import org .eclipse .core .resources .IProject ;
2930import org .eclipse .core .resources .IncrementalProjectBuilder ;
3031import org .eclipse .core .runtime .CoreException ;
32+ import org .eclipse .core .runtime .IConfigurationElement ;
33+ import org .eclipse .core .runtime .IExecutableExtension ;
34+ import org .eclipse .core .runtime .IPath ;
3135import org .eclipse .core .runtime .IProgressMonitor ;
36+ import org .eclipse .jdt .core .IClasspathEntry ;
37+ import org .eclipse .jdt .core .IJavaElement ;
3238import org .eclipse .jdt .core .IJavaProject ;
39+ import org .eclipse .jdt .core .JavaCore ;
3340import org .eclipse .jdt .core .JavaModelException ;
34- import org .eclipse .jdt .internal .ui .wizards .JavaProjectWizard ;
41+ import org .eclipse .jdt .internal .ui .JavaPlugin ;
42+ import org .eclipse .jdt .internal .ui .JavaPluginImages ;
43+ import org .eclipse .jdt .internal .ui .util .ExceptionHandler ;
44+ import org .eclipse .jdt .internal .ui .wizards .JavaProjectWizardFirstPage ;
45+ import org .eclipse .jdt .internal .ui .wizards .JavaProjectWizardSecondPage ;
46+ import org .eclipse .jdt .internal .ui .wizards .NewElementWizard ;
47+ import org .eclipse .jdt .internal .ui .wizards .NewWizardMessages ;
3548import org .eclipse .jface .preference .PreferenceDialog ;
49+ import org .eclipse .swt .widgets .Shell ;
50+ import org .eclipse .ui .wizards .newresource .BasicNewProjectResourceWizard ;
3651
3752/**
3853 * @author zhou renjian
3954 *
4055 * 2007-3-4
4156 */
42- public class Java2ScriptProjectWizard extends JavaProjectWizard {
43- /**
44- *
45- */
46- public Java2ScriptProjectWizard () {
47- super ();
57+ public class Java2ScriptProjectWizard extends NewElementWizard implements IExecutableExtension {
58+
59+ private JavaProjectWizardFirstPage fFirstPage ;
60+ private JavaProjectWizardSecondPage fSecondPage ;
61+
62+ private IConfigurationElement fConfigElement ;
63+
64+ public Java2ScriptProjectWizard () {
65+ setDefaultPageImageDescriptor (JavaPluginImages .DESC_WIZBAN_NEWJPRJ );
66+ setDialogSettings (JavaPlugin .getDefault ().getDialogSettings ());
67+ setWindowTitle (NewWizardMessages .JavaProjectWizard_title );
4868updateJava2ScriptWizardTitle ();
49- }
69+ }
5070
51- protected void updateJava2ScriptWizardTitle () {
52- setWindowTitle (getWindowTitle () +" with Java2Script Enabled" );
53- }
54-
71+ /*
72+ * @see Wizard#addPages
73+ */
74+ public void addPages () {
75+ super .addPages ();
76+ fFirstPage =new JavaProjectWizardFirstPage ();
77+ addPage (fFirstPage );
78+ fSecondPage =new JavaProjectWizardSecondPage (fFirstPage ) {
79+
80+ public void init (IJavaProject jproject ,IPath defaultOutputLocation ,
81+ IClasspathEntry []defaultEntries ,
82+ boolean defaultsOverrideExistingClasspath ) {
83+ super .init (jproject ,defaultOutputLocation ,updateJavaLibraries (defaultEntries ),
84+ defaultsOverrideExistingClasspath );
85+ }
86+
87+ };
88+ addPage (fSecondPage );
89+ }
90+
91+ /* (non-Javadoc)
92+ * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#finishPage(org.eclipse.core.runtime.IProgressMonitor)
93+ */
94+ protected void finishPage (IProgressMonitor monitor )throws InterruptedException ,CoreException {
95+ fSecondPage .performFinish (monitor );// use the full progress monitor
96+ }
97+
5598/* (non-Javadoc)
56- * @see org.eclipse.jdt.internal.ui.wizards.JavaProjectWizard #performFinish()
99+ * @see org.eclipse.jface.wizard.IWizard #performFinish()
57100 */
58101public boolean performFinish () {
59- boolean finished =super .performFinish ();
102+ boolean finished =super .performFinish ();
60103if (finished ) {
104+ BasicNewProjectResourceWizard .updatePerspective (fConfigElement );
105+ selectAndReveal (fSecondPage .getJavaProject ().getProject ());
106+
61107if (getContainer ()instanceof PreferenceDialog ) {
62108PreferenceDialog dialog = (PreferenceDialog )getContainer ();
63109dialog .close ();
@@ -139,7 +185,7 @@ public boolean performFinish() {
139185try {
140186Java2ScriptProjectNature pn =new Java2ScriptProjectNature ();
141187pn .setProject (project );
142- pn .addToBuildSpec ( "net.sf.j2s.core.java2scriptbuilder" );
188+ pn .configure ( );
143189 }catch (CoreException e ) {
144190e .printStackTrace ();
145191 }
@@ -151,10 +197,48 @@ public boolean performFinish() {
151197}
152198return finished ;
153199}
200+
201+ protected void handleFinishException (Shell shell ,InvocationTargetException e ) {
202+ String title =NewWizardMessages .JavaProjectWizard_op_error_title ;
203+ String message =NewWizardMessages .JavaProjectWizard_op_error_create_message ;
204+ ExceptionHandler .handle (e ,getShell (),title ,message );
205+ }
206+
207+ /*
208+ * Stores the configuration element for the wizard. The config element will be used
209+ * in <code>performFinish</code> to set the result perspective.
210+ */
211+ public void setInitializationData (IConfigurationElement cfig ,String propertyName ,Object data ) {
212+ fConfigElement =cfig ;
213+ }
214+
215+ /* (non-Javadoc)
216+ * @see IWizard#performCancel()
217+ */
218+ public boolean performCancel () {
219+ fSecondPage .performCancel ();
220+ return super .performCancel ();
221+ }
222+
223+ /* (non-Javadoc)
224+ * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#getCreatedElement()
225+ */
226+ public IJavaElement getCreatedElement () {
227+ return JavaCore .create (fFirstPage .getProjectHandle ());
228+ }
229+
230+ protected void updateJava2ScriptWizardTitle () {
231+ setWindowTitle (getWindowTitle () +" with Java2Script Enabled" );
232+ }
154233
155234protected void updateJava2ScriptLibraries (J2SClasspathModel classpathModel ,String j2sLibPath ) {
156235}
157236
158237protected void updateJava2ScriptProject (String prjFolder ,String binRelative ) {
159238}
239+
240+ protected IClasspathEntry []updateJavaLibraries (IClasspathEntry []defaultEntries ) {
241+ return defaultEntries ;
242+ }
243+
160244}