Application dialogs

When a standard dialog is too simple for your plug-in, you can build your own dialog using the Dialog class. Earlier, we saw how the readme tool contributed an "Open Readme Browser" action in an action set.  This action set is shown in the workbench tool bar and Window->Readme File Editor menu.  

Now we are ready to look at the implementation of this action in the readme tool's WindowActionDelegate.

   public void run(IAction action) {
      SectionsDialog dialog = new SectionsDialog(window.getShell(),
         ReadmeModelFactory.getInstance().getSections(selection));
      dialog.open();
   }

The window action delegate for the action set uses the current selection in the resource navigator view (the .readme file) to get a list of sections in the readme file. This list and the workbench window's shell are passed to the SectionsDialog. 

When the user selects the action, the SectionsDialog is opened.

The SectionsDialog is implemented in the readme tool plug-in by subclassing the Dialog class in the org.eclipse.jface.dialogs package.

The Dialog class provides basic support for building a dialog shell window, creating the common dialog buttons, and launching the dialog. The subclasses are responsible for handling the content of the dialog itself:

Dialogs can be as simple or as complicated as necessary. When you implement a dialog, most of your dialog code is concerned with creating the SWT controls that represent its content area and handling any events necessary while the dialog is up. Once a button is pressed by the user, the dialog can query the state of the various controls (or viewers) that make up the dialog to determine what to do.