Skip to content

Commit 1192256

Browse files
author
zhourenjian
committed
Add JFace support
1 parent ab2cd12 commit 1192256

File tree

2 files changed

+166
-0
lines changed

2 files changed

+166
-0
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2007 java2script.org and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Zhou Renjian - initial API and implementation
10+
*******************************************************************************/
11+
12+
package net.sf.j2s.ajax;
13+
14+
import org.eclipse.jface.window.Window;
15+
import org.eclipse.swt.events.DisposeEvent;
16+
import org.eclipse.swt.events.DisposeListener;
17+
import org.eclipse.swt.widgets.Display;
18+
import org.eclipse.swt.widgets.Shell;
19+
20+
/**
21+
* @author zhou renjian
22+
*
23+
* 2006-4-29
24+
*/
25+
public class AWindowDelegate {
26+
Window win;
27+
28+
AWindowDelegate(Window win) {
29+
super();
30+
this.win = win;
31+
}
32+
33+
public static void open(Window win,AWindowRunnable runnable) {
34+
win.setBlockOnOpen(false);
35+
new AWindowDelegate(win).nonBlockOpen(null, runnable);
36+
}
37+
/* Only JavaScript call this method. */
38+
static void asyncOpen(Window win, Object oThis, AWindowRunnable runnable) {
39+
win.setBlockOnOpen(false);
40+
new AWindowDelegate(win).nonBlockOpen(oThis, runnable);
41+
}
42+
43+
void nonBlockOpen(final Object oThis, final AWindowRunnable runnable) {
44+
if (runnable instanceof AWindowRunnable) {
45+
runnable.setWindow(win);
46+
}
47+
boolean isJ2SEnv = false;
48+
/**
49+
* @j2sNative
50+
* isJ2SEnv = true;
51+
*/ {}
52+
if (isJ2SEnv) {
53+
//win.open();
54+
/**
55+
* @j2sNative
56+
* this.win.open ();
57+
*/ {}
58+
(new Runnable() {
59+
public void run() {
60+
Shell shell = win.getShell();
61+
if (shell == null) {
62+
getActiveDisplay().timerExec(10, this);
63+
return;
64+
}
65+
shell.addDisposeListener(new DisposeListener() {
66+
public void widgetDisposed(DisposeEvent e) {
67+
e.display.update();
68+
if (oThis == null) {
69+
e.display.timerExec(5, runnable);
70+
} else
71+
/**
72+
* @j2sNative
73+
* var $runnable = this.f$.runnable;
74+
* var $oThis = this.f$.oThis;
75+
* window.setTimeout (function () {
76+
* $runnable.apply ($oThis);
77+
* }, 0);
78+
*/
79+
{
80+
81+
}
82+
}
83+
});
84+
shell.getDisplay().readAndDispatch();
85+
}
86+
}).run();
87+
} else
88+
/**
89+
* @j2sNative
90+
*/
91+
{
92+
new Thread(new Runnable() {
93+
public void run() {
94+
while (win.getShell() == null) {
95+
try {
96+
Thread.sleep(10);
97+
} catch (InterruptedException e) {
98+
e.printStackTrace();
99+
}
100+
}
101+
getActiveDisplay().syncExec(new Runnable() {
102+
public void run() {
103+
win.getShell().addDisposeListener(new DisposeListener() {
104+
public synchronized void widgetDisposed(DisposeEvent e) {
105+
e.display.update();
106+
runnable.run();
107+
}
108+
});
109+
}
110+
});
111+
}
112+
}).start();
113+
win.open();
114+
}
115+
}
116+
117+
Display getActiveDisplay() {
118+
Display display = null;
119+
Shell shell = win.getShell();
120+
if (shell != null) {
121+
display = shell.getDisplay();
122+
}
123+
if (display == null) {
124+
display = Display.getCurrent();
125+
}
126+
if (display == null) {
127+
display = Display.getDefault();
128+
}
129+
return display;
130+
}
131+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2007 java2script.org and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Zhou Renjian - initial API and implementation
10+
*******************************************************************************/
11+
12+
package net.sf.j2s.ajax;
13+
14+
import org.eclipse.jface.window.Window;
15+
16+
/**
17+
* @author zhou renjian
18+
*
19+
* 2006-4-29
20+
*/
21+
public abstract class AWindowRunnable implements Runnable {
22+
private Window win;
23+
24+
protected void setWindow(Window win) {
25+
this.win = win;
26+
}
27+
28+
public Window getWindow() {
29+
return win;
30+
}
31+
32+
public int getReturnCode() {
33+
return win.getReturnCode();
34+
}
35+
}

0 commit comments

Comments
 (0)