at.spardat.xma.rpc.BusyExecutorHelper Maven / Gradle / Ivy
package at.spardat.xma.rpc;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.eclipse.swt.widgets.Display;
public class BusyExecutorHelper {
public static Display getDisplay() {
Display display = Display.getCurrent(); // from the UI thread
if (display == null) {
display = Display.getDefault();
}
return display;
}
public static boolean hasDisplayMessages() {
return getDisplayMessageCount() != 0;
}
public static int getDisplayMessageCount() {
Display display = getDisplay();
Integer result = null;
if (display != null) {
Method m;
try {
m = display.getClass().getDeclaredMethod("getMessageCount",null);
m.setAccessible(true);
try {
result = (Integer) m.invoke(display, null);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
if (result==null) {
return -1;
} else {
return result.intValue();
}
} else {
return -1;
}
}
}