public class ProgressMonitorDialog extends IconAndMessageDialog implements IRunnableContext
This concrete dialog class can be instantiated as is, or further subclassed as required.
Typical usage is:
try { IRunnableWithProgress op = ...; new ProgressMonitorDialog(activeShell).run(true, true, op); } catch (InvocationTargetException e) { // handle exception } catch (InterruptedException e) { // handle cancelation }
Note that the ProgressMonitorDialog is not intended to be used with multiple runnables - this dialog should be discarded after completion of one IRunnableWithProgress and a new one instantiated for use by a second or sebsequent IRunnableWithProgress to ensure proper initialization.
Note that not forking the process will result in it running in the UI which may starve the UI. The most obvious symptom of this problem is non responsiveness of the cancel button. If you are running within the UI Thread you should do the bulk of your work in another Thread to prevent starvation. It is recommended that fork is set to true in most cases.
Window.IExceptionHandler
Modifier and Type | Field and Description |
---|---|
protected Cursor |
arrowCursor
The cursor used in the cancel button;
|
protected Button |
cancel
The Cancel button control.
|
protected boolean |
enableCancelButton
Indicates whether the Cancel button is to be enabled.
|
protected boolean |
operationCancelableState
Indicates whether the Cancel button is to be shown.
|
protected ProgressIndicator |
progressIndicator
The progress indicator control.
|
protected Label |
subTaskLabel
The label control for the subtask.
|
protected Label |
taskLabel
The label control for the task.
|
imageLabel, message, messageLabel
blockedHandler, buttonBar, DIALOG_DEFAULT_BOUNDS, DIALOG_PERSISTLOCATION, DIALOG_PERSISTSIZE, dialogArea, DLG_IMG_ERROR, DLG_IMG_HELP, DLG_IMG_INFO, DLG_IMG_MESSAGE_ERROR, DLG_IMG_MESSAGE_INFO, DLG_IMG_MESSAGE_WARNING, DLG_IMG_QUESTION, DLG_IMG_WARNING, ELLIPSIS
CANCEL, OK, resizeHasOccurred
Constructor and Description |
---|
ProgressMonitorDialog(Shell parent)
Creates a progress monitor dialog under the given shell.
|
Modifier and Type | Method and Description |
---|---|
protected void |
aboutToRun()
Called just before the operation is run.
|
protected void |
cancelPressed()
The cancel button has been pressed.
|
protected void |
clearCursors()
Clear the cursors in the dialog.
|
boolean |
close()
The
ProgressMonitorDialog implementation of this method
only closes the dialog if there are no currently running runnables. |
protected void |
configureShell(Shell shell)
Configures the given shell in preparation for opening this window in it.
|
protected void |
createButtonsForButtonBar(Composite parent)
Adds buttons to this dialog's button bar.
|
protected void |
createCancelButton(Composite parent)
Creates the cancel button.
|
protected Control |
createDialogArea(Composite parent)
Creates and returns the contents of the upper part of this dialog (above
the button bar).
|
protected void |
decrementNestingDepth()
Decrements the nesting depth of running operations.
|
protected void |
finishedRun()
Called just after the operation is run.
|
protected Image |
getImage()
Returns the image to display beside the message in this dialog.
|
protected Point |
getInitialSize()
Returns the initial size to use for the shell.
|
protected int |
getNestingDepth()
Returns the nesting depth of running operations.
|
boolean |
getOpenOnRun()
Returns whether the dialog should be opened before the operation is run.
|
IProgressMonitor |
getProgressMonitor()
Returns the progress monitor to use for operations run in this progress
dialog.
|
protected void |
incrementNestingDepth()
Increments the nesting depth of running operations.
|
int |
open()
Opens this window, creating it first if it has not yet been created.
|
void |
run(boolean fork,
boolean cancelable,
IRunnableWithProgress runnable)
This implementation of IRunnableContext#run(boolean, boolean,
IRunnableWithProgress) runs the given
IRunnableWithProgress
using the progress monitor for this progress dialog and blocks until the
runnable has been run, regardless of the value of fork . |
void |
setCancelable(boolean cancelable)
Sets whether the progress dialog is cancelable or not.
|
void |
setOpenOnRun(boolean openOnRun)
Sets whether the dialog should be opened before the operation is run.
|
protected void |
setOperationCancelButtonEnabled(boolean b)
Helper to enable/disable Cancel button for this dialog.
|
protected void |
updateForClearBlocked()
Clear blocked state from the receiver.
|
protected void |
updateForSetBlocked(IStatus reason)
Set blocked state from the receiver.
|
createButtonBar, createContents, createDialogAndButtonArea, createMessageArea, getErrorImage, getInfoImage, getMessageLabelStyle, getQuestionImage, getWarningImage
applyDialogFont, buttonPressed, convertHeightInCharsToPixels, convertHeightInCharsToPixels, convertHorizontalDLUsToPixels, convertHorizontalDLUsToPixels, convertVerticalDLUsToPixels, convertVerticalDLUsToPixels, convertWidthInCharsToPixels, convertWidthInCharsToPixels, create, createButton, dialogFontIsDefault, getBlockedHandler, getButton, getButtonBar, getCancelButton, getDialogArea, getDialogBoundsSettings, getDialogBoundsStrategy, getImage, getInitialLocation, getOKButton, initializeBounds, initializeDialogUnits, isResizable, okPressed, setBlockedHandler, setButtonLayoutData, setButtonLayoutFormData, shortenText
canHandleShellCloseEvent, constrainShellSize, createShell, getConstrainedShellBounds, getContents, getDefaultImage, getDefaultImages, getDefaultOrientation, getLayout, getParentShell, getReturnCode, getShell, getShellListener, getShellStyle, getWindowManager, handleFontChange, handleShellCloseEvent, setBlockOnOpen, setDefaultImage, setDefaultImages, setDefaultModalParent, setDefaultOrientation, setExceptionHandler, setParentShell, setReturnCode, setShellStyle, setWindowManager
protected ProgressIndicator progressIndicator
protected Label taskLabel
protected Label subTaskLabel
protected Button cancel
protected boolean operationCancelableState
protected boolean enableCancelButton
protected Cursor arrowCursor
public ProgressMonitorDialog(Shell parent)
open
is non-blocking.parent
- the parent shell, or null
to create a top-level
shellprotected void updateForClearBlocked()
protected void updateForSetBlocked(IStatus reason)
reason
- IStatus that gives the detailsprotected void cancelPressed()
cancelPressed
in class Dialog
public boolean close()
ProgressMonitorDialog
implementation of this method
only closes the dialog if there are no currently running runnables.close
in class Dialog
true
if the window is (or was already) closed, and
false
if it is still openWindow.close()
protected void clearCursors()
protected void configureShell(Shell shell)
Window
The default implementation of this framework method sets the shell's image and gives it a grid layout. Subclasses may extend or reimplement.
configureShell
in class Window
shell
- the shellprotected void createButtonsForButtonBar(Composite parent)
Dialog
The Dialog
implementation of this framework method adds
standard ok and cancel buttons using the createButton
framework method. These standard buttons will be accessible from
getCancelButton
, and getOKButton
.
Subclasses may override.
Note: The common button order is: {other buttons}, OK, Cancel.
On some platforms, Dialog.initializeBounds()
will move the default button to the right.
createButtonsForButtonBar
in class Dialog
parent
- the button bar compositeprotected void createCancelButton(Composite parent)
parent
- the parent compositeprotected Control createDialogArea(Composite parent)
Dialog
The Dialog
implementation of this framework method creates
and returns a new Composite
with standard margins and
spacing.
The returned control's layout data must be an instance of
GridData
. This method must not modify the parent's
layout.
Subclasses must override this method but may call super
as
in the following example:
Composite composite = (Composite) super.createDialogArea(parent); //add controls to composite as necessary return composite;
createDialogArea
in class Dialog
parent
- the parent composite to contain the dialog areaprotected Point getInitialSize()
Dialog
getInitialSize
in class Dialog
Dialog.getDialogBoundsSettings()
,
Dialog.getDialogBoundsStrategy()
public IProgressMonitor getProgressMonitor()
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException
IRunnableWithProgress
using the progress monitor for this progress dialog and blocks until the
runnable has been run, regardless of the value of fork
.
The dialog is opened before the runnable is run, and closed after it
completes. It is recommended that fork
is set to true in
most cases. If fork
is set to false
, the
runnable will run in the UI thread and it is the runnable's
responsibility to call Display.readAndDispatch()
to ensure
UI responsiveness.run
in interface IRunnableContext
fork
- true
if the runnable should be run in a separate thread,
and false
to run in the same threadcancelable
- true
to enable the cancelation, and
false
to make the operation uncancellablerunnable
- the runnable to runInvocationTargetException
- wraps any exception or error which occurs
while running the runnableInterruptedException
- propagated by the context if the runnable
acknowledges cancelation by throwing this exception. This should not be thrown
if cancelable is false
.public boolean getOpenOnRun()
true
true
to open the dialog before run,
false
to only create the dialog, but not open itpublic void setOpenOnRun(boolean openOnRun)
openOnRun
- true
to open the dialog before run,
false
to only create the dialog, but not open
itprotected int getNestingDepth()
protected void incrementNestingDepth()
protected void decrementNestingDepth()
protected void aboutToRun()
getOpenOnRun
,
and increment the nesting depth.protected void finishedRun()
public void setCancelable(boolean cancelable)
cancelable
- true
if the end user can cancel this progress
dialog, and false
if it cannot be canceledprotected void setOperationCancelButtonEnabled(boolean b)
b
- true
to enable the cancel button, and
false
to disable itprotected Image getImage()
IconAndMessageDialog
Subclasses may override.
getImage
in class IconAndMessageDialog
public int open()
Window
If this window has been configured to block on open (
setBlockOnOpen
), this method waits until the window is
closed by the end user, and then it returns the window's return code;
otherwise, this method returns immediately. A window's return codes are
window-specific, although two standard return codes are predefined:
OK
and CANCEL
.
open
in class Window
Window.create()
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.