RCP Message Dialog

While developing applications, it’s common to have a common set of functionalities used across most applications.
Message dialogs are one of those examples. In Rich Client Platform (RCP) applications, it may take too much time finding which JFace dialog class suits better for a giving aim…

The following notes will help in identifying which dialog to use. All the methods needed are statically available in the org.eclipse.jface.dialogs.MessageDialog class:

  • MessageDialog.openConfirm, for a confirmation dialog with an Ok/Cancel button set.
  • MessageDialog.openError, for an error dialog with an Ok button.
  • MessageDialog.openInformation, for an information dialog with an Ok button.
  • MessageDialog.openQuestion, for a question dialog with and Yes/No button set.
  • MessageDialog.openWarning, for warning dialog with an Ok button.

The org.eclipse.jface.dialogs.MessageDialogWithToggle is similar,but allows the user to adjust a toggle setting, like Yes Always/Yes/No or Yes/No/Never.

One can use org.eclipse.jface.dialogs.DialogSettings for a dialog setting, supporting loading and saving of properties in an XML file.

One can use org.eclipse.jface.dialogs.ProgressMonitorDialog to display progress during a long running operation.

An, finally, one can design your own dialog windows.
To do it, one just has to extend the org.eclipse.jface.dialogs.IconAndMessageDialog class.

Note: in RCP, the shell can be obtained using
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();.

SWT File Dialog

During the development of an Rich Client Platform (RCP) it is common to develop a file browse dialog, here’s how to show a file dialog in SWT:

import org.eclipse.swt.widgets.FileDialog;

FileDialog dialog = new FileDialog(this.getShell(), SWT.NULL);
dialog.setFilterExtensions(new String[] { "*.txt", "*.*" });
dialog.setFilterNames(new String[] { "Text files", "All files" });
String path = dialog.open();
if (path != null) {
   File file = new File(path);
   if (file.isFile()) {
     System.out.println(file.toString());
   }
}

The snippet above filters by text files (*.txt) and all files (*.*) and it is easily applied to the click event of any button or file menu option.

Intenationalize RCP applications

To internationalize (i18n) and Rich Client Platform (RCP) application, also known as Eclipse Application, it’s not enough to download the language package. One also needs to download the language packs for the RCP core.

Here’s what it takes to i18n the core of an RCP application:

  1. Download the language packages from the Babel project using the Eclipse install/update mechanism.
  2. Open the RCP application “.product” file.
  3. Go to the “Configuration” section.
  4. Press “Add Required Plug-ins” button.

This last step is the “magical step”, it includes the i18n plugins to the RCP application.
You can identify the language plugins by their name. They come in the “<plugin>.nl_<language>” format. For instance, Portuguese JFace translation file is “org.eclipse.jface.nl_pt”.