Discover Eclipse's JFace Dialogs
The 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 suit 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 an overview of Dialogs.
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, and so on.
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 implementors 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."
FileDialog fsd = new FileDialog(shell);
fsd.setFilterExtensions(new String[] {"*.jpg"});
fsd.setText("Select My JPG Files...");
fsd.open();

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)





Comments
Florian Potschka replied on Sun, 2008/03/16 - 3:20pm
Mark Dexter replied on Thu, 2008/03/20 - 9:11pm
Hi. I'm using Eclipse 3.3 and I don't have the ElementListSelection or any of the ones you discuss after this. Are these new in 3.4? Thanks.
Florian Potschka replied on Fri, 2008/03/21 - 9:24am
in response to:
Mark Dexter
Mark Dexter replied on Fri, 2008/03/21 - 11:12am
Mark Dexter replied on Fri, 2008/03/21 - 3:31pm
I spoke to soon. The file "org.eclipse.ui.ide*.jar" is NOT the right one. It has a package called org.eclipse.ui.dialogs, but not these classes.
The correct JAR file is "org.eclipse.ui.workbench*.jar". This has all of the missing dialog classes. Thanks.
Mark Dexter replied on Fri, 2008/03/21 - 4:11pm
Well..., it appears that you also need the JAR org.eclipse.osgi_*.jar. Otherwise, it can't find the org.eclipse.osgi.util.NLS class (whatever that is). So I'm up to 7 external JAR files to use JFace. Mark
Later that day ... It works great! Six lines of code replaces 3 whole classes. Thanks!