Skip to content

Commit b43530f

Browse files
author
zhourenjian
committed
Add Java2Script preferences so that users can have more debugging options like
open Java2Script application in external browsers, loading chrome://*.js while it is in Firefox, and a ALAA (A Link An Application) link is provided so user can load application more than one times without refreshing the page and user can also paste the link in other web pages and get loaded correctly! Some wizards are added. Java2Script project, Java2Script AJAX project, Java2Script SWT project, Java2Script SWT AJAX project, Java2Script Servlet project. Users can create normal Java project with above wizards and get Java2Script compiler enabled by default and related libraries pre-set. In Java2Script Servlet projects, an Ant build.xml is provided. And it will be very easy to export the Java2Script Application into a *.war and get deployed to Tomcat or other JEE containers. In Java2Script SWT-related projects, an "SWT_LIBRARY" enviroment variable, pointing to SWT jar, is required.
1 parent c36d64d commit b43530f

22 files changed

+1516
-94
lines changed

sources/net.sf.j2s.ui/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ Require-Bundle: org.eclipse.ui,
2929
org.eclipse.ui.console,
3030
net.sf.j2s.core,
3131
org.junit,
32-
org.eclipse.jdt.junit
32+
org.eclipse.jdt.junit,
33+
net.sf.j2s.ajax
3334
Eclipse-AutoStart: true
595 Bytes
Loading

sources/net.sf.j2s.ui/icons/view.gif

-103 Bytes
Binary file not shown.
-1020 Bytes
Binary file not shown.
-1.05 KB
Binary file not shown.

sources/net.sf.j2s.ui/plugin.xml

