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. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.