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

The following examples show how to use org.eclipse.swt.widgets.Display#getThread() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
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
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 Project: nebula   File: AsyncImage.java    License: 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
/**
 * 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
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
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();
	}
}