Lines changed: 90 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,96 @@
252252
</action>
253253
</viewerContribution>
254254
</extension>
255+
<extension
256+
point="org.eclipse.jdt.ui.javadocCompletionProcessor">
257+
<javadocCompletionProcessor
258+
class="net.sf.j2s.ui.text.javadoc.JavaDocCompletionEvaluator"
259+
id="net.sf.j2s.javadocCompletionProcessor"/>
260+
</extension>
261+
<extension
262+
point="org.eclipse.ui.preferencePages">
263+
<page
264+
class="net.sf.j2s.ui.preferences.Java2ScriptPreferencePage"
265+
id="net.sf.j2s.ui.preferences.Java2ScriptPreferencePage"
266+
name="Java2Script"/>
267+
</extension>
268+
<extension
269+
point="org.eclipse.core.runtime.preferences">
270+
<initializer class="net.sf.j2s.ui.preferences.PreferenceInitializer"/>
271+
</extension>
272+
273+
<extension
274+
point="org.eclipse.ui.newWizards">
275+
<category
276+
name="Java2Script"
277+
id="net.sf.j2s.ui.java2script">
278+
</category>
279+
<wizard
280+
name="Java2Script Project"
281+
icon="icons/e/newjprj_wiz.gif"
282+
category="net.sf.j2s.ui.java2script"
283+
class="net.sf.j2s.ui.wizards.Java2ScriptProjectWizard"
284+
preferredPerspectives="org.eclipse.jdt.ui.JavaPerspective,org.eclipse.jdt.ui.JavaBrowsingPerspective,org.eclipse.jdt.ui.JavaHierarchyPerspective"
285+
project="true"
286+
finalPerspective="org.eclipse.jdt.ui.JavaPerspective"
287+
id="net.sf.j2s.ui.wizards.Java2ScriptProjectWizard">
288+
<description>
289+
Create Java Project with Java2Script enabled.
290+
</description>
291+
</wizard>
292+
<wizard
293+
name="Java2Script AJAX Project"
294+
icon="icons/e/newjprj_wiz.gif"
295+
category="net.sf.j2s.ui.java2script"
296+
class="net.sf.j2s.ui.wizards.Java2ScriptAJAXProjectWizard"
297+
preferredPerspectives="org.eclipse.jdt.ui.JavaPerspective,org.eclipse.jdt.ui.JavaBrowsingPerspective,org.eclipse.jdt.ui.JavaHierarchyPerspective"
298+
project="true"
299+
finalPerspective="org.eclipse.jdt.ui.JavaPerspective"
300+
id="net.sf.j2s.ui.wizards.Java2ScriptAJAXProjectWizard">
301+
<description>
302+
Create Java Project with Java2Script AJAX enabled.
303+
</description>
304+
</wizard>
305+
<wizard
306+
name="Java2Script SWT Project"
307+
icon="icons/e/newjprj_wiz.gif"
308+
category="net.sf.j2s.ui.java2script"
309+
class="net.sf.j2s.ui.wizards.Java2ScriptSWTProjectWizard"
310+
preferredPerspectives="org.eclipse.jdt.ui.JavaPerspective,org.eclipse.jdt.ui.JavaBrowsingPerspective,org.eclipse.jdt.ui.JavaHierarchyPerspective"
311+
project="true"
312+
finalPerspective="org.eclipse.jdt.ui.JavaPerspective"
313+
id="net.sf.j2s.ui.wizards.Java2ScriptSWTProjectWizard">
314+
<description>
315+
Create Java Project with Java2Script and SWT enabled.
316+
</description>
317+
</wizard>
318+
<wizard
319+
name="Java2Script SWT AJAX Project"
320+
icon="icons/e/newjprj_wiz.gif"
321+
category="net.sf.j2s.ui.java2script"
322+
class="net.sf.j2s.ui.wizards.Java2ScriptSWTAJAXProjectWizard"
323+
preferredPerspectives="org.eclipse.jdt.ui.JavaPerspective,org.eclipse.jdt.ui.JavaBrowsingPerspective,org.eclipse.jdt.ui.JavaHierarchyPerspective"
324+
project="true"
325+
finalPerspective="org.eclipse.jdt.ui.JavaPerspective"
326+
id="net.sf.j2s.ui.wizards.Java2ScriptSWTAJAXProjectWizard">
327+
<description>
328+
Create Java Project with Java2Script AJAX and SWT enabled.
329+
</description>
330+
</wizard>
331+
<wizard
332+
name="Java2Script Servlet Project"
333+
icon="icons/e/newjprj_wiz.gif"
334+
category="net.sf.j2s.ui.java2script"
335+
class="net.sf.j2s.ui.wizards.Java2ScriptServletProjectWizard"
336+
preferredPerspectives="org.eclipse.jdt.ui.JavaPerspective,org.eclipse.jdt.ui.JavaBrowsingPerspective,org.eclipse.jdt.ui.JavaHierarchyPerspective"
337+
project="true"
338+
finalPerspective="org.eclipse.jdt.ui.JavaPerspective"
339+
id="net.sf.j2s.ui.wizards.Java2ScriptServletProjectWizard">
340+
<description>
341+
Create Java Servlet Project with Java2Script AJAX and SWT enabled.
342+
</description>
343+
</wizard>
344+
</extension>
255345
<!--
256346
<extension
257347
point="org.eclipse.ui.exportWizards">
@@ -264,11 +354,4 @@
264354
</wizard>
265355
</extension>
266356
-->
267-
<extension
268-
point="org.eclipse.jdt.ui.javadocCompletionProcessor">
269-
<javadocCompletionProcessor
270-
class="net.sf.j2s.ui.text.javadoc.JavaDocCompletionEvaluator"
271-
id="net.sf.j2s.javadocCompletionProcessor"/>
272-
</extension>
273-
274357
</plugin>

sources/net.sf.j2s.ui/src/net/sf/j2s/ui/launching/ArgsUtil.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static String outputString(String s) {
127127
return buffer.toString();
128128
}
129129

