Class ProgressMonitorDialog
- All Implemented Interfaces:
- IRunnableContext,- IShellProvider
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.
- 
Nested Class SummaryNested classes/interfaces inherited from class org.eclipse.jface.window.WindowWindow.IExceptionHandler
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected CursorThe cursor used in the cancel button;protected ButtonThe Cancel button control.protected booleanIndicates whether the Cancel button is to be enabled.protected booleanIndicates whether the Cancel button is to be shown.protected ProgressIndicatorThe progress indicator control.protected LabelThe label control for the subtask.protected LabelThe label control for the task.Fields inherited from class org.eclipse.jface.dialogs.IconAndMessageDialogimageLabel, message, messageLabelFields inherited from class org.eclipse.jface.dialogs.DialogblockedHandler, 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, ELLIPSISFields inherited from class org.eclipse.jface.window.WindowCANCEL, OK, resizeHasOccurred
- 
Constructor SummaryConstructorsConstructorDescriptionProgressMonitorDialog(Shell parent) Creates a progress monitor dialog under the given shell.
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidCalled just before the operation is run.protected voidThe cancel button has been pressed.protected voidClear the cursors in the dialog.booleanclose()TheProgressMonitorDialogimplementation of this method only closes the dialog if there are no currently running runnables.protected voidconfigureShell(Shell shell) Configures the given shell in preparation for opening this window in it.protected voidcreateButtonsForButtonBar(Composite parent) Adds buttons to this dialog's button bar.protected voidcreateCancelButton(Composite parent) Creates the cancel button.protected ControlcreateDialogArea(Composite parent) Creates and returns the contents of the upper part of this dialog (above the button bar).protected voidDecrements the nesting depth of running operations.protected voidCalled just after the operation is run.protected ImagegetImage()Returns the image to display beside the message in this dialog.protected PointReturns the initial size to use for the shell.protected intReturns the nesting depth of running operations.booleanReturns whether the dialog should be opened before the operation is run.Returns the progress monitor to use for operations run in this progress dialog.protected voidIncrements the nesting depth of running operations.intopen()Opens this window, creating it first if it has not yet been created.voidrun(boolean fork, boolean cancelable, IRunnableWithProgress runnable) This implementation of IRunnableContext#run(boolean, boolean, IRunnableWithProgress) runs the givenIRunnableWithProgressusing the progress monitor for this progress dialog and blocks until the runnable has been run, regardless of the value offork.voidsetCancelable(boolean cancelable) Sets whether the progress dialog is cancelable or not.voidsetOpenOnRun(boolean openOnRun) Sets whether the dialog should be opened before the operation is run.protected voidsetOperationCancelButtonEnabled(boolean b) Helper to enable/disable Cancel button for this dialog.protected voidClear blocked state from the receiver.protected voidupdateForSetBlocked(IStatus reason) Set blocked state from the receiver.Methods inherited from class org.eclipse.jface.dialogs.IconAndMessageDialogcreateButtonBar, createContents, createDialogAndButtonArea, createMessageArea, getColumnCount, getErrorImage, getInfoImage, getMessageLabelStyle, getQuestionImage, getWarningImageMethods inherited from class org.eclipse.jface.dialogs.DialogapplyDialogFont, 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, shortenTextMethods inherited from class org.eclipse.jface.window.WindowcanHandleShellCloseEvent, 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
- 
Field Details- 
progressIndicatorThe progress indicator control.
- 
taskLabelThe label control for the task. Kept for backwards compatibility.
- 
subTaskLabelThe label control for the subtask.
- 
cancelThe Cancel button control.
- 
operationCancelableStateprotected boolean operationCancelableStateIndicates whether the Cancel button is to be shown.
- 
enableCancelButtonprotected boolean enableCancelButtonIndicates whether the Cancel button is to be enabled.
- 
arrowCursorThe cursor used in the cancel button;
 
- 
- 
Constructor Details- 
ProgressMonitorDialogCreates a progress monitor dialog under the given shell. The dialog has a standard title and no image.openis non-blocking.- Parameters:
- parent- the parent shell, or- nullto create a top-level shell
 
 
- 
- 
Method Details- 
updateForClearBlockedprotected void updateForClearBlocked()Clear blocked state from the receiver.
- 
updateForSetBlockedSet blocked state from the receiver.- Parameters:
- reason- IStatus that gives the details
 
- 
cancelPressedprotected void cancelPressed()The cancel button has been pressed.- Overrides:
- cancelPressedin class- Dialog
- Since:
- 3.0
 
- 
closepublic boolean close()TheProgressMonitorDialogimplementation of this method only closes the dialog if there are no currently running runnables.
- 
clearCursorsprotected void clearCursors()Clear the cursors in the dialog.- Since:
- 3.0
 
