Skip to content

Commit 7163c4e

Browse files
author
zhourenjian
committed
Replace Java compiler with Java2Script compiler and others (Synchronize from Eclipse 3.3 branch)
1 parent 47a7cb8 commit 7163c4e

File tree

6 files changed

+177
-19
lines changed

6 files changed

+177
-19
lines changed

sources/net.sf.j2s.ui/src/net/sf/j2s/ui/property/J2SPropertyPage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public boolean performOk() {
191191
try {
192192
Java2ScriptProjectNature pn = new Java2ScriptProjectNature();
193193
pn.setProject(project);
194-
pn.addToBuildSpec("net.sf.j2s.core.java2scriptbuilder");
194+
pn.configure();
195195
} catch (CoreException e) {
196196
e.printStackTrace();
197197
}
@@ -206,7 +206,7 @@ public boolean performOk() {
206206
try {
207207
Java2ScriptProjectNature pn = new Java2ScriptProjectNature();
208208
pn.setProject(project);
209-
pn.removeFromBuildSpec("net.sf.j2s.core.java2scriptbuilder");
209+
pn.deconfigure();
210210
} catch (CoreException e) {
211211
e.printStackTrace();
212212
}

sources/net.sf.j2s.ui/src/net/sf/j2s/ui/wizards/Java2ScriptAJAXProjectWizard.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
import java.io.FileNotFoundException;
1717
import java.io.FileOutputStream;
1818
import java.io.IOException;
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
22+
import org.eclipse.core.runtime.IPath;
23+
import org.eclipse.core.runtime.Path;
24+
import org.eclipse.jdt.core.IClasspathEntry;
25+
import org.eclipse.jdt.core.JavaCore;
26+
1927
import net.sf.j2s.ui.launching.J2SLaunchingUtil;
2028
import net.sf.j2s.ui.property.J2SClasspathModel;
2129

@@ -35,6 +43,17 @@ protected void updateJava2ScriptWizardTitle() {
3543

3644
protected void updateJava2ScriptLibraries(J2SClasspathModel classpathModel, String j2sLibPath) {
3745
}
46+
47+
protected IClasspathEntry[] updateJavaLibraries(
48+
IClasspathEntry[] defaultEntries) {
49+
List list = new ArrayList();
50+
for (int i = 0; i < defaultEntries.length; i++) {
51+
list.add(i, defaultEntries[i]);
52+
}
53+
list.add(JavaCore.newVariableEntry(new Path("AJAX_CORE"), new Path("AJAX_CORE_SRC"), null));
54+
list.add(JavaCore.newVariableEntry(new Path("AJAX_RPC"), new Path("AJAX_RPC_SRC"), null));
55+
return super.updateJavaLibraries((IClasspathEntry[]) list.toArray(new IClasspathEntry[list.size()]));
56+
}
3857

3958
protected void updateJava2ScriptProject(String prjFolder, String binRelative) {
4059
try {

sources/net.sf.j2s.ui/src/net/sf/j2s/ui/wizards/Java2ScriptProjectWizard.java

Lines changed: 99 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
import java.io.FileNotFoundException;
1616
import java.io.FileOutputStream;
1717
import java.io.IOException;
18-
import java.util.Iterator;
19-
import java.util.List;
18+
import java.lang.reflect.InvocationTargetException;
2019
import java.util.Properties;
2120
import net.sf.j2s.core.Java2ScriptProjectNature;
2221
import net.sf.j2s.ui.classpath.IRuntimeClasspathEntry;
@@ -28,36 +27,81 @@
2827
import org.eclipse.core.resources.IProject;
2928
import org.eclipse.core.resources.IncrementalProjectBuilder;
3029
import 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;
3133
import org.eclipse.core.runtime.IProgressMonitor;
34+
import org.eclipse.jdt.core.IClasspathEntry;
35+
import org.eclipse.jdt.core.IJavaElement;
3236
import org.eclipse.jdt.core.IJavaProject;
37+
import org.eclipse.jdt.core.JavaCore;
3338
import 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;
3546
import 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
}

sources/net.sf.j2s.ui/src/net/sf/j2s/ui/wizards/Java2ScriptSWTAJAXProjectWizard.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
import java.io.FileNotFoundException;
1717
import java.io.FileOutputStream;
1818
import java.io.IOException;
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
22+
import org.eclipse.core.runtime.IPath;
23+
import org.eclipse.core.runtime.Path;
24+
import org.eclipse.jdt.core.IClasspathEntry;
25+
import org.eclipse.jdt.core.JavaCore;
26+
1927
import net.sf.j2s.ui.classpath.IRuntimeClasspathEntry;
2028
import net.sf.j2s.ui.classpath.Resource;
2129
import net.sf.j2s.ui.launching.J2SLaunchingUtil;
@@ -43,6 +51,18 @@ protected void updateJava2ScriptLibraries(J2SClasspathModel classpathModel, Stri
4351
classpathModel.addResource((Resource) entry);
4452
}
4553
}
54+
55+
protected IClasspathEntry[] updateJavaLibraries(
56+
IClasspathEntry[] defaultEntries) {
57+
List list = new ArrayList();
58+
for (int i = 0; i < defaultEntries.length; i++) {
59+
list.add(i, defaultEntries[i]);
60+
}
61+
list.add(JavaCore.newVariableEntry(new Path("ECLIPSE_SWT"), null, null));
62+
list.add(JavaCore.newVariableEntry(new Path("AJAX_SWT"), new Path("AJAX_SWT_SRC"), null));
63+
list.add(JavaCore.newVariableEntry(new Path("AJAX_RPC"), new Path("AJAX_RPC_SRC"), null));
64+
return super.updateJavaLibraries((IClasspathEntry[]) list.toArray(new IClasspathEntry[list.size()]));
65+
}
4666

4767
protected void updateJava2ScriptProject(String prjFolder, String binRelative) {
4868
try {

sources/net.sf.j2s.ui/src/net/sf/j2s/ui/wizards/Java2ScriptSWTProjectWizard.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
import java.io.FileNotFoundException;
1717
import java.io.FileOutputStream;
1818
import java.io.IOException;
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
22+
import org.eclipse.core.runtime.IPath;
23+
import org.eclipse.core.runtime.Path;
24+
import org.eclipse.jdt.core.IClasspathEntry;
25+
import org.eclipse.jdt.core.JavaCore;
26+
1927
import net.sf.j2s.ui.classpath.IRuntimeClasspathEntry;
2028
import net.sf.j2s.ui.classpath.Resource;
2129
import net.sf.j2s.ui.launching.J2SLaunchingUtil;
@@ -43,6 +51,16 @@ protected void updateJava2ScriptLibraries(J2SClasspathModel classpathModel, Stri
4351
classpathModel.addResource((Resource) entry);
4452
}
4553
}
54+
55+
protected IClasspathEntry[] updateJavaLibraries(
56+
IClasspathEntry[] defaultEntries) {
57+
List list = new ArrayList();
58+
for (int i = 0; i < defaultEntries.length; i++) {
59+
list.add(i, defaultEntries[i]);
60+
}
61+
list.add(JavaCore.newVariableEntry(new Path("ECLIPSE_SWT"), null, null));
62+
return super.updateJavaLibraries((IClasspathEntry[]) list.toArray(new IClasspathEntry[list.size()]));
63+
}
4664

4765
protected void updateJava2ScriptProject(String prjFolder, String binRelative) {
4866
try {

sources/net.sf.j2s.ui/src/net/sf/j2s/ui/wizards/Java2ScriptServletProjectWizard.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
import java.io.FileOutputStream;
1818
import java.io.IOException;
1919
import java.net.URL;
20+
import java.util.ArrayList;
21+
import java.util.Arrays;
22+
import java.util.List;
23+
2024
import net.sf.j2s.ajax.AjaxPlugin;
2125
import net.sf.j2s.ui.classpath.IRuntimeClasspathEntry;
2226
import net.sf.j2s.ui.classpath.Resource;
@@ -26,6 +30,9 @@
2630
import org.eclipse.core.runtime.IPath;
2731
import org.eclipse.core.runtime.Path;
2832
import org.eclipse.core.runtime.Platform;
33+
import org.eclipse.jdt.core.IClasspathEntry;
34+
import org.eclipse.jdt.core.JavaCore;
35+
import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPVariableElement;
2936

3037
/**
3138
* @author zhou renjian
@@ -48,6 +55,18 @@ protected void updateJava2ScriptLibraries(J2SClasspathModel classpathModel, Stri
4855
classpathModel.addResource((Resource) entry);
4956
}
5057
}
58+
59+
protected IClasspathEntry[] updateJavaLibraries(
60+
IClasspathEntry[] defaultEntries) {
61+
List list = new ArrayList();
62+
for (int i = 0; i < defaultEntries.length; i++) {
63+
list.add(i, defaultEntries[i]);
64+
}
65+
list.add(JavaCore.newVariableEntry(new Path("ECLIPSE_SWT"), null, null));
66+
list.add(JavaCore.newVariableEntry(new Path("AJAX_SWT"), new Path("AJAX_SWT_SRC"), null));
67+
list.add(JavaCore.newVariableEntry(new Path("AJAX_RPC"), new Path("AJAX_RPC_SRC"), null));
68+
return super.updateJavaLibraries((IClasspathEntry[]) list.toArray(new IClasspathEntry[list.size()]));
69+
}
5170

5271
protected void updateJava2ScriptProject(String prjFolder, String binRelative) {
5372
try {

0 commit comments

Comments
 (0)