Eclipse Platform
2.0

org.eclipse.jface.dialogs
Class ProgressMonitorDialog

java.lang.Object
  |
  +--org.eclipse.jface.window.Window
        |
        +--org.eclipse.jface.dialogs.Dialog
              |
              +--org.eclipse.jface.dialogs.ProgressMonitorDialog
All Implemented Interfaces:
IRunnableContext

public class ProgressMonitorDialog
extends Dialog
implements IRunnableContext

A modal dialog that displays progress during a long running operation.

This concete 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
 }
 


Nested Class Summary
 
Nested classes inherited from class org.eclipse.jface.window.Window
Window.IExceptionHandler
 
Field Summary
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.
 
Fields inherited from class org.eclipse.jface.dialogs.Dialog
DLG_IMG_ERROR, DLG_IMG_INFO, DLG_IMG_MESSAGE_ERROR, DLG_IMG_MESSAGE_INFO, DLG_IMG_MESSAGE_WARNING, DLG_IMG_QUESTION, DLG_IMG_WARNING
 
Fields inherited from class org.eclipse.jface.window.Window
CANCEL, OK
 
Constructor Summary
ProgressMonitorDialog(Shell parent)
          Creates a progress monitor dialog under the given shell.
 
Method Summary
 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  Control createDialogArea(Composite parent)
          Creates and returns the contents of the upper part of this dialog (above the button bar).
protected  Point getInitialSize()
          Returns the initial size to use for the shell.
 IProgressMonitor getProgressMonitor()
          Returns the progress monitor to use for operations run in this progress dialog.
 void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
          Runs the given IRunnableWithProgress in this context.
 void setCancelable(boolean cancelable)
          Sets whether the progress dialog is cancelable or not.
 
Methods inherited from class org.eclipse.jface.dialogs.Dialog
buttonPressed, cancelPressed, constrainShellSize, convertHeightInCharsToPixels, convertHeightInCharsToPixels, convertHorizontalDLUsToPixels, convertHorizontalDLUsToPixels, convertVerticalDLUsToPixels, convertVerticalDLUsToPixels, convertWidthInCharsToPixels, convertWidthInCharsToPixels, createButton, createButtonBar, createContents, getButton, getButtonBar, getCancelButton, getDialogArea, getImage, getOKButton, initializeDialogUnits, okPressed
 
Methods inherited from class org.eclipse.jface.window.Window
create, createShell, getContents, getDefaultImage, getInitialLocation, getParentShell, getReturnCode, getShell, getShellListener, getShellStyle, getWindowManager, handleFontChange, handleShellCloseEvent, initializeBounds, open, setBlockOnOpen, setDefaultImage, setExceptionHandler, setReturnCode, setShellStyle, setWindowManager
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

progressIndicator

protected ProgressIndicator progressIndicator
The progress indicator control.


taskLabel

protected Label taskLabel
The label control for the task.


subTaskLabel

protected Label subTaskLabel
The label control for the subtask.


cancel

protected Button cancel
The Cancel button control.


operationCancelableState

protected boolean operationCancelableState
Indicates whether the Cancel button is to be shown.


enableCancelButton

protected boolean enableCancelButton
Indicates whether the Cancel button is to be enabled.

Constructor Detail

ProgressMonitorDialog

public ProgressMonitorDialog(Shell parent)
Creates a progress monitor dialog under the given shell. The dialog has a standard title and no image. open is non-blocking.

Parameters:
parent - the parent shell
Method Detail

close

public boolean close()
The ProgressMonitorDialog implementation of this method only closes the dialog if there are no currently running runnables.

Overrides:
close in class Window
Returns:
true if the window is (or was already) closed, and false if it is still open

configureShell

protected void configureShell(Shell shell)
Description copied from class: Window
Configures 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:
configureShell in class Window
Parameters:
shell - the shell

createButtonsForButtonBar

protected void createButtonsForButtonBar(Composite parent)
Description copied from class: Dialog
Adds buttons to this dialog's button bar.

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.

Overrides:
createButtonsForButtonBar in class Dialog
Parameters:
parent - the button bar composite

createDialogArea

protected Control createDialogArea(Composite parent)
Description copied from class: Dialog
Creates and returns the contents of the upper part of this dialog (above the button bar).

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.

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;
 

Overrides:
createDialogArea in class Dialog
Parameters:
parent - the parent composite to contain the dialog area
Returns:
the dialog area control

getInitialSize

protected Point getInitialSize()
Description copied from class: Window
Returns the initial size to use for the shell. The default implementation returns the preferred size of the shell, using Shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).

Overrides:
getInitialSize in class Window
Returns:
the initial size of the shell

getProgressMonitor

public IProgressMonitor getProgressMonitor()
Returns the progress monitor to use for operations run in this progress dialog.

Returns:
the progress monitor

run

public void run(boolean fork,
                boolean cancelable,
                IRunnableWithProgress runnable)
         throws InvocationTargetException,
                InterruptedException
Description copied from interface: IRunnableContext
Runs the given IRunnableWithProgress in this context. For example, if this is a ProgressMonitorDialog then the runnable is run using this dialog's progress monitor.

Specified by:
run in interface IRunnableContext
Parameters:
fork - true if the runnable should be run in a separate thread, and false to run in the same thread
cancelable - true to enable the cancelation, and false to 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

setCancelable

public void setCancelable(boolean cancelable)
Sets whether the progress dialog is cancelable or not.

Parameters:
cancelable - true if the end user can cancel this progress dialog, and false if it cannot be canceled

Eclipse Platform
2.0

Copyright (c) IBM Corp. and others 2000, 2002. All Rights Reserved.