- 
configureShellDescription copied from class:WindowConfigures the given shell in preparation for opening this window in it.The default implementation of this framework method sets the shell's image and gives it a grid layout. Subclasses may extend or reimplement. - Overrides:
- configureShellin class- Window
- Parameters:
- shell- the shell
 
- 
createButtonsForButtonBarDescription copied from class:DialogAdds buttons to this dialog's button bar.The Dialogimplementation of this framework method adds standard ok and cancel buttons using thecreateButtonframework method. These standard buttons will be accessible fromgetCancelButton, andgetOKButton. 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.- Overrides:
- createButtonsForButtonBarin class- Dialog
- Parameters:
- parent- the button bar composite
 
- 
createCancelButtonCreates the cancel button.- Parameters:
- parent- the parent composite
- Since:
- 3.0
 
- 
createDialogAreaDescription copied from class:DialogCreates and returns the contents of the upper part of this dialog (above the button bar).The Dialogimplementation of this framework method creates and returns a newCompositewith 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 superas in the following example:Composite composite = (Composite) super.createDialogArea(parent); //add controls to composite as necessary return composite; - Overrides:
- createDialogAreain class- Dialog
- Parameters:
- parent- the parent composite to contain the dialog area
- Returns:
- the dialog area control
 
- 
getInitialSizeDescription copied from class:DialogReturns the initial size to use for the shell. Overridden to check whether a size has been stored in dialog settings. If a size has been stored, it is returned.- Overrides:
- getInitialSizein class- Dialog
- Returns:
- the initial size of the shell
- See Also:
 
- 
getProgressMonitorReturns the progress monitor to use for operations run in this progress dialog.- Returns:
- the progress monitor
 
- 
runpublic void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException This implementation of IRunnableContext#run(boolean, boolean, IRunnableWithProgress) runs the givenIRunnableWithProgressusing the progress monitor for this progress dialog and blocks until the runnable has been run, regardless of the value offork. The dialog is opened before the runnable is run, and closed after it completes. It is recommended thatforkis set to true in most cases. Ifforkis set tofalse, the runnable will run in the UI thread and it is the runnable's responsibility to callDisplay.readAndDispatch()to ensure UI responsiveness.- Specified by:
- runin interface- IRunnableContext
- Parameters:
- fork-- trueif the runnable should be run in a separate thread, and- falseto run in the same thread
- cancelable-- trueto enable the cancelation, and- falseto make the operation uncancellable
- runnable- the runnable to run
- Throws:
- InvocationTargetException- wraps any exception or error which occurs while running the runnable
- InterruptedException- propagated by the context if the runnable acknowledges cancelation by throwing this exception. This should not be thrown if cancelable is- false.
 
- 
getOpenOnRunpublic boolean getOpenOnRun()Returns whether the dialog should be opened before the operation is run. Defaults totrue- Returns:
- trueto open the dialog before run,- falseto only create the dialog, but not open it
- Since:
- 3.0
 
- 
setOpenOnRunpublic void setOpenOnRun(boolean openOnRun) Sets whether the dialog should be opened before the operation is run. NOTE: Setting this to false and not forking a process may starve any asyncExec that tries to open the dialog later.- Parameters:
- openOnRun-- trueto open the dialog before run,- falseto only create the dialog, but not open it
- Since:
- 3.0
 
- 
getNestingDepthprotected int getNestingDepth()Returns the nesting depth of running operations.- Returns:
- the nesting depth of running operations
- Since:
- 3.0
 
- 
incrementNestingDepthprotected void incrementNestingDepth()Increments the nesting depth of running operations.- Since:
- 3.0
 
- 
decrementNestingDepthprotected void decrementNestingDepth()Decrements the nesting depth of running operations.- Since:
- 3.0
 
- 
aboutToRunprotected void aboutToRun()Called just before the operation is run. Default behaviour is to open or create the dialog, based on the setting ofgetOpenOnRun, and increment the nesting depth.- Since:
- 3.0
 
- 
finishedRunprotected void finishedRun()Called just after the operation is run. Default behaviour is to decrement the nesting depth, and close the dialog.- Since:
- 3.0
 
- 
setCancelablepublic void setCancelable(boolean cancelable) Sets whether the progress dialog is cancelable or not.- Parameters:
- cancelable-- trueif the end user can cancel this progress dialog, and- falseif it cannot be canceled
 
- 
setOperationCancelButtonEnabledprotected void setOperationCancelButtonEnabled(boolean b) Helper to enable/disable Cancel button for this dialog.- Parameters:
- b-- trueto enable the cancel button, and- falseto disable it
- Since:
- 3.0
 
- 
getImageDescription copied from class:IconAndMessageDialogReturns the image to display beside the message in this dialog.Subclasses may override. - Specified by:
- getImagein class- IconAndMessageDialog
- Returns:
- the image to display beside the message
 
- 
openpublic int open()Description copied from class:WindowOpens this window, creating it first if it has not yet been created.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:OKandCANCEL.
 
-