130-
public static String wrapAsArgumentArray(String s) {
130+
public static String wrapAsArgumentArray(String s, boolean whitespace) {
131131
String[] args = splitArguments(s);
132132
StringBuffer buffer = new StringBuffer();
133133
buffer.append('[');
@@ -136,7 +136,10 @@ public static String wrapAsArgumentArray(String s) {
136136
buffer.append(outputString(args[i]));
137137
buffer.append('\"');
138138
if (i != args.length - 1) {
139-
buffer.append(", ");
139+
buffer.append(",");
140+
if (whitespace) {
141+
buffer.append(" ");
142+
}
140143
}
141144
}
142145
buffer.append(']');

sources/net.sf.j2s.ui/src/net/sf/j2s/ui/launching/IJ2SLauchingConfiguration.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
public interface IJ2SLauchingConfiguration {
44

5+
public static final String VIEW_IN_INNER_J2S_CONSOLE = "view.in.j2s.console";
56
public static final String FAST_VIEW_J2S_CONSOLE = "fast.view.j2s.console";
67
public static final String MAXIMIZE_J2S_CONSOLE = "maximize.j2s.console";
78

@@ -11,6 +12,9 @@ public interface IJ2SLauchingConfiguration {
1112
public static final String TAIL_HEADER_HTML = "tail.header.html";
1213
public static final String HEAD_HEADER_HTML = "head.header.html";
1314

15+
public static final String J2S_MOZILLA_ADDON_COMPATIABLE = "j2s.mozilla.addon.compatiable";
16+
public static final String J2S_MOZILLA_ADDON_COMPATIABLE_JS = "j2s.mozilla.addon.compatiable.js";
17+
1418
public static final String J2S_CLASS_PATH = "j2s.class.path";
1519
public static final String J2S_ABANDON_CLASS_PATH = "j2s.abandon.class.path";
1620
}

sources/net.sf.j2s.ui/src/net/sf/j2s/ui/launching/J2SApplicationRunnable.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
package net.sf.j2s.ui.launching;
22

3+
import java.io.File;
4+
import java.net.MalformedURLException;
5+
import java.net.URL;
36
import net.sf.j2s.ui.Java2ScriptUIPlugin;
47
import net.sf.j2s.ui.console.J2SConsoleView;
8+
import net.sf.j2s.ui.preferences.PreferenceConstants;
59

610
import org.eclipse.core.runtime.CoreException;
711
import org.eclipse.debug.core.ILaunchConfiguration;
12+
import org.eclipse.jface.preference.IPreferenceStore;
13+
import org.eclipse.swt.program.Program;
814
import org.eclipse.ui.IViewPart;
915
import org.eclipse.ui.IViewReference;
1016
import org.eclipse.ui.IWorkbenchPage;
@@ -23,16 +29,41 @@ public J2SApplicationRunnable(ILaunchConfiguration configuration, String url) {
2329
}
2430

2531
public void run() {
32+
boolean isToViewInConsole = true;
2633
boolean isViewFast = false;
2734
boolean isViewMaximize = false;
2835
try {
36+
IPreferenceStore store = Java2ScriptUIPlugin.getDefault().getPreferenceStore();
37+
38+
boolean preferred = store.getBoolean(PreferenceConstants.INNER_CONSOLE);
39+
40+
isToViewInConsole = configuration.getAttribute(
41+
IJ2SLauchingConfiguration.VIEW_IN_INNER_J2S_CONSOLE, preferred);
2942
isViewMaximize = configuration.getAttribute(
3043
IJ2SLauchingConfiguration.MAXIMIZE_J2S_CONSOLE, false);
3144
isViewFast = configuration.getAttribute(
3245
IJ2SLauchingConfiguration.FAST_VIEW_J2S_CONSOLE, false);
3346
} catch (CoreException e1) {
3447
e1.printStackTrace();
3548
}
49+
50+
if (!isToViewInConsole) {
51+
if (url != null && url.length() != 0) {
52+
try {
53+
String file = new URL(url).getFile();
54+
boolean win32 = ((System.getProperty("os.name").indexOf("Windows") != -1) //$NON-NLS-1$ //$NON-NLS-2$
55+
|| (System.getProperty("os.name").indexOf("windows") != -1)); //$NON-NLS-1$ //$NON-NLS-2$
56+
if (win32 && file.startsWith("/")) {
57+
file = file.substring(1);
58+
}
59+
file = file.replace('/', File.separatorChar);
60+
Program.launch(file);
61+
} catch (MalformedURLException e1) {
62+
e1.printStackTrace();
63+
}
64+
}
65+
return;
66+
}
3667
IWorkbenchPage activePage = Java2ScriptUIPlugin.getDefault()
3768
.getWorkbench().getWorkbenchWindows()[0].getActivePage();
3869
IViewPart console = activePage

sources/net.sf.j2s.ui/src/net/sf/j2s/ui/launching/J2SConsoleOptionsTab.java

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package net.sf.j2s.ui.launching;
22

3+
import net.sf.j2s.ui.Java2ScriptUIPlugin;
4+
import net.sf.j2s.ui.preferences.PreferenceConstants;
35
import org.eclipse.core.runtime.CoreException;
46
import org.eclipse.debug.core.ILaunchConfiguration;
57
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
68
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
79
import org.eclipse.jdt.internal.debug.ui.JavaDebugImages;
10+
import org.eclipse.jface.preference.IPreferenceStore;
811
import org.eclipse.swt.SWT;
912
import org.eclipse.swt.events.SelectionAdapter;
1013
import org.eclipse.swt.events.SelectionEvent;
@@ -17,6 +20,12 @@
1720
import org.eclipse.swt.widgets.Group;
1821

1922
public class J2SConsoleOptionsTab extends AbstractLaunchConfigurationTab {
23+
24+
private Button btnInner;
25+
26+
private Button btnCompatiable;
27+
28+
private Button btnCompatiableJS; // whether import or include mozilla.addon.js
2029

2130
private Button btnFastView;
2231

@@ -43,11 +52,24 @@ public void createControl(Composite parent) {
4352
group.setLayout(layout);
4453
group.setLayoutData(new GridData(GridData.FILL_BOTH));
4554

46-
String controlName = "Console UI Options";
55+
String controlName = "Console Misc Options";
4756
group.setText(controlName);
57+
58+
btnInner = new Button(group, SWT.CHECK);
59+
btnInner.setText("View Java2Script application in J2S console");
60+
btnInner.addSelectionListener(new SelectionAdapter() {
61+
public void widgetSelected(SelectionEvent e) {
62+
updateLaunchConfigurationDialog();
63+
btnFastView.setEnabled(btnInner.getSelection());
64+
btnMaximize.setEnabled(btnInner.getSelection());
65+
}
66+
});
4867

4968
btnFastView = new Button(group, SWT.CHECK);
5069
btnFastView.setText("Make J2S console as fast view automatically");
70+
GridData gdfv = new GridData();
71+
gdfv.horizontalIndent = 32;
72+
btnFastView.setLayoutData(gdfv);
5173
btnFastView.addSelectionListener(new SelectionAdapter() {
5274
public void widgetSelected(SelectionEvent e) {
5375
updateLaunchConfigurationDialog();
@@ -56,18 +78,57 @@ public void widgetSelected(SelectionEvent e) {
5678

5779
btnMaximize = new Button(group, SWT.CHECK);
5880
btnMaximize.setText("Maximize J2S console automatically");
81+
GridData gdm = new GridData();
82+
gdm.horizontalIndent = 32;
83+
btnMaximize.setLayoutData(gdm);
5984
btnMaximize.addSelectionListener(new SelectionAdapter() {
6085
public void widgetSelected(SelectionEvent e) {
6186
updateLaunchConfigurationDialog();
6287
}
6388
});
89+
90+
btnCompatiable = new Button(group, SWT.CHECK);
91+
btnCompatiable.setText("Generate codes with Mozilla Addon compatiabilities");
92+
btnCompatiable.addSelectionListener(new SelectionAdapter() {
93+
public void widgetSelected(SelectionEvent e) {
94+
updateLaunchConfigurationDialog();
95+
btnCompatiableJS.setEnabled(btnCompatiable.getSelection());
96+
}
97+
});
98+
99+
btnCompatiableJS = new Button(group, SWT.CHECK);
100+
GridData gdjs = new GridData();
101+
gdjs.horizontalIndent = 32;
102+
btnCompatiableJS.setLayoutData(gdjs);
103+
btnCompatiableJS.setText("Write compatiable JavaScript instead of including mozilla.addon.js");
104+
btnCompatiableJS.addSelectionListener(new SelectionAdapter() {
105+
public void widgetSelected(SelectionEvent e) {
106+
updateLaunchConfigurationDialog();
107+
}
108+
});
64109
}
65110

66111
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
67112
configuration.setAttribute(IJ2SLauchingConfiguration.FAST_VIEW_J2S_CONSOLE,
68113
false);
69114
configuration.setAttribute(
70115
IJ2SLauchingConfiguration.MAXIMIZE_J2S_CONSOLE, false);
116+
117+
IPreferenceStore store = Java2ScriptUIPlugin.getDefault()
118+
.getPreferenceStore();
119+
120+
boolean preferred = store.getBoolean(PreferenceConstants.INNER_CONSOLE);
121+
122+
configuration.setAttribute(
123+
IJ2SLauchingConfiguration.VIEW_IN_INNER_J2S_CONSOLE, preferred);
124+
125+
preferred = store.getBoolean(PreferenceConstants.ADDON_COMPATIABLE);
126+
127+
configuration.setAttribute(
128+
IJ2SLauchingConfiguration.J2S_MOZILLA_ADDON_COMPATIABLE, preferred);
129+
130+
configuration.setAttribute(
131+
IJ2SLauchingConfiguration.J2S_MOZILLA_ADDON_COMPATIABLE_JS, false);
71132
}
72133

73134
public void initializeFrom(ILaunchConfiguration configuration) {
@@ -76,6 +137,27 @@ public void initializeFrom(ILaunchConfiguration configuration) {
76137
IJ2SLauchingConfiguration.FAST_VIEW_J2S_CONSOLE, false));
77138
btnMaximize.setSelection(configuration.getAttribute(
78139
IJ2SLauchingConfiguration.MAXIMIZE_J2S_CONSOLE, false));
140+
btnCompatiableJS.setSelection(configuration.getAttribute(
141+
IJ2SLauchingConfiguration.J2S_MOZILLA_ADDON_COMPATIABLE_JS, false));
142+
143+
IPreferenceStore store = Java2ScriptUIPlugin.getDefault()
144+
.getPreferenceStore();
145+
146+
boolean preferred = store.getBoolean(PreferenceConstants.INNER_CONSOLE);
147+
148+
boolean external = configuration.getAttribute(
149+
IJ2SLauchingConfiguration.VIEW_IN_INNER_J2S_CONSOLE, preferred);
150+
btnInner.setSelection(external);
151+
btnFastView.setEnabled(external);
152+
btnMaximize.setEnabled(external);
153+
154+
preferred = store.getBoolean(PreferenceConstants.ADDON_COMPATIABLE);
155+
156+
boolean compatiable = configuration.getAttribute(
157+
IJ2SLauchingConfiguration.J2S_MOZILLA_ADDON_COMPATIABLE, preferred);
158+
btnCompatiable.setSelection(compatiable);
159+
btnCompatiableJS.setEnabled(compatiable);
160+
79161
} catch (CoreException e) {
80162
e.printStackTrace();
81163
}
@@ -86,10 +168,16 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
86168
btnFastView.getSelection());
87169
configuration.setAttribute(
88170
IJ2SLauchingConfiguration.MAXIMIZE_J2S_CONSOLE, btnMaximize.getSelection());
171+
configuration.setAttribute(
172+
IJ2SLauchingConfiguration.VIEW_IN_INNER_J2S_CONSOLE, btnInner.getSelection());
173+
configuration.setAttribute(
174+
IJ2SLauchingConfiguration.J2S_MOZILLA_ADDON_COMPATIABLE, btnCompatiable.getSelection());
175+
configuration.setAttribute(
176+
IJ2SLauchingConfiguration.J2S_MOZILLA_ADDON_COMPATIABLE_JS, btnCompatiableJS.getSelection());
89177
}
90178

91179
public String getName() {
92-
return "Console UI";
180+
return "Misc";
93181
}
94182

95183
public Image getImage() {

sources/net.sf.j2s.ui/src/net/sf/j2s/ui/launching/J2SLaunchConfigurationDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void launch(ILaunchConfiguration configuration, String mode,
1616
ILaunch launch, IProgressMonitor monitor) throws CoreException {
1717
if (configuration != null) {
1818
try {
19-
J2SLaunchingUtil.launchingJ2SApp(configuration);
19+
J2SLaunchingUtil.launchingJ2SApp(configuration, mode);
2020
} catch (CoreException e) {
2121
e.printStackTrace();
2222
}

0 commit comments

Comments
 (0)