T
- the return value of the run method (that gets passed through
busyCursor(IProgressMonitor)
etc.)public abstract class LongOperation<T> extends Object
Implementors instantiate a subclass of this and implement its run method with
their functionality. Then, they call runInJob(IProgressMonitor, String)
on it.
Here is an example on how to use it:
public InputStream openInputStream(final int options, final IProgressMonitor monitor) throws CoreException { return new LongOperation<InputStream>() { @Override public InputStream run(IProgressMonitor monitor) throws CoreException { return doOpenInputStream(options, monitor); } }.runInJob(monitor); }
Modifier and Type | Class and Description |
---|---|
protected class |
LongOperation.JoiningRunnable |
static class |
LongOperation.LongOperationException
An exception that is thrown when an error occurs while running the
LongOperation . |
protected class |
LongOperation.RunnableWrappingJob
A job that wraps a
IRunnableWithProgress and adapts the API for error reporting and cancellation. |
Constructor and Description |
---|
LongOperation() |
Modifier and Type | Method and Description |
---|---|
T |
busyCursor(IProgressMonitor monitor)
Deprecated.
in some cases, might trigger TG-360 on Macs. Also displays a large enervating popup dialog. Use
runInJob(IProgressMonitor, String) instead. |
protected T |
getResult() |
abstract T |
run(IProgressMonitor monitor)
A long-running operation that should in no case be executed in the UI thread.
|
T |
runInJob(IProgressMonitor monitor,
String message)
Run the operation in a background job and wait for the background job to finish, when called from an UI thread.
|
public abstract T run(IProgressMonitor monitor) throws CoreException
monitor
- A progress monitor to report progress to. May be null
.CoreException
public T busyCursor(IProgressMonitor monitor) throws CoreException
runInJob(IProgressMonitor, String)
instead.run(IProgressMonitor)
method as appropriate:
run(IProgressMonitor)
method.IProgressService.busyCursorWhile(IRunnableWithProgress)
method.monitor
- a progress monitor that will be used when the method is not called from the UI thread.run(IProgressMonitor)
method.LongOperation.LongOperationException
- when run(IProgressMonitor)
has thrown an unknown exception (which it shouldn't)CoreException
- when the run(IProgressMonitor)
has thrown a CoreExceptionRuntimeException
- when run(IProgressMonitor)
has thrown a RuntimeException
public T runInJob(IProgressMonitor monitor, String message) throws CoreException
monitor
- a monitor to report progress tomessage
- the job title if this operation is forced to the backgroundrun(IProgressMonitor)
)CoreException
- in case of an error, see run(IProgressMonitor)
and LongOperation.LongOperationException
protected T getResult()
run(IProgressMonitor)
method after that has run or null
.