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.”
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.”
MessageDialog : “A dialog for showing messages to the user. This concrete dialog class can be instantiated as is, or further subclassed as required.”
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.
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.”
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.
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.
ElementListSelectionDialog: “A class to select elements out of a list of elements.”
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.”
TwoPaneElementSelector: “A list selection dialog with two panes. Duplicated entries will be folded together and are displayed in the lower pane (qualifier).”
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.“
ElementTreeSelectionDialog: “A dialog class to select elements out of a tree structure.”
CheckedTreeSelectionDialog: “A dialog class to select elements out of a tree structure”
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:
Ketan Padegaonkar said
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.
Guenther said
Thanks for the list of the Dialog, This is a great overview of the Dialogs.
Wishwas said
Great post dude !!! Got to try more of these dialogs in Mercury π
How to show new window after click on button - Java Forums said
[…] 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 […]
SlowStrider said
Thank you, this is useful! Right after making my own version of the ListSelectionDialog I found your page… oops… π
SlowStrider said
Oh well, at least my dialog has the advantage that it doesn’t require a Workbench.
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
John said
would have been better to include some sample code here
Andrey said
Thanks! Great stuff
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.
breast actives reviews said
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 π
breast actives review side effects said
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!
Fix Com.biomatters.plugins.treeviewer.treeviewerplugin.jar Errors - Windows XP, Vista, 7 & 8 said
[…] JFace Dialogs : which one is right for you ? Β« Sciology … β Mar 15, 2008Β Β· MessageDialog : βA dialog for showing messages to the user. This concrete dialog class can be instantiated as is, or further subclassed as required…. […]
Imperial Advance said
Imperial Advance
JFace Dialogs : which one is right for you ? Β« Sciology = Science + Technology
real estate said
real estate
JFace Dialogs : which one is right for you ? Β« Sciology = Science + Technology
Christian Gabby said
Weiter so ! Netter Beitrag π