Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html /
 
 package org.eclipse.xtext.ui.util;
 
import  org.eclipse.swt.widgets.Display;
public abstract class DisplayRunnableWithResult <T>{
	protected abstract T run() throws Exception;
	public T syncExec() {
		if (Display.getCurrent() == null) {
			final Wrapper<T> resultWrapper = new Wrapper<T>();
			final Wrapper<ExceptionexceptionWrapper = new Wrapper<Exception>();
			Display.getDefault().syncExec(new Runnable() {
				public void run() {
					try {
						resultWrapper.set(DisplayRunnableWithResult.this.run());
catch (Exception e) {
						exceptionWrapper.set(e);
					}
				}
			});
			Exception exception = exceptionWrapper.get();
			if (exception != null)
				throw (exception instanceof RuntimeException
					? (RuntimeExceptionexception 
new WrappedException(exception);
			return resultWrapper.get();
else {
			try {
				return run();
catch (Exception e) {
				throw new WrappedException(e);
			}
		}
	}
New to GrepCode? Check out our FAQ X