Skip to content

Commit ddacb00

Browse files
author
jossonsmith
committed
Support blocking of SWT.Dialog#open
1 parent 65149fe commit ddacb00

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/Dialog.java

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
import org.eclipse.swt.*;
1515
import org.eclipse.swt.events.SelectionAdapter;
1616
import org.eclipse.swt.events.SelectionEvent;
17-
import org.eclipse.swt.graphics.Image;
1817
import org.eclipse.swt.graphics.Point;
1918
import org.eclipse.swt.internal.ResizeSystem;
20-
import org.eclipse.swt.internal.xhtml.document;
2119
import org.eclipse.swt.layout.GridData;
2220
import org.eclipse.swt.layout.GridLayout;
2321

@@ -45,13 +43,23 @@
4543
* public Object open () {
4644
* Shell parent = getParent();
4745
* Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
46+
* // remove following "-"
47+
* /-**
48+
* * @-j2sNative
49+
* * this.dialogShell = shell;
50+
* *-/ {}
4851
* shell.setText(getText());
4952
* // Your code goes here (widget creation, set result, etc).
5053
* shell.open();
5154
* Display display = parent.getDisplay();
5255
* while (!shell.isDisposed()) {
5356
* if (!display.readAndDispatch()) display.sleep();
5457
* }
58+
* // remove following "-"
59+
* /-**
60+
* * @-j2sNative
61+
* * this.dialogReturn = this.result;
62+
* *-/ {}
5563
* return result;
5664
* }
5765
* }
@@ -79,12 +87,44 @@
7987
* </p>
8088
*
8189
* @see Shell
90+
* @j2sSuffix
91+
DialogSync2Async = {};
92+
DialogSync2Async.block = function (dialog, oThis, runnable) {
93+
if (dialog == null) return;
94+
dialog.open();
95+
var shell = dialog.dialogShell;
96+
if (shell == null) return;
97+
shell.addDisposeListener ((function (innerThis, finalVars) {
98+
if (!Clazz.isClassDefined ("DialogSync2Async$1")) {
99+
Clazz.pu$h ();
100+
cla$$ = DialogSync2Async$1 = function () {
101+
Clazz.prepareCallback (this, arguments);
102+
Clazz.instantialize (this, arguments);
103+
};
104+
Clazz.decorateAsType (cla$$, "DialogSync2Async$1", null, $wt.events.DisposeListener);
105+
Clazz.defineMethod (cla$$, "widgetDisposed",
106+
function (e) {
107+
var $runnable = this.f$.runnable;
108+
var $oThis = this.f$.oThis;
109+
window.setTimeout (function () {
110+
$runnable.apply ($oThis);
111+
}, 0);
112+
//this.f$.runnable.apply (this.f$.oThis);
113+
}, "$wt.events.DisposeEvent");
114+
cla$$ = Clazz.p0p ();
115+
}
116+
return Clazz.innerTypeInstance (DialogSync2Async$1, innerThis, finalVars);
117+
}) (this, Clazz.cloneFinals ("runnable", runnable, "oThis", oThis)));
118+
shell.getDisplay ().readAndDispatch ();
119+
};
82120
*/
83121

84122
public abstract class Dialog {
85123
int style;
86124
Shell parent;
87125
String title;
126+
Shell dialogShell;
127+
Object dialogReturn;
88128

89129
/**
90130
* Constructs a new instance of this class given only its
@@ -257,7 +297,7 @@ public void setText (String string) {
257297

258298

259299
protected void dialogUnimplemented() {
260-
final Shell dialogShell = new Shell(parent.display, style | SWT.CLOSE | SWT.BORDER);
300+
dialogShell = new Shell(parent.display, style | SWT.CLOSE | SWT.BORDER | SWT.SHELL_TRIM);
261301
dialogShell.addListener(SWT.Close, new Listener() {
262302
public void handleEvent(Event event) {
263303
//updateReturnCode();
@@ -267,7 +307,7 @@ public void handleEvent(Event event) {
267307
dialogShell.setLayout(new GridLayout(2, false));
268308

269309
Label icon = new Label(dialogShell, SWT.NONE);
270-
icon.setImage(new Image(dialogShell.display, "j2slib/images/warning.png"));
310+
icon.setImage(parent.display.getSystemImage(SWT.ICON_WARNING));
271311
GridData gridData = new GridData(32, 32);
272312
icon.setLayoutData(gridData);
273313

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/MessageBox.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
public class MessageBox extends Dialog {
4848
String message = "";
4949
private Composite buttonPanel;
50-
private Shell dialogShell;
5150
private Button btn;
5251
private int returnCode;
5352

@@ -207,7 +206,7 @@ public int open () {
207206
}
208207
*/
209208
returnCode = -1;
210-
dialogShell = new Shell(parent.display, style | SWT.CLOSE | SWT.BORDER);
209+
dialogShell = new Shell(parent.display, style | SWT.CLOSE | SWT.BORDER | SWT.SHELL_TRIM);
211210
dialogShell.addListener(SWT.Close, new Listener() {
212211
public void handleEvent(Event event) {
213212
updateReturnCode();
@@ -388,6 +387,10 @@ private void updateReturnCode() {
388387
if ((style & (SWT.RETRY | SWT.CANCEL)) == (SWT.RETRY | SWT.CANCEL)) returnCode = SWT.CANCEL;
389388
if ((style & (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) returnCode = SWT.IGNORE;
390389
}
390+
/**
391+
* @j2sNative
392+
* this.dialogReturn = this.returnCode;
393+
*/{}
391394
}
392395

393396
}

0 commit comments

Comments
 (0)