## Dialog settings

The org.eclipse.jface.dialogs package provides a utility class, DialogSettings, for storing and retrieving keyed values. You can use this class to save and retrieve primitive data types and string values that you associate with key names. The settings are loaded and saved using an XML file.

AbstractUIPlugin provides support for plug-in wide dialog settings stored in an XML file in your plug-in's directory. If a dialog settings file is not found in your plug-in directory, an empty DialogSettings will be created for you. When the plug-in is shut down, any settings that were added to it will be saved in an XML file and retrieved the next time the plug-in is started up.

You can access your dialog settings anywhere in your plug-in code. The following snippet shows how you could obtain the dialog settings for the readme tool.

       IDialogSettings settings = ReadmePlugin.getDefault().getDialogSettings();

Values are stored and retrieved using get and put methods. The get methods are named after the type of primitive that is being accessed. You can store and retrieve boolean, long, double, float, int, array, and string values. The following snippet shows how we could use dialog settings to initialize control values in a dialog.

       protected Control createDialogArea(Composite parent) {
          IDialogSettings settings = ReadmePlugin.getDefault().getDialogSettings();
          checkbox = new Button(parent,SWT.CHECK);
          checkbox.setText("Generate sample section titles");
          // initialize the checkbox according to the dialog settings
          checkbox.setSelection(settings.getBoolean("GenSections"));
       }

The value of the setting can be stored later when the ok button is pressed.

       protected void okPressed() {
          IDialogSettings settings = ReadmePlugin.getDefault().getDialogSettings();
          // store the value of the generate sections checkbox
          settings.put("GenSections", checkbox.getSelection());
          super.okPressed();
       }