JFace Dialogs : which one is right for you ?

JFace framework of Eclipse provides many standard and useful dialogs and a framework to build custom dialogs and wizards. When the standard dialogs seems to be too simple for your plugin or RCP developement, one can extend the standard dialogs to suite their own needs. The aim of this article is to provide example oriented approach to dialogs and see in depth of all frequently used dialogs. I am hoping to have this article as the point of reference for many developers to get Dialogs overview.

Dialogs are modal UI components which would do some user interaction tasks. Traditionally Dialogs are used to enter a simple input, to select a choice from a list, to select multiple nodes from a tree, to inform about a success/failure from an operation, to input confirmations from the user, etc…

Eclipse provides standard dialogs from two different frameworks, SWT provides very basic dialogs like FontDialog, ColorDialog, DirectoryDialog, FileDialog and FontDialog. These SWT dialogs are coming out of the SWT as they are very basic and has close connection to the OS. All these Dialogs are available from org.eclipse.swt.widgets package from the org.eclipse.swt.<platform>.jar.

JFace provides a variety of Dialogs for the implementers to extend or to use them directly. Its interesting to look into variety of dialogs provided by JFace and i would leave the usage to your imagination and context. Rest of this article is mostly code, screen shots and less of textual description. I tried to keep the short, sweet and simple.

FileDialog: This is a SWT Dialog but worth mentioning under the general concept of the Dialogs.

“Instances of this class allow the user to navigate the file system and select or enter a file name. Note: Only one of the styles SAVE and OPEN may be specified.

IMPORTANT: This class is intended to be subclassed <em>only</em> within the SWT implementation.”

File Dialog

Information Dialogs: These dialogs are used to inform user about some event and take some necessary action. There are different Dialogs under this category.

ErrorDialog : A dialog to display one or more errors to the user, as contained in an IStatus object. If an error contains additional detailed information then a Details button is automatically supplied, which shows or hides an error details viewer when pressed by the user.

Error Dialog

MessageDialog : “A dialog for showing messages to the user. This concrete dialog class can be instantiated as is, or further subclassed as required.

Information Dialog
Question Dialog

InputDialog: This Dialog is used for a very general paradigm to process some input from the user. Generally its not recommended to use this for input of complex data and for large number of input fields.

InputDialog

PrinterDialog: “Instances of this class allow the user to select a printer and various print-related parameters prior to starting a print job. IMPORTANT: This class is intended to be subclassed only within the SWT implementation.

Print Dialog

ProgressMonitorDialog: This is a very important Dialog component most of the applications would use. This Dialog is used to represent any time consuming task or to provide a long running workspace task to the user. Proper care must be taken to show accurate information of progress information to the user.

Progress Dialog

TitleAreaDialog: “A dialog that has a title area for displaying a title and an image as well as a common area for displaying a description, a message, or an error message. This dialog class may be subclassed.

This is the class that i often use for “About MyCompany” kind of dialogs.

TitleArea Dialog

ElementListSelectionDialog:A class to select elements out of a list of elements.

ElementListSelectionDialog

ListDialog:A dialog that prompts for one element out of a list of elements. Uses IStructuredContentProvider to provide the elements and ILabelProvider to provide their labels.

ListDialog

TwoPaneElementSelector:A list selection dialog with two panes. Duplicated entries will be folded together and are displayed in the lower pane (qualifier).”

TwoPaneElementDialog

List SelectionDialog:A standard dialog which solicits a list of selections from the user. This class is configured with an arbitrary data model represented by content and label provider objects. The getResult method returns the selected elements.

ListSelectionDialog

ElementTreeSelectionDialog:A dialog class to select elements out of a tree structure.

ElementTreeSelectionDialog

CheckedTreeSelectionDialog: “A dialog class to select elements out of a tree structure”

CheckedTreeSelectionDialog

Some Notes :

  • YesNoCancelListSelectionDialog has been Deprecated in 3.3 of Eclipse.
  • RCP Product extensions and custmizations can be done via AboutDialogs.
    • AboutDialog
    • AboutFeaturesDialog
    • AboutPluginsDialog
    • AboutSystemDialog

    Note : Above Dialogs are internal dialogs and not APIs. They are mentioned only as a reference.

  • PrintDialog is intended to be sub-classes by the clients and use it for identifying the printers and other parameters for print job.
  • SaveAsDialog is not available in Eclipse 3.3

Conclusion: Dialogs are a great way to present simple data and receive user input. Its very important to understand several Dialogs provided by JFace and use them appropriately.

References:

This entry was posted in eclipse, java, plugins, software and tagged , , , . Bookmark the permalink.

4 Responses to JFace Dialogs : which one is right for you ?

  1. Interesting, I never new that I can use so many rich dialogs from Eclipse!

    Perhaps you should open a bug against a few of these requesting that they be moved to a public package, in order to encourage more usage.

  2. Guenther says:

    Thanks for the list of the Dialog, This is a great overview of the Dialogs.

  3. Wishwas says:

    Great post dude !!! Got to try more of these dialogs in Mercury 🙂

  4. Pingback: How to show new window after click on button - Java Forums

Leave a Reply

Your email address will not be published. Required fields are marked *