1 /*******************************************************************************
\r
2 * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * which accompanies this distribution, and is available at
\r
6 * http://www.eclipse.org/legal/epl-v10.html
\r
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.utils.threads;
\r
13 import java.util.concurrent.Executor;
\r
15 import org.eclipse.swt.widgets.Display;
\r
17 public class Executors2 {
\r
19 public static Executor createSWTExecutor(Display display, boolean async) {
\r
20 return async ? new SWTExecutorAsync(display) : new SWTExecutorSync(display);
\r
25 class SWTExecutorAsync implements Executor {
\r
28 public SWTExecutorAsync(Display display)
\r
30 this.display = display;
\r
34 public void execute(Runnable command) {
\r
35 // Don't accept work if the SWT thread is disposed.
\r
36 if (display.isDisposed())
\r
37 throw new RuntimeException("The SWT thread has been disposed");
\r
38 display.asyncExec(command);
\r
43 class SWTExecutorSync implements Executor {
\r
46 public SWTExecutorSync(Display display)
\r
48 this.display = display;
\r
52 public void execute(Runnable command) {
\r
53 // Don't accept work if the SWT thread is disposed.
\r
54 if (display.isDisposed())
\r
55 throw new RuntimeException("The SWT thread has been disposed");
\r
56 display.syncExec(command);
\r