1
1
package net .sf .j2s .ui .launching ;
2
2
3
+ import java .io .File ;
4
+ import java .io .FileInputStream ;
5
+ import java .io .FileNotFoundException ;
6
+ import java .io .IOException ;
7
+ import java .util .Properties ;
3
8
import net .sf .j2s .ui .Java2ScriptUIPlugin ;
4
9
import net .sf .j2s .ui .preferences .PreferenceConstants ;
10
+ import net .sf .j2s .ui .property .FileUtil ;
11
+ import net .sf .j2s .ui .resources .ExternalResources ;
12
+ import org .eclipse .core .resources .ResourcesPlugin ;
5
13
import org .eclipse .core .runtime .CoreException ;
6
14
import org .eclipse .debug .core .ILaunchConfiguration ;
7
15
import org .eclipse .debug .core .ILaunchConfigurationWorkingCopy ;
8
16
import org .eclipse .debug .ui .AbstractLaunchConfigurationTab ;
17
+ import org .eclipse .jdt .core .IJavaModel ;
18
+ import org .eclipse .jdt .core .IJavaProject ;
19
+ import org .eclipse .jdt .core .JavaCore ;
20
+ import org .eclipse .jdt .core .JavaModelException ;
9
21
import org .eclipse .jdt .internal .debug .ui .JavaDebugImages ;
22
+ import org .eclipse .jdt .launching .IJavaLaunchConfigurationConstants ;
10
23
import org .eclipse .jface .preference .IPreferenceStore ;
11
24
import org .eclipse .swt .SWT ;
25
+ import org .eclipse .swt .events .FocusAdapter ;
26
+ import org .eclipse .swt .events .FocusEvent ;
27
+ import org .eclipse .swt .events .FocusListener ;
28
+ import org .eclipse .swt .events .ModifyEvent ;
29
+ import org .eclipse .swt .events .ModifyListener ;
12
30
import org .eclipse .swt .events .SelectionAdapter ;
13
31
import org .eclipse .swt .events .SelectionEvent ;
14
32
import org .eclipse .swt .graphics .Font ;
18
36
import org .eclipse .swt .widgets .Button ;
19
37
import org .eclipse .swt .widgets .Composite ;
20
38
import org .eclipse .swt .widgets .Group ;
39
+ import org .eclipse .swt .widgets .Label ;
40
+ import org .eclipse .swt .widgets .Text ;
21
41
22
42
public class J2SConsoleOptionsTab extends AbstractLaunchConfigurationTab {
23
43
24
- private Button btnInner ;
44
+ Button btnInner ;
25
45
26
- private Button btnCompatiable ;
46
+ Button btnCompatiable ;
27
47
28
- private Button btnCompatiableRawJS ; // whether import or include mozilla.addon.js
48
+ Button btnCompatiableRawJS ; // whether import or include mozilla.addon.js
29
49
30
- private Button btnFastView ;
50
+ Button btnFastView ;
31
51
32
- private Button btnMaximize ;
52
+ Button btnMaximize ;
53
+
54
+ Button btnUseGlobalURL ;
55
+
56
+ Button btnExternal ;
57
+
58
+ Label lblJ2SLib ;
59
+
60
+ Text txtJ2SLib ;
61
+
62
+ Label lblBin ;
63
+
64
+ Text txtBin ;
33
65
34
66
public J2SConsoleOptionsTab () {
35
67
super ();
@@ -50,13 +82,13 @@ public void createControl(Composite parent) {
50
82
group .setFont (font );
51
83
layout = new GridLayout ();
52
84
group .setLayout (layout );
53
- group .setLayoutData (new GridData (GridData .FILL_BOTH ));
85
+ group .setLayoutData (new GridData (GridData .FILL_HORIZONTAL ));
54
86
55
- String controlName = "Console Misc Options" ;
87
+ String controlName = "Java2Script Console Misc Options" ;
56
88
group .setText (controlName );
57
89
58
- btnInner = new Button (group , SWT .CHECK );
59
- btnInner .setText ("View Java2Script application in J2S console " );
90
+ btnInner = new Button (group , SWT .RADIO );
91
+ btnInner .setText ("Inner J2S Console " );
60
92
btnInner .addSelectionListener (new SelectionAdapter () {
61
93
public void widgetSelected (SelectionEvent e ) {
62
94
updateLaunchConfigurationDialog ();
@@ -87,16 +119,26 @@ public void widgetSelected(SelectionEvent e) {
87
119
}
88
120
});
89
121
90
- btnCompatiable = new Button (group , SWT .CHECK );
91
- btnCompatiable .setText ("Generate codes with Mozilla Addon compatiabilities" );
122
+ btnExternal = new Button (group , SWT .RADIO );
123
+ btnExternal .setText ("Registered external browsers, like Firefox, IE" );
124
+ btnExternal .addSelectionListener (new SelectionAdapter () {
125
+ public void widgetSelected (SelectionEvent e ) {
126
+ updateLaunchConfigurationDialog ();
127
+ btnFastView .setEnabled (btnInner .getSelection ());
128
+ btnMaximize .setEnabled (btnInner .getSelection ());
129
+ }
130
+ });
131
+
132
+ btnCompatiable = new Button (comp , SWT .CHECK );
133
+ btnCompatiable .setText ("Generate codes with Mozilla Add-on supports" );
92
134
btnCompatiable .addSelectionListener (new SelectionAdapter () {
93
135
public void widgetSelected (SelectionEvent e ) {
94
136
updateLaunchConfigurationDialog ();
95
137
btnCompatiableRawJS .setEnabled (btnCompatiable .getSelection ());
96
138
}
97
139
});
98
140
99
- btnCompatiableRawJS = new Button (group , SWT .CHECK );
141
+ btnCompatiableRawJS = new Button (comp , SWT .CHECK );
100
142
GridData gdjs = new GridData ();
101
143
gdjs .horizontalIndent = 32 ;
102
144
btnCompatiableRawJS .setLayoutData (gdjs );
@@ -106,6 +148,56 @@ public void widgetSelected(SelectionEvent e) {
106
148
updateLaunchConfigurationDialog ();
107
149
}
108
150
});
151
+
152
+ btnUseGlobalURL = new Button (comp , SWT .CHECK );
153
+ btnUseGlobalURL .setText ("Use global *.js URL" );
154
+ btnUseGlobalURL .addSelectionListener (new SelectionAdapter () {
155
+ public void widgetSelected (SelectionEvent e ) {
156
+ updateLaunchConfigurationDialog ();
157
+ boolean selection = btnUseGlobalURL .getSelection ();
158
+ lblJ2SLib .setEnabled (selection );
159
+ lblBin .setEnabled (selection );
160
+ txtJ2SLib .setEnabled (selection );
161
+ txtBin .setEnabled (selection );
162
+ }
163
+ });
164
+
165
+ Composite txtComp = new Composite (comp , SWT .NONE );
166
+ GridData gdtxt = new GridData ();
167
+ gdtxt .horizontalIndent = 32 ;
168
+ txtComp .setLayoutData (gdtxt );
169
+ txtComp .setLayout (new GridLayout (2 , false ));
170
+
171
+ lblJ2SLib = new Label (txtComp , SWT .NONE );
172
+ lblJ2SLib .setText ("J2SLib base URL:" );
173
+
174
+ txtJ2SLib = new Text (txtComp , SWT .BORDER );
175
+ GridData gdtxt1 = new GridData ();
176
+ gdtxt1 .widthHint = 240 ;
177
+ txtJ2SLib .setLayoutData (gdtxt1 );
178
+ FocusListener focusListener = new FocusAdapter () {
179
+ public void focusGained (FocusEvent e ) {
180
+ // select txt
181
+ ((Text ) e .widget ).selectAll ();
182
+ }
183
+ };
184
+ ModifyListener modifyListener = new ModifyListener () {
185
+ public void modifyText (ModifyEvent e ) {
186
+ updateLaunchConfigurationDialog ();
187
+ }
188
+ };
189
+ txtJ2SLib .addFocusListener (focusListener );
190
+ txtJ2SLib .addModifyListener (modifyListener );
191
+
192
+ lblBin = new Label (txtComp , SWT .NONE );
193
+ lblBin .setText ("Binary folder URL:" );
194
+
195
+ txtBin = new Text (txtComp , SWT .BORDER );
196
+ GridData gdtxt2 = new GridData ();
197
+ gdtxt2 .widthHint = 240 ;
198
+ txtBin .setLayoutData (gdtxt2 );
199
+ txtBin .addFocusListener (focusListener );
200
+ txtBin .addModifyListener (modifyListener );
109
201
}
110
202
111
203
public void setDefaults (ILaunchConfigurationWorkingCopy configuration ) {
@@ -129,6 +221,16 @@ public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
129
221
130
222
configuration .setAttribute (
131
223
IJ2SLauchingConfiguration .J2S_MOZILLA_ADDON_COMPATIABLE_RAW_JS , true );
224
+
225
+ configuration .setAttribute (
226
+ IJ2SLauchingConfiguration .USE_GLOBAL_ALAA_URL , false );
227
+
228
+ configuration .setAttribute (
229
+ IJ2SLauchingConfiguration .GLOBAL_J2SLIB_URL ,
230
+ "http://archive.java2script.org/" + getCurrentReleaseAlias (configuration ) + "/" );
231
+
232
+ configuration .setAttribute (
233
+ IJ2SLauchingConfiguration .GLOBAL_BINARY_URL , getCurrentBinPath (configuration ));
132
234
}
133
235
134
236
public void initializeFrom (ILaunchConfiguration configuration ) {
@@ -148,6 +250,7 @@ public void initializeFrom(ILaunchConfiguration configuration) {
148
250
boolean external = configuration .getAttribute (
149
251
IJ2SLauchingConfiguration .VIEW_IN_INNER_J2S_CONSOLE , preferred );
150
252
btnInner .setSelection (external );
253
+ btnExternal .setSelection (!external );
151
254
btnFastView .setEnabled (external );
152
255
btnMaximize .setEnabled (external );
153
256
@@ -158,11 +261,95 @@ public void initializeFrom(ILaunchConfiguration configuration) {
158
261
btnCompatiable .setSelection (compatiable );
159
262
btnCompatiableRawJS .setEnabled (compatiable );
160
263
264
+ boolean useGlobal = configuration .getAttribute (
265
+ IJ2SLauchingConfiguration .USE_GLOBAL_ALAA_URL , false );
266
+ btnUseGlobalURL .setSelection (useGlobal );
267
+ lblJ2SLib .setEnabled (useGlobal );
268
+ lblBin .setEnabled (useGlobal );
269
+ txtJ2SLib .setEnabled (useGlobal );
270
+ txtBin .setEnabled (useGlobal );
271
+
272
+ txtJ2SLib .setText (configuration .getAttribute (
273
+ IJ2SLauchingConfiguration .GLOBAL_J2SLIB_URL ,
274
+ "http://archive.java2script.org/" + getCurrentReleaseAlias (configuration ) + "/" ));
275
+
276
+ txtBin .setText (configuration .getAttribute (
277
+ IJ2SLauchingConfiguration .GLOBAL_BINARY_URL , getCurrentBinPath (configuration )));
278
+
161
279
} catch (CoreException e ) {
162
280
e .printStackTrace ();
163
281
}
164
282
}
165
283
284
+ private String getCurrentBinPath (ILaunchConfiguration configuration ) {
285
+ IJavaModel javaModel = JavaCore .create (ResourcesPlugin .getWorkspace ().getRoot ());
286
+ try {
287
+ String projectName = configuration .getAttribute (IJavaLaunchConfigurationConstants .ATTR_PROJECT_NAME , (String )null );
288
+ if ((projectName == null ) || (projectName .trim ().length () < 1 )) {
289
+ return null ;
290
+ }
291
+ IJavaProject javaProject = javaModel .getJavaProject (projectName );
292
+ if ((javaProject == null ) || !javaProject .exists ()) {
293
+ return null ;
294
+ }
295
+ String path = javaProject .getOutputLocation ().toString ();
296
+ int idx = path .indexOf ('/' , 2 );
297
+ String relativePath = "" ;
298
+ if (idx != -1 ) {
299
+ relativePath = path .substring (idx + 1 );
300
+ }
301
+ return relativePath ;
302
+ } catch (JavaModelException e ) {
303
+ e .printStackTrace ();
304
+ } catch (CoreException e ) {
305
+ e .printStackTrace ();
306
+ }
307
+ return "bin/" ;
308
+ }
309
+ private String getCurrentJ2SLibPath (File workingDir ) {
310
+ String [][] allResources = ExternalResources .getAllResources ();
311
+ String j2sLibPath = null ;
312
+ if (allResources != null && allResources .length != 0 && allResources [0 ].length != 0 ) {
313
+ if ((allResources [0 ][0 ]).startsWith ("|" )) {
314
+ allResources [0 ][0 ] = FileUtil .toRelativePath (allResources [0 ][0 ].substring (1 ),
315
+ workingDir .getAbsolutePath ());;
316
+ }
317
+ j2sLibPath = allResources [0 ][0 ].substring (0 , allResources [0 ][0 ].lastIndexOf ("/" ) + 1 );
318
+ } else {
319
+ j2sLibPath = "../net.sf.j2s.lib/j2slib/" ;
320
+ }
321
+ return j2sLibPath ;
322
+ }
323
+ private String getCurrentReleaseAlias (ILaunchConfiguration configuration ) {
324
+ File workingDir = null ;
325
+ try {
326
+ workingDir = J2SLaunchingUtil .getWorkingDirectory (configuration );
327
+ String j2sLibPath = getCurrentJ2SLibPath (workingDir );
328
+
329
+ File j2slibFolder = new File (workingDir .getAbsolutePath (), j2sLibPath );
330
+ File j2sRelease = new File (j2slibFolder , ".release" );
331
+ Properties release = new Properties ();
332
+ String alias = "1.0.0" ;
333
+ String version = "20070304" ;
334
+ release .put ("alias" , alias );
335
+ release .put ("version" , version );
336
+ if (j2sRelease .exists ()) {
337
+ try {
338
+ release .load (new FileInputStream (j2sRelease ));
339
+ } catch (FileNotFoundException e ) {
340
+ e .printStackTrace ();
341
+ } catch (IOException e ) {
342
+ e .printStackTrace ();
343
+ }
344
+ alias = release .getProperty ("alias" );
345
+ version = release .getProperty ("version" );
346
+ }
347
+ return alias ;
348
+ } catch (CoreException e ) {
349
+ e .printStackTrace ();
350
+ return "1.0.0" ;
351
+ }
352
+ }
166
353
public void performApply (ILaunchConfigurationWorkingCopy configuration ) {
167
354
configuration .setAttribute (IJ2SLauchingConfiguration .FAST_VIEW_J2S_CONSOLE ,
168
355
btnFastView .getSelection ());
@@ -174,6 +361,12 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
174
361
IJ2SLauchingConfiguration .J2S_MOZILLA_ADDON_COMPATIABLE , btnCompatiable .getSelection ());
175
362
configuration .setAttribute (
176
363
IJ2SLauchingConfiguration .J2S_MOZILLA_ADDON_COMPATIABLE_RAW_JS , btnCompatiableRawJS .getSelection ());
364
+ configuration .setAttribute (
365
+ IJ2SLauchingConfiguration .USE_GLOBAL_ALAA_URL , btnUseGlobalURL .getSelection ());
366
+ configuration .setAttribute (
367
+ IJ2SLauchingConfiguration .GLOBAL_J2SLIB_URL , txtJ2SLib .getText ());
368
+ configuration .setAttribute (
369
+ IJ2SLauchingConfiguration .GLOBAL_BINARY_URL , txtBin .getText ());
177
370
}
178
371
179
372
public String getName () {
0 commit comments