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 ;
2120import net .sf .j2s .core .Java2ScriptProjectNature ;
2221import net .sf .j2s .ui .classpath .IRuntimeClasspathEntry ;
2827import org .eclipse .core .resources .IProject ;
2928import org .eclipse .core .resources .IncrementalProjectBuilder ;
3029import org .eclipse .core .runtime .CoreException ;
30+ import org .eclipse .core .runtime .IConfigurationElement ;
31+ import org .eclipse .core .runtime .IExecutableExtension ;
32+ import org .eclipse .core .runtime .IPath ;
3133import org .eclipse .core .runtime .IProgressMonitor ;
34+ import org .eclipse .jdt .core .IClasspathEntry ;
35+ import org .eclipse .jdt .core .IJavaElement ;
3236import org .eclipse .jdt .core .IJavaProject ;
37+ import org .eclipse .jdt .core .JavaCore ;
3338import org .eclipse .jdt .core .JavaModelException ;
34- import org .eclipse .jdt .internal .ui .wizards .JavaProjectWizard ;
39+ import org .eclipse .jdt .internal .ui .JavaPlugin ;
40+ import org .eclipse .jdt .internal .ui .JavaPluginImages ;
41+ import org .eclipse .jdt .internal .ui .util .ExceptionHandler ;
42+ import org .eclipse .jdt .internal .ui .wizards .JavaProjectWizardFirstPage ;
43+ import org .eclipse .jdt .internal .ui .wizards .JavaProjectWizardSecondPage ;
44+ import org .eclipse .jdt .internal .ui .wizards .NewElementWizard ;
45+ import org .eclipse .jdt .internal .ui .wizards .NewWizardMessages ;
3546import org .eclipse .jface .preference .PreferenceDialog ;
47+ import org .eclipse .swt .widgets .Shell ;
48+ import org .eclipse .ui .wizards .newresource .BasicNewProjectResourceWizard ;
3649
3750/**
3851 * @author zhou renjian
3952 *
4053 * 2007-3-4
4154 */
42- public class Java2ScriptProjectWizard extends JavaProjectWizard {
43- /**
44- *
45- */
46- public Java2ScriptProjectWizard () {
47- super ();
55+ public class Java2ScriptProjectWizard extends NewElementWizard implements IExecutableExtension {
56+
57+ private JavaProjectWizardFirstPage fFirstPage ;
58+ private JavaProjectWizardSecondPage fSecondPage ;
59+
60+ private IConfigurationElement fConfigElement ;
61+
62+ public Java2ScriptProjectWizard () {
63+ setDefaultPageImageDescriptor (JavaPluginImages .DESC_WIZBAN_NEWJPRJ );
64+ setDialogSettings (JavaPlugin .getDefault ().getDialogSettings ());
65+ setWindowTitle (NewWizardMessages .JavaProjectWizard_title );
4866 updateJava2ScriptWizardTitle ();
49- }
67+ }
5068
51- protected void updateJava2ScriptWizardTitle () {
52- setWindowTitle (getWindowTitle () + " with Java2Script Enabled" );
53- }
54-
69+ /*
70+ * @see Wizard#addPages
71+ */
72+ public void addPages () {
73+ super .addPages ();
74+ fFirstPage = new JavaProjectWizardFirstPage ();
75+ addPage (fFirstPage );
76+ fSecondPage = new JavaProjectWizardSecondPage (fFirstPage ) {
77+
78+ public void init (IJavaProject jproject , IPath defaultOutputLocation ,
79+ IClasspathEntry [] defaultEntries ,
80+ boolean defaultsOverrideExistingClasspath ) {
81+ super .init (jproject , defaultOutputLocation , updateJavaLibraries (defaultEntries ),
82+ defaultsOverrideExistingClasspath );
83+ }
84+
85+ };
86+ addPage (fSecondPage );
87+ }
88+
89+ /* (non-Javadoc)
90+ * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#finishPage(org.eclipse.core.runtime.IProgressMonitor)
91+ */
92+ protected void finishPage (IProgressMonitor monitor ) throws InterruptedException , CoreException {
93+ fSecondPage .performFinish (monitor ); // use the full progress monitor
94+ }
95+
5596 /* (non-Javadoc)
56- * @see org.eclipse.jdt.internal.ui.wizards.JavaProjectWizard #performFinish()
97+ * @see org.eclipse.jface.wizard.IWizard #performFinish()
5798 */
5899 public boolean performFinish () {
59- boolean finished = super .performFinish ();
100+ boolean finished = super .performFinish ();
60101 if (finished ) {
102+ BasicNewProjectResourceWizard .updatePerspective (fConfigElement );
103+ selectAndReveal (fSecondPage .getJavaProject ().getProject ());
104+
61105 if (getContainer () instanceof PreferenceDialog ) {
62106 PreferenceDialog dialog = (PreferenceDialog ) getContainer ();
63107 dialog .close ();
@@ -139,7 +183,7 @@ public boolean performFinish() {
139183 try {
140184 Java2ScriptProjectNature pn = new Java2ScriptProjectNature ();
141185 pn .setProject (project );
142- pn .addToBuildSpec ( "net.sf.j2s.core.java2scriptbuilder" );
186+ pn .configure ( );
143187 } catch (CoreException e ) {
144188 e .printStackTrace ();
145189 }
@@ -151,10 +195,48 @@ public boolean performFinish() {
151195 }
152196 return finished ;
153197 }
198+
199+ protected void handleFinishException (Shell shell , InvocationTargetException e ) {
200+ String title = NewWizardMessages .JavaProjectWizard_op_error_title ;
201+ String message = NewWizardMessages .JavaProjectWizard_op_error_create_message ;
202+ ExceptionHandler .handle (e , getShell (), title , message );
203+ }
204+
205+ /*
206+ * Stores the configuration element for the wizard. The config element will be used
207+ * in <code>performFinish</code> to set the result perspective.
208+ */
209+ public void setInitializationData (IConfigurationElement cfig , String propertyName , Object data ) {
210+ fConfigElement = cfig ;
211+ }
212+
213+ /* (non-Javadoc)
214+ * @see IWizard#performCancel()
215+ */
216+ public boolean performCancel () {
217+ fSecondPage .performCancel ();
218+ return super .performCancel ();
219+ }
220+
221+ /* (non-Javadoc)
222+ * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#getCreatedElement()
223+ */
224+ public IJavaElement getCreatedElement () {
225+ return JavaCore .create (fFirstPage .getProjectHandle ());
226+ }
227+
228+ protected void updateJava2ScriptWizardTitle () {
229+ setWindowTitle (getWindowTitle () + " with Java2Script Enabled" );
230+ }
154231
155232 protected void updateJava2ScriptLibraries (J2SClasspathModel classpathModel , String j2sLibPath ) {
156233 }
157234
158235 protected void updateJava2ScriptProject (String prjFolder , String binRelative ) {
159236 }
237+
238+ protected IClasspathEntry [] updateJavaLibraries (IClasspathEntry [] defaultEntries ) {
239+ return defaultEntries ;
240+ }
241+
160242}
0 commit comments