SWT Wizard Composite : Wizard « 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 » WizardScreenshots 
SWT Wizard Composite

/*
SWT/JFace in Action
GUI Design with Eclipse 3.0
Matthew Scarpino, Stephen Holder, Stanford Ng, and Laurent Mihalkovic

ISBN: 1932394273

Publisher: Manning
*/


import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
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.Label;
import org.eclipse.swt.widgets.Text;

public class Ch11WizardComposite extends Composite {
  public Ch11WizardComposite(Composite parent) {
    super(parent, SWT.NONE);
    buildControls();
  }

  protected void buildControls() {
    final Composite parent = this;
    FillLayout layout = new FillLayout();
    parent.setLayout(layout);

    Button dialogBtn = new Button(parent, SWT.PUSH);
    dialogBtn.setText("Wizard Dialog...");
    dialogBtn.addSelectionListener(new SelectionListener() {

      public void widgetSelected(SelectionEvent e) {
        WizardDialog dialog = new WizardDialog(parent.getShell(),
            new ProjectWizard());
        dialog.open();
      }

      public void widgetDefaultSelected(SelectionEvent e) {
      }
    });
  }

}

class ProjectWizard extends Wizard {

  public ProjectWizard() {
    super();
  }

  public void addPages() {
    addPage(new DirectoryPage());
    addPage(new ChooseDirectoryPage());
    addPage(new SummaryPage());
  }

  public boolean performFinish() {
    DirectoryPage dirPage = getDirectoryPage();
    if (dirPage.useDefaultDirectory()) {
      System.out.println("Using default directory");
    else {
      ChooseDirectoryPage choosePage = getChoosePage();
      System.out.println("Using directory: " + choosePage.getDirectory());
    }
    return true;
  }

  private ChooseDirectoryPage getChoosePage() {
    return (ChooseDirectoryPagegetPage(ChooseDirectoryPage.PAGE_NAME);
  }

  private DirectoryPage getDirectoryPage() {
    return (DirectoryPagegetPage(DirectoryPage.PAGE_NAME);
  }

  public boolean performCancel() {
    System.out.println("Perform Cancel called");
    return true;
  }

  public IWizardPage getNextPage(IWizardPage page) {
    if (page instanceof DirectoryPage) {
      DirectoryPage dirPage = (DirectoryPagepage;
      if (dirPage.useDefaultDirectory()) {
        SummaryPage summaryPage = (SummaryPagegetPage(SummaryPage.PAGE_NAME);
        summaryPage.updateText("Using default directory");
        return summaryPage;
      }
    }

    IWizardPage nextPage = super.getNextPage(page);
    if (nextPage instanceof SummaryPage) {
      SummaryPage summary = (SummaryPagenextPage;
      DirectoryPage dirPage = getDirectoryPage();
      summary
          .updateText(dirPage.useDefaultDirectory() "Using default directory"
              "Using directory:"
                  + getChoosePage().getDirectory());
    }
    return nextPage;
  }
}

class SummaryPage extends WizardPage {
  public static final String PAGE_NAME = "Summary";

  private Label textLabel;

  public SummaryPage() {
    super(PAGE_NAME, "Summary Page"null);
  }

  public void createControl(Composite parent) {
    Composite topLevel = new Composite(parent, SWT.NONE);
    topLevel.setLayout(new FillLayout());

    textLabel = new Label(topLevel, SWT.CENTER);
    textLabel.setText("");

    setControl(topLevel);
    setPageComplete(true);
  }

  public void updateText(String newText) {
    textLabel.setText(newText);
  }
}

class DirectoryPage extends WizardPage {
  public static final String PAGE_NAME = "Directory";

  private Button button;

  public DirectoryPage() {
    super(PAGE_NAME, "Directory Page"null);
  }

  public void createControl(Composite parent) {
    Composite topLevel = new Composite(parent, SWT.NONE);
    topLevel.setLayout(new GridLayout(2false));

    Label l = new Label(topLevel, SWT.CENTER);
    l.setText("Use default directory?");

    button = new Button(topLevel, SWT.CHECK);

    setControl(topLevel);
    setPageComplete(true);
  }

  public boolean useDefaultDirectory() {
    return button.getSelection();
  }
}

class ChooseDirectoryPage extends WizardPage {
  public static final String PAGE_NAME = "Choose Directory";

  private Text text;

  public ChooseDirectoryPage() {
    super(PAGE_NAME, "Choose Directory Page"null);
  }

  public void createControl(Composite parent) {
    Composite topLevel = new Composite(parent, SWT.NONE);
    topLevel.setLayout(new GridLayout(2false));

    Label l = new Label(topLevel, SWT.CENTER);
    l.setText("Enter the directory to use:");

    text = new Text(topLevel, SWT.SINGLE);
    text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    setControl(topLevel);
    setPageComplete(true);
  }

  public String getDirectory() {
    return text.getText();
  }
}

           
       
Related examples in the same category
1. Wizard DemoWizard Demo
2. A survey using a wizardA survey using a wizard
3. An address book, using a wizard to add a new entryAn address book, using a wizard to add a new entry
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.