Sciology = Science + Technology

Commonsense in Technology

JFace Dialogs : which one is right for you ?

Posted by sureshkrishna on March 15, 2008

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:

About these ads

12 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 said

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

  3. Wishwas said

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

  4. [...] a dialog may be suffcient; depends on how much you want to do with your ui. see dialogs for details (maybe TitleAreaDialog?) Or you can try JFace Wizards which are also very powerfull [...]

  5. SlowStrider said

    Thank you, this is useful! Right after making my own version of the ListSelectionDialog I found your page… oops… :D

  6. Pawan said

    Hi

    Can you tell me any way to create Wizard Interface Dialog (<> and finish dialog) using JFace?
    I can write bulk code to design UI for this, but I want to know if any easy way available which can minimize my efforts.

    Thanks

  7. John said

    would have been better to include some sample code here

  8. Andrey said

    Thanks! Great stuff

  9. Joseph said

    ElementListSelectionDialog, ListDialog, TwoPaneElementSelector, ListSelectionDialog, ElementTreeSelectionDialog, and CheckedTreeSelectionDialog are all in the org.eclipse.ui.dialogs package, not JFace. This means while they can be used for plugin development there cannot be used in a standalone RCP application. Although it seems that some of them may work anyway. I spent a week fighting with a ElementListSelectionDialog to come to this conclusion.

  10. I’d like to thank you for the efforts you have put in writing this website. I am hoping to see the same high-grade blog posts from you in the future as well. In fact, your creative writing abilities has motivated me to get my own, personal site now ;)

  11. Greetings from Carolina! I’m bored to death at work so I decided to browse your blog on my iphone during lunch break. I love the knowledge you present here and can’t wait to take a look when I get
    home. I’m amazed at how fast your blog loaded on my phone .. I’m
    not even using WIFI, just 3G .. Anyhow, very good blog!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 39 other followers

%d bloggers like this: