Skip to content

Commit 48fdb67

Browse files
author
zhourenjian
committed
Replace Java builder with Java2Script builder and others (merge branch 3.3)
1 parent c080c07 commit 48fdb67

File tree

6 files changed

+179
-19
lines changed

6 files changed

+179
-19
lines changed

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
}

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 {

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

Lines changed: 101 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,95 @@
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;
20+
2121
import net.sf.j2s.core.Java2ScriptProjectNature;
2222
import net.sf.j2s.ui.classpath.IRuntimeClasspathEntry;
2323
import net.sf.j2s.ui.classpath.Resource;
2424
import net.sf.j2s.ui.launching.JavaRuntime;
2525
import net.sf.j2s.ui.property.FileUtil;
2626
import net.sf.j2s.ui.property.J2SClasspathModel;
2727
import net.sf.j2s.ui.resources.ExternalResources;
28+
2829
import org.eclipse.core.resources.IProject;
2930
import org.eclipse.core.resources.IncrementalProjectBuilder;
3031
import 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;
3135
import org.eclipse.core.runtime.IProgressMonitor;
36+
import org.eclipse.jdt.core.IClasspathEntry;
37+
import org.eclipse.jdt.core.IJavaElement;
3238
import org.eclipse.jdt.core.IJavaProject;
39+
import org.eclipse.jdt.core.JavaCore;
3340
import 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;
3548
import 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);
4868
updateJava2ScriptWizardTitle();
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
*/
58101
public boolean performFinish() {
59-
boolean finished = super.performFinish();
102+
boolean finished= super.performFinish();
60103
if (finished) {
104+
BasicNewProjectResourceWizard.updatePerspective(fConfigElement);
105+
selectAndReveal(fSecondPage.getJavaProject().getProject());
106+
61107
if (getContainer() instanceof PreferenceDialog) {
62108
PreferenceDialog dialog = (PreferenceDialog) getContainer();
63109
dialog.close();
@@ -139,7 +185,7 @@ public boolean performFinish() {
139185
try {
140186
Java2ScriptProjectNature pn = new Java2ScriptProjectNature();
141187
pn.setProject(project);
142-
pn.addToBuildSpec("net.sf.j2s.core.java2scriptbuilder");
188+
pn.configure();
143189
} catch (CoreException e) {
144190
e.printStackTrace();
145191
}
@@ -151,10 +197,48 @@ public boolean performFinish() {
151197
}
152198
return 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

155234
protected void updateJava2ScriptLibraries(J2SClasspathModel classpathModel, String j2sLibPath) {
156235
}
157236

158237
protected void updateJava2ScriptProject(String prjFolder, String binRelative) {
159238
}
239+
240+
protected IClasspathEntry[] updateJavaLibraries(IClasspathEntry[] defaultEntries) {
241+
return defaultEntries;
242+
}
243+
160244
}

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 {

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 {

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)