|
| 1 | +/******************************************************************************* |
| 2 | + * Java2Script Pacemaker (http://j2s.sourceforge.net) |
| 3 | + * |
| 4 | + * Copyright (c) 2006 ognize.com and others. |
| 5 | + * All rights reserved. This program and the accompanying materials |
| 6 | + * are made available under the terms of the Eclipse Public License v1.0 |
| 7 | + * which accompanies this distribution, and is available at |
| 8 | + * http://www.eclipse.org/legal/epl-v10.html |
| 9 | + * |
| 10 | + * Contributors: |
| 11 | + * ognize.com - initial API and implementation |
| 12 | + *******************************************************************************/ |
| 13 | + |
| 14 | +package com.ognize.jface.async; |
| 15 | + |
| 16 | +import org.eclipse.jface.window.Window; |
| 17 | +import org.eclipse.jface.window.WindowProxy; |
| 18 | +import org.eclipse.swt.events.DisposeEvent; |
| 19 | +import org.eclipse.swt.events.DisposeListener; |
| 20 | +import org.eclipse.swt.widgets.Display; |
| 21 | +import org.eclipse.swt.widgets.Shell; |
| 22 | + |
| 23 | +/** |
| 24 | + * @author josson smith |
| 25 | + * |
| 26 | + * 2006-4-29 |
| 27 | + */ |
| 28 | +public class AsyncWindowProxy { |
| 29 | + protected Window window; |
| 30 | + |
| 31 | + public AsyncWindowProxy(Window window) { |
| 32 | + super(); |
| 33 | + this.window = window; |
| 34 | + } |
| 35 | + |
| 36 | + public static void open(Window window, AsyncWindowRunnable runnable) { |
| 37 | + new AsyncWindowProxy(window).open(runnable); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * @j2sNative |
| 42 | +runnable.setWindow (this.window); |
| 43 | +this.window.open (); |
| 44 | +(function (innerThis, finalVars) { |
| 45 | +if (!Clazz.isClassDefined ("com.ognize.jface.async.AsyncWindowProxy$1")) { |
| 46 | +Clazz.pu$h (); |
| 47 | +cla$$ = com.ognize.jface.async.AsyncWindowProxy$1 = function () { |
| 48 | +Clazz.prepareCallback (this, arguments); |
| 49 | +Clazz.instantialize (this, arguments); |
| 50 | +}; |
| 51 | +Clazz.decorateAsType (cla$$, "com.ognize.jface.async.AsyncWindowProxy$1", null, Runnable); |
| 52 | +Clazz.defineMethod (cla$$, "run", |
| 53 | +function () { |
| 54 | +if (this.callbacks["com.ognize.jface.async.AsyncWindowProxy"].window.getShell () == null) { |
| 55 | +this.callbacks["com.ognize.jface.async.AsyncWindowProxy"].getActiveDisplay ().timerExec (10, this); |
| 56 | +return ; |
| 57 | +} |
| 58 | +var $hell = this.callbacks["com.ognize.jface.async.AsyncWindowProxy"].window.getShell (); |
| 59 | +$hell.addDisposeListener ((function (innerThis, finalVars) { |
| 60 | +if (!Clazz.isClassDefined ("com.ognize.jface.async.AsyncWindowProxy$1$2")) { |
| 61 | +Clazz.pu$h (); |
| 62 | +cla$$ = com.ognize.jface.async.AsyncWindowProxy$1$2 = function () { |
| 63 | +Clazz.prepareCallback (this, arguments); |
| 64 | +Clazz.instantialize (this, arguments); |
| 65 | +}; |
| 66 | +Clazz.decorateAsType (cla$$, "com.ognize.jface.async.AsyncWindowProxy$1$2", null, $wt.events.DisposeListener); |
| 67 | +Clazz.defineMethod (cla$$, "widgetDisposed", |
| 68 | +function (e) { |
| 69 | +//this.$finals.runnable.run (); |
| 70 | +this.callbacks["com.ognize.jface.async.AsyncWindowProxy"].getActiveDisplay ().timerExec (5, this.$finals.runnable); |
| 71 | +}, "$wt.events.DisposeEvent"); |
| 72 | +cla$$ = Clazz.p0p (); |
| 73 | +} |
| 74 | +return Clazz.innerTypeInstance (com.ognize.jface.async.AsyncWindowProxy$1$2, innerThis, finalVars); |
| 75 | +}) (this, Clazz.cloneFinals ("runnable", this.$finals.runnable))); |
| 76 | +$hell.getDisplay ().readAndDispatch (); |
| 77 | +}); |
| 78 | +cla$$ = Clazz.p0p (); |
| 79 | +} |
| 80 | +return Clazz.innerTypeInstance (com.ognize.jface.async.AsyncWindowProxy$1, innerThis, finalVars); |
| 81 | +}) (this, Clazz.cloneFinals ("runnable", runnable)).run (); |
| 82 | + */ |
| 83 | + public void open(final AsyncWindowRunnable runnable) { |
| 84 | + runnable.setWindow(window); |
| 85 | + new Thread(new Runnable() { |
| 86 | + public void run() { |
| 87 | + while (window.getShell() == null) { |
| 88 | + try { |
| 89 | + Thread.sleep(10); |
| 90 | + } catch (InterruptedException e) { |
| 91 | + e.printStackTrace(); |
| 92 | + } |
| 93 | + } |
| 94 | + getActiveDisplay().syncExec(new Runnable() { |
| 95 | + public void run() { |
| 96 | + window.getShell().addDisposeListener(new DisposeListener() { |
| 97 | + public synchronized void widgetDisposed(DisposeEvent e) { |
| 98 | + runnable.run(); |
| 99 | + } |
| 100 | + }); |
| 101 | + } |
| 102 | + }); |
| 103 | + } |
| 104 | + }).start(); |
| 105 | + window.open(); |
| 106 | + } |
| 107 | + |
| 108 | + /* |
| 109 | + public void open(final AsyncWindowRunnable runnable) { |
| 110 | + runnable.setWindow(window); |
| 111 | + window.open(); |
| 112 | + new Runnable() { |
| 113 | + public void run() { |
| 114 | + if (window.getShell() == null) { |
| 115 | + getActiveDisplay().timerExec(10, this); |
| 116 | + return ; |
| 117 | + } |
| 118 | + window.getShell().addDisposeListener(new DisposeListener() { |
| 119 | + public synchronized void widgetDisposed(DisposeEvent e) { |
| 120 | + //runnable.run(); |
| 121 | + getActiveDisplay().timerExec(5, runnable); |
| 122 | + } |
| 123 | + }); |
| 124 | + } |
| 125 | + }.run(); |
| 126 | + } |
| 127 | + */ |
| 128 | + |
| 129 | + Display getActiveDisplay() { |
| 130 | + Display display = null; |
| 131 | + Shell shell = window.getShell(); |
| 132 | + if (shell == null) { |
| 133 | + shell = WindowProxy.getParentShell(window); |
| 134 | + } |
| 135 | + if (shell != null) { |
| 136 | + display = shell.getDisplay(); |
| 137 | + } |
| 138 | + if (display == null) { |
| 139 | + display = Display.getCurrent(); |
| 140 | + } |
| 141 | + if (display == null) { |
| 142 | + display = Display.getDefault(); |
| 143 | + } |
| 144 | + return display; |
| 145 | + } |
| 146 | +} |
0 commit comments