public interface ProgressIndicator
setText(java.lang.String)
, setText2(java.lang.String)
, setFraction(double)
, setIndeterminate(boolean)
) and
interrupt if the computation is canceled (checkCanceled()
).
There are many implementations which may implement only parts of the functionality in this interface. Some indicators are invisible,
not showing any status to the user, but still tracking cancellation.
To run a task with a visible progress indicator, modal or displayed in the status bar, please use ProgressManager.run(com.intellij.openapi.progress.Task)
methods.
To associate a thread with a progress, use ProgressManager.runProcess(java.lang.Runnable, com.intellij.openapi.progress.ProgressIndicator)
methods. This is mostly
used with invisible progress indicators for cancellation handling. A common case is to take a read action that's interrupted by a write action
about to occur in the UI thread, to avoid UI freezes (see ReadAction.nonBlocking(Runnable)
).
Another common case is wrapping main thread's to parallelize the associated computation by forking additional threads.
Current thread's progress indicator, visible or not, can be retrieved with ProgressIndicatorProvider.getGlobalProgressIndicator()
.
Here are some commonly used implementations:
EmptyProgressIndicator
: invisible (ignores text/fraction-related methods), used only for cancellation tracking.
Remembers its creation modality state.ProgressIndicatorBase
: invisible, but can be made visible by subclassing:
remembers text/fraction inside and allows to retrieve them and possibly show in the UI. Non-modal by default.ProgressWindow
: visible progress, either modal or background. Usually not created directly,
instantiated internally inside ProgressManager.run(com.intellij.openapi.progress.Task)
.ProgressWrapper
: wraps an existing progress indicator, usually to fork another thread
with the same cancellation policy. Use SensitiveProgressWrapper
to allow
that separate thread's indicator to be canceled independently from the main thread.start()
can be called only once after the indicator was created. (Or also after stop()
, if the indicator is reusable - see AbstractProgressIndicatorBase.isReuseable()
)stop()
can be called only once after start()
setModalityProgress(ProgressIndicator)
can be called only before start()
setFraction(double)
/getFraction()
can be called only after setIndeterminate(false)
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Cancels the current process.
|
void |
checkCanceled()
Usually invoked in the thread associated with this indicator, used to check if the computation performed by this thread
has been canceled, and, if yes, stop it immediately (by throwing an exception).
|
default void |
finishNonCancelableSection()
Deprecated.
|
double |
getFraction() |
ModalityState |
getModalityState() |
java.lang.String |
getText() |
java.lang.String |
getText2() |
boolean |
isCanceled() |
boolean |
isIndeterminate() |
boolean |
isModal() |
boolean |
isPopupWasShown() |
boolean |
isRunning() |
boolean |
isShowing() |
void |
popState() |
void |
pushState() |
void |
setFraction(double fraction)
Sets the fraction: a number between 0.0 and 1.0 reflecting the ratio of work that has already be done (0.0 for nothing, 1.0 for all).
|
void |
setIndeterminate(boolean indeterminate)
Marks the progress indeterminate (for processes that can't estimate the amount of work to be done) or determinate (for processes
that can display the fraction of the work done using
setFraction(double) ). |
void |
setModalityProgress(ProgressIndicator modalityProgress)
In many implementations, grants to this progress indicator its own modality state.
|
void |
setText(java.lang.String text)
Sets text above the progress bar
|
void |
setText2(java.lang.String text)
Sets text under the progress bar
|
void |
start()
Marks the process as started.
|
default void |
startNonCancelableSection()
Deprecated.
|
void |
stop()
Marks the process as finished.
|
void start()
ProgressManager
internals, shouldn't be called from client code
unless you know what you're doing.void stop()
ProgressManager
internals, shouldn't be called from client code
unless you know what you're doing.boolean isRunning()
void cancel()
boolean isCanceled()
checkCanceled()
is called instead.cancel()
void setText(java.lang.String text)
text
- Text to setsetText2(String)
java.lang.String getText()
setText(String)
void setText2(java.lang.String text)
text
- Text to setsetText(String)
java.lang.String getText2()
setText2(String)
double getFraction()
setFraction(double)
void setFraction(double fraction)
setIndeterminate(boolean)
void pushState()
void popState()
@Deprecated default void startNonCancelableSection()
ProgressManager.executeNonCancelableSection(Runnable)
instead@Deprecated default void finishNonCancelableSection()
ProgressManager.executeNonCancelableSection(Runnable)
insteadboolean isModal()
setModalityProgress(ProgressIndicator)
ModalityState getModalityState()
ModalityState.defaultModalityState()
on threads associated with this progress.
By default, depending on implementation, it's ModalityState.NON_MODAL
or current modality at the moment of progress indicator creation.
It can be later modified by setModalityProgress(ProgressIndicator)
, but it mostly makes sense for processes showing modal dialogs.void setModalityProgress(ProgressIndicator modalityProgress)
isModal()
, which, if not accompanied by showing a modal dialog,
might affect the whole IDE adversely: e.g. actions won't be executed, editor typing won't work, and all that with no visible indication.boolean isIndeterminate()
void setIndeterminate(boolean indeterminate)
setFraction(double)
).void checkCanceled() throws ProcessCanceledException
ProgressManager.checkCanceled()
where you don't need to know current indicator and pass it around.ProcessCanceledException
- if this progress has been canceled, i.e. isCanceled()
returns true.boolean isPopupWasShown()
boolean isShowing()