TitleAreaDialog: MailDialog : Dialog « SWT JFace Eclipse « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » SWT JFace Eclipse » DialogScreenshots 
TitleAreaDialog: MailDialog


import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;

public class MailDialog extends TitleAreaDialog {
  // IDs for MailDialog buttons
  // We use large integers because we don't want
  // to conflict with system constants
  public static final int OPEN = 9999;

  public static final int DELETE 9998;

  // List widget
  List list;

  // Initial content of the list
  String[] items;

  // Selected items
  String[] itemsToOpen;

  /**
   * Constructor for MailDialog.
   
   @param shell -
   *            Containing shell
   @param items -
   *            Mail messages passed to the dialog
   */
  public MailDialog(Shell shell, String[] items) {
    super(shell);
    this.items = items;
  }

  /**
   @see org.eclipse.jface.window.Window#create() We complete the dialog with
   *      a title and a message
   */
  public void create() {
    super.create();
    setTitle("Mail");
    setMessage("You have mail! \n It could be vital for this evening...");
  }

  /**
   @see org.eclipse.jface.dialogs.Dialog#
   *      createDialogArea(org.eclipse.swt.widgets.Composite) Here we fill the
   *      center area of the dialog
   */
  protected Control createDialogArea(Composite parent) {
    // Create new composite as container
    final Composite area = new Composite(parent, SWT.NULL);
    // We use a grid layout and set the size of the margins
    final GridLayout gridLayout = new GridLayout();
    gridLayout.marginWidth = 15;
    gridLayout.marginHeight = 10;
    area.setLayout(gridLayout);
    // Now we create the list widget
    list = new List(area, SWT.BORDER | SWT.MULTI);
    // We define a minimum width for the list
    final GridData gridData = new GridData();
    gridData.widthHint = 200;
    list.setLayoutData(gridData);
    // We add a SelectionListener
    list.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {
        // When the selection changes, we re-validate the list
        validate();
      }
    });
    // We add the initial mail messages to the list
    for (int i = 0; i < items.length; i++) {
      list.add(items[i]);
    }
    return area;
  }

  private void validate() {
    // We select the number of selected list entries
    boolean selected = (list.getSelectionCount() 0);
    // We enable/disable the Open and Delete buttons
    getButton(OPEN).setEnabled(selected);
    getButton(DELETE).setEnabled(selected);
    if (!selected)
      // If nothing was selected, we set an error message
      setErrorMessage("Select at least one entry!");
    else
      // Otherwise we set the error message to null
      // to show the intial content of the message area
      setErrorMessage(null);
  }

  /**
   @see org.eclipse.jface.dialogs.Dialog#
   *      createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) We
   *      replace the OK and Cancel buttons by our own creations We use the
   *      method createButton() (from Dialog), to create the new buttons
   */
  protected void createButtonsForButtonBar(Composite parent) {
    // Create Open button
    Button openButton = createButton(parent, OPEN, "Open"true);
    // Initially deactivate it
    openButton.setEnabled(false);
    // Add a SelectionListener
    openButton.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {
        // Retrieve selected entries from list
        itemsToOpen = list.getSelection();
        // Set return code
        setReturnCode(OPEN);
        // Close dialog
        close();
      }
    });
    // Create Delete button
    Button deleteButton = createButton(parent, DELETE, "Delete"false);
    deleteButton.setEnabled(false);
    // Add a SelectionListener
    deleteButton.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {
        // Get the indices of the selected entries
        int selectedItems[] = list.getSelectionIndices();
        // Remove all these entries
        list.remove(selectedItems);
        // Now re-validate the list because it has changed
        validate();
      }
    });
    // Create Cancel button
    Button cancelButton = createButton(parent, CANCEL, "Cancel"false);
    // Add a SelectionListener
    cancelButton.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {
        setReturnCode(CANCEL);
        close();
      }
    });
  }

  /**
   * Method getItemsToOpen.
   
   @return String[] - the selected items
   */
  public String[] getItemsToOpen() {
    return itemsToOpen;
  }
}

           
       
Related examples in the same category
1. Dialog ShellDialog Shell
2. MessageBox ExampleMessageBox Example
3. Number Input DialogNumber Input Dialog
4. Dialog ExamplesDialog Examples
5. Demonstrates FileDialogDemonstrates FileDialog
6. A facade for the save FileDialog
7. How to create your own dialog classesHow to create your own dialog classes
8. Demonstrates the FontDialog classDemonstrates the FontDialog class
9. Demonstrates the ColorDialog classDemonstrates the ColorDialog class
10. Demonstrates the DirectoryDialog classDemonstrates the DirectoryDialog class
11. Demonstrates the custom InputDialog classDemonstrates the custom InputDialog class
12. Demonstrates the MessageBox classDemonstrates the MessageBox class
13. Dialog Example
14. Shell Dialog ExampleShell Dialog Example
15. Color Dialog ExampleColor Dialog Example
16. File Dialog ExampleFile Dialog Example
17. Font Dialog ExampleFont Dialog Example
18. Yes No Icon MessageBoxYes No Icon MessageBox
19. Print Dialog ExamplePrint Dialog Example
20. SWT Dialog ClassSWT Dialog Class
21. Prevent escape from closing a SWT dialogPrevent escape from closing a SWT dialog
22. Create a dialog shell (prompt for a value)Create a dialog shell (prompt for a value)
23. Create a SWT dialog shellCreate a SWT dialog shell
ww__w___.__ja___v_a___2___s__._c_o_m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.