Java Code Examples for org.eclipse.swt.widgets.Display#getThread()

The following examples show how to use org.eclipse.swt.widgets.Display#getThread() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: APICloudSplashHandler.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private void updateUI(final Runnable r) {
	Shell splashShell = getSplash();
	if (splashShell == null || splashShell.isDisposed())
		return;

	Display display = splashShell.getDisplay();

	if (Thread.currentThread() == display.getThread())
		r.run();
	else {
		StartupRunnable startupRunnable = new StartupRunnable() {

			public void runWithException() throws Throwable {
				r.run();
			}
		};
		display.asyncExec(startupRunnable);
	}
}
 
Example 2
Source File: BOSSplashHandler.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void updateUI(final Runnable r) {
    final Shell splashShell = getSplash();
    if (splashShell == null || splashShell.isDisposed()) {
        return;
    }

    final Display display = splashShell.getDisplay();

    if (Thread.currentThread() == display.getThread()) {
        r.run(); // run immediatley if we're on the UI thread
    } else {
        // wrapper with a StartupRunnable to ensure that it will run before
        // the UI is fully initialized
        final StartupRunnable startupRunnable = new StartupRunnable() {

            @Override
            public void runWithException() throws Throwable {
                r.run();
            }
        };
        display.asyncExec(startupRunnable);
    }
}
 
Example 3
Source File: AsyncImage.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void checkThread(Display display) {
	// jdk 1.6 bug from checkWidget still fails here
	if (display.getThread() != Thread.currentThread()) {
		throw new IllegalStateException(
				"Wrong thread to pick up the image"); //$NON-NLS-1$
	}
}
 
Example 4
Source File: XtextDocument.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Run the model listeners on the UI thread.
 * 
 * @note Some of the {@link IXtextModelListener}s assume that the {@link XtextDocument} that is associated with the model is not
 *       changing while they run. To achieve this, we run the {@link IXtextModelListener}s on the UI thread.
 */
private void notifyModelListenersOnUiThread() {
	Display display = PlatformUI.getWorkbench().getDisplay();
	if (Thread.currentThread() == display.getThread()) {
		// We are already running on the display thread.  Run the listeners immediately.
		notifyModelListeners(getState());
	} else {
		display.asyncExec(() -> {
			XtextDocument.this.tryReadOnly(((XtextResource resource) -> {
				notifyModelListeners(resource);
				return null;
			}));
		});
	}
}
 
Example 5
Source File: WorkbenchHelper.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isDisplayThread() {
	Display d = getDisplay();
	if (d == null) {
		d = Display.getCurrent();
	}
	if (d == null) { return false; }
	return d.getThread() == Thread.currentThread();
}
 
Example 6
Source File: WorkbenchHelper.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static void run(final Runnable r) {
	final Display d = getDisplay();
	if (d != null && !d.isDisposed()) {
		if (d.getThread() == Thread.currentThread()) {
			r.run();
		} else {
			d.syncExec(r);
		}
	} else {
		r.run();
	}
}