Skip to content

Commit

Permalink
Bug 578871 - use ISchedulableOperation (#18)
Browse files Browse the repository at this point in the history
to prevent UI freeze during UNDO
  • Loading branch information
jukzi authored Apr 22, 2022
1 parent bc29744 commit d93628b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.ISchedulableOperation;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.LegacyActionTools;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IPartListener;
Expand Down Expand Up @@ -298,7 +303,32 @@ public final void run() {
if (getOperation() instanceof IAdvancedUndoableOperation2) {
runInBackground = ((IAdvancedUndoableOperation2) getOperation()).runInBackground();
}
progressDialog.run(runInBackground, true, runnable);
if (runInBackground) {
progressDialog.run(runInBackground, true, runnable);
} else {
final IJobManager manager = Job.getJobManager();
final ISchedulingRule rule = (getOperation() instanceof ISchedulableOperation)
? ((ISchedulableOperation) getOperation()).getSchedulingRule()
: null;
if (rule == null) {
progressDialog.run(runInBackground, true, runnable);
} else {
// prevent UI freeze during AutoBuild as in
// org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper#perform
try {
try {
// interrupt autobuild or show Wait/Cancel Dialog:
Runnable r = () -> manager.beginRule(rule, null);
BusyIndicator.showWhile(parent.getDisplay(), r);
} catch (OperationCanceledException e) {
throw new InterruptedException(e.getMessage());
}
progressDialog.run(runInBackground, true, runnable); // <-- actual work
} finally {
manager.endRule(rule);
}
}
}
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
if (t == null) {
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Export-Package: org.eclipse.e4.ui.workbench.addons.perspectiveswitcher;x-interna
org.eclipse.ui.themes,
org.eclipse.ui.views,
org.eclipse.ui.wizards
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.19.0,4.0.0)",
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.25.0,4.0.0)",
org.eclipse.help;bundle-version="[3.2.0,4.0.0)",
org.eclipse.jface;bundle-version="[3.18.0,4.0.0)",
org.eclipse.swt;bundle-version="[3.107.0,4.0.0)",
Expand Down

0 comments on commit d93628b

Please sign in to comment.