mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ProgressManager: allow to run tasks from non-EDT thread
This commit is contained in:
committed by
Aleksey Pivovarov
parent
d59e708e79
commit
aa78093cc9
@@ -317,19 +317,49 @@ public class CoreProgressManager extends ProgressManager implements Disposable {
|
||||
}
|
||||
}
|
||||
else if (task.isModal()) {
|
||||
runProcessWithProgressSynchronously(task.asModal(), null);
|
||||
runSynchronously(task.asModal());
|
||||
}
|
||||
else {
|
||||
final Task.Backgroundable backgroundable = task.asBackgroundable();
|
||||
if (backgroundable.isConditionalModal() && !backgroundable.shouldStartInBackground()) {
|
||||
runProcessWithProgressSynchronously(task, null);
|
||||
runSynchronously(task);
|
||||
}
|
||||
else {
|
||||
runProcessWithProgressAsynchronously(backgroundable);
|
||||
runAsynchronously(backgroundable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void runSynchronously(@NotNull final Task task) {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runProcessWithProgressSynchronously(task, null);
|
||||
}
|
||||
};
|
||||
if (ApplicationManager.getApplication().isDispatchThread()) {
|
||||
runnable.run();
|
||||
}
|
||||
else {
|
||||
ApplicationManager.getApplication().invokeAndWait(runnable, ModalityState.NON_MODAL);
|
||||
}
|
||||
}
|
||||
|
||||
private void runAsynchronously(@NotNull final Task.Backgroundable task) {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runProcessWithProgressAsynchronously(task);
|
||||
}
|
||||
};
|
||||
if (ApplicationManager.getApplication().isDispatchThread()) {
|
||||
runnable.run();
|
||||
}
|
||||
else {
|
||||
ApplicationManager.getApplication().invokeLater(runnable, ModalityState.NON_MODAL);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Future<?> runProcessWithProgressAsynchronously(@NotNull Task.Backgroundable task) {
|
||||
return runProcessWithProgressAsynchronously(task, new EmptyProgressIndicator(), null);
|
||||
|
||||
@@ -168,7 +168,7 @@ public class GitVcs extends AbstractVcs<CommittedChangeList> {
|
||||
* @param task the task to run
|
||||
*/
|
||||
public static void runInBackground(Task.Backgroundable task) {
|
||||
UIUtil.invokeLaterIfNeeded(() -> task.queue());
|
||||
task.queue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user