E mail preference page java

Here is an example of a simple email preference page in Java:

EmailPreferencePage.java

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.PreferencePage;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

public class EmailPreferencePage extends PreferencePage {
    private StringFieldEditor emailField;
    private BooleanFieldEditor notifyOnNewEmailField;
    private Button saveButton;

    @Override
    public void createControl(Composite parent) {
        Composite composite = new Composite(parent, SWT.NONE);
        composite.setLayout(new FormLayout());

        // Email field
        emailField = new StringFieldEditor("email", "Email:", composite);
        FormData formData = new FormData();
        formData.top = new FormAttachment(0);
        formData.left = new FormAttachment(0);
        formData.right = new FormAttachment(100);
        formData.bottom = new FormAttachment(100);
        emailField.getControl().setLayoutData(formData);

        // Notify on new email field
        notifyOnNewEmailField = new BooleanFieldEditor("notifyOnNewEmail", "Notify on new email:", composite);
        formData = new FormData();
        formData.top = new FormAttachment(emailField.getControl(), 10);
        formData.left = new FormAttachment(0);
        formData.right = new FormAttachment(100);
        formData.bottom = new FormAttachment(100);
        notifyOnNewEmailField.getControl().setLayoutData(formData);

        // Save button
        saveButton = new Button(composite, SWT.PUSH);
        saveButton.setText("Save");
        formData = new FormData();
        formData.top = new FormAttachment(notifyOnNewEmailField.getControl(), 10);
        formData.left = new FormAttachment(0);
        formData.right = new FormAttachment(100);
        formData.bottom = new FormAttachment(100);
        saveButton.setLayoutData(formData);

        saveButton.addSelectionListener(new SelectionListener() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                save();
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                save();
            }
        });

        setControl(composite);
    }

    private void save() {
        // Save the preferences
        String email = emailField.getStringValue();
        boolean notifyOnNewEmail = notifyOnNewEmailField.getBooleanValue();
        // Save the preferences to the preference store
        getPreferenceStore().setValue("email", email);
        getPreferenceStore().setValue("notifyOnNewEmail", notifyOnNewEmail);
    }

    @Override
    public boolean performOk() {
        save();
        return true;
    }
}

This code creates a simple preference page with two fields: an email field and a boolean field to notify on new emails. The page also has a save button that saves the preferences to the preference store.

How to use:

  1. Create a new Java class that extends PreferencePage.
  2. Override the createControl method to create the UI components (fields, buttons, etc.).
  3. Use the StringFieldEditor and BooleanFieldEditor classes to create the fields.
  4. Use the FormData class to layout the components.
  5. Add a selection listener to the save button to save the preferences when the button is clicked.
  6. Override the performOk method to save the preferences when the OK button is clicked.

Note: This is a basic example and you may want to add more features, such as error handling, validation, and internationalization.

Also: This code uses the Eclipse JFace framework, which is part of the Eclipse SDK. If you are not using Eclipse, you may need to use a different framework or library to create a preference page.