Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Läubrich2021-02-20 04:22:52 +0000
committerMickael Istria2021-02-22 10:18:44 +0000
commit9d7194d5b61f010662d7992f85119d5738b12b05 (patch)
tree407e2f1d3a220ab279155a84de1a6921fcbe232d
parenta96b1671d0207e20079631352e107d2466e4d2a3 (diff)
downloadeclipse.platform.ui-9d7194d5b61f010662d7992f85119d5738b12b05.tar.gz
eclipse.platform.ui-9d7194d5b61f010662d7992f85119d5738b12b05.tar.xz
eclipse.platform.ui-9d7194d5b61f010662d7992f85119d5738b12b05.zip
Bug 563459 - Enhance UISynchronize to make it more usefulY20210222-1000I20210223-0650I20210223-0600I20210222-1800I20210222-0600
postpone public API changes to the next release. Change-Id: Ibe4bbf51f4520642cd9ba1b89fddf090dd121237 Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
-rw-r--r--bundles/org.eclipse.e4.ui.di/src/org/eclipse/e4/ui/di/UISynchronize.java119
1 files changed, 0 insertions, 119 deletions
diff --git a/bundles/org.eclipse.e4.ui.di/src/org/eclipse/e4/ui/di/UISynchronize.java b/bundles/org.eclipse.e4.ui.di/src/org/eclipse/e4/ui/di/UISynchronize.java
index e1d4278e14b..57e184c8e75 100644
--- a/bundles/org.eclipse.e4.ui.di/src/org/eclipse/e4/ui/di/UISynchronize.java
+++ b/bundles/org.eclipse.e4.ui.di/src/org/eclipse/e4/ui/di/UISynchronize.java
@@ -15,13 +15,6 @@
*******************************************************************************/
package org.eclipse.e4.ui.di;
-import java.util.Objects;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ForkJoinPool;
-import java.util.concurrent.ForkJoinTask;
-import java.util.concurrent.FutureTask;
-
/**
* Widget toolkit abstract to synchronize back into the UI-Thread from other
* threads
@@ -73,117 +66,5 @@ public abstract class UISynchronize {
*/
protected abstract boolean dispatchEvents();
- /**
- * Executes the given action inside the UI thread (either directly if the
- * current thread is the UI-Thread or by using {@link #syncExec(Runnable)} if
- * not returning the result to the caller
- *
- * @param action the action to perform
- * @since 1.3
- */
- public void exec(Runnable action) {
- Thread thread = Thread.currentThread();
- if (isUIThread(thread)) {
- action.run();
- } else {
- syncExec(action);
- }
- }
-
- /**
- * Calls the given {@link Callable} inside the UI thread (either directly if the
- * current thread is the UI Thread or by using {@link #syncExec(Runnable)} if
- * not returning the result to the caller
- *
- * @param <T> the return type of the {@link Callable}
- * @param action the action to perform
- * @return the value as a result of calling the {@link Callable}
- * @throws InterruptedException if either the current or the background thread
- * where interrupted while waiting for the result
- * @throws ExecutionException if the synchronous execution has thrown an
- * exception
- * @since 1.3
- */
- public <T> T call(Callable<T> action) throws InterruptedException, ExecutionException {
- Thread thread = Thread.currentThread();
- if (isUIThread(thread)) {
- try {
- return action.call();
- } catch (Exception e) {
- if (e instanceof InterruptedException) {
- throw (InterruptedException) e;
- }
- throw new ExecutionException(e);
- }
- } else {
- FutureTask<T> task = new FutureTask<>(action);
- try {
- syncExec(task);
- } catch (RuntimeException e) {
- throw new ExecutionException(e);
- }
- return task.get();
- }
- }
-
- /**
- * Performs the given action in a background (non-ui thread) showing a
- * busy-indicator on a best-effort basis if called from the UI-Thread, otherwise
- * simply executes the action
- *
- * @param action the action to be performed must not be <code>null</code>
- * @throws InterruptedException if either the current or the background thread
- * where interrupted while waiting for the result
- * exception
- * @since 1.3
- */
- public void busyExec(Runnable action) throws InterruptedException {
- try {
- busyCall(() -> {
- action.run();
- return null;
- });
- } catch (ExecutionException e) {
- Throwable cause = e.getCause();
- if (cause instanceof RuntimeException) {
- throw (RuntimeException) cause;
- }
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Performs the given action in a non-ui thread showing a busy-indicator on a
- * best-effort basis and returning the result of the {@link Callable} to the
- * caller
- *
- * @param <T> return type of the {@link Callable}
- * @param action the action to be performed must not be <code>null</code>
- * @return the value as a result of calling the {@link Callable}
- * @throws InterruptedException if either the current or the background thread
- * where interrupted while waiting for the result
- * @throws ExecutionException if the concurrent execution has thrown an
- * exception
- * @since 1.3
- */
- public <T> T busyCall(Callable<T> action) throws InterruptedException, ExecutionException {
- Objects.requireNonNull(action);
- FutureTask<T> task = new FutureTask<>(action);
- Thread thread = Thread.currentThread();
- if (isUIThread(thread)) {
- ForkJoinTask<?> fork = ForkJoinPool.commonPool().submit(task);
- showBusyWhile(() -> {
- while (!fork.isDone() && !Thread.currentThread().isInterrupted()) {
- if (dispatchEvents()) {
- continue;
- }
- Thread.yield();
- }
- });
- } else {
- task.run();
- }
- return task.get();
- }
}

Back to the top