Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Wizards

jbdevstudioqajenkins edited this page Jun 18, 2015 · 62 revisions

All wizard dialogs in RedDeer extend org.jboss.reddeer.eclipse.jface.wizard.WizardDialog class. It represents the dialog itself, not a concrete wizard page and offers methods like next, finish etc. It does not specify how the dialog is open (you instantiate the dialog once it is open in Eclipse).

New Wizard Dialog

Mostly you will extend org.jboss.reddeer.eclipse.jface.wizard.NewWizardDialog which is a special abstract subclass of wizard dialog. It represents wizards accessible by top menu (File -> New -> Other...). It contain logic for opening the wizard. Other examples of such a wizard are

  • org.jboss.reddeer.eclipse.jface.wizard.ImportWizardDialog
  • org.jboss.reddeer.eclipse.jface.wizard.ExportWizardDialog

Pages in Wizard Dialog

Wizard page represents the content of the wizard (text fields, combo boxes, etc.). Every wizard dialog can provide access to the wizard pages. This means that you do not have to find the concrete wizard page to use, it is created by the wizard dialog. To create a wizard page just extend org.jboss.reddeer.eclipse.jface.wizard.WizardPage as follows

package org.jboss.reddeer.eclipse.jdt.ui;

import org.jboss.reddeer.jface.wizard.WizardPage;
import org.jboss.reddeer.swt.impl.button.CheckBox;
import org.jboss.reddeer.swt.impl.text.LabeledText;

/**
 * Wizard page for creating a java class.
 */
public class NewJavaClassWizardPage extends WizardPage {

	public NewJavaClassWizardPage() {
		super();
	}
	
	/**
	 * Sets a given name.
	 * 
	 * @param name Name
	 */
	public void setName(String name){
		new LabeledText("Name:").setText(name);
	}
	
	/**
	 * Sets a given package name.
	 * 
	 * @param packageName Package name
	 */
	public void setPackage(String packageName) {
		new LabeledText("Package:").setText(packageName);
	}
	
	/**
	 * Sets a given source folder.
	 * 
	 * @param sourceFolder Source folder
	 */
	public void setSourceFolder(String sourceFolder){
		new LabeledText("Source folder:").setText(sourceFolder);
	}
	
	/**
	 * Sets generating static main method.
	 * 
	 * @param setMainMethod Indicates whether to generate static main method
	 */
	public void setStaticMainMethod(boolean setMainMethod) {
//		new CheckBox("public static void main(String[] args)").toggle(setMainMethod);
		new CheckBox(4).toggle(setMainMethod); // initiate with label doesnt work
	}
	
	/**
	 * Returns a package name.
	 * 
	 * @return package name
	 */
	public String getPackage(){
		return new LabeledText("Package:").getText();
	}
	
	/**
	 * Returns a class name.
	 * 
	 * @return Class name
	 */
	public String getName(){
		return new LabeledText("Name:").getText();
	}
	
	/**
	 * Returns a source folder.
	 * 
	 * @return Source folder
	 */
	public String getSourceFolder(){
		return new LabeledText("Source folder:").getText();
	}
}

source code

As you can see the wizard page can exist as a standalone unit. So, you can instantiate a wizard page by yourself but you can still use the dialog's methods next, cancel, finish etc.

For accessing pages from wizard dialog you have to add these pages to the wizard by the method addWizardPage(WizardPage page, int pageIndex). This approach allows you to add wizard pages at runtime. Then, you can get the page by calling getWizardPage() (or by getFirstPage() for the first page).

package org.jboss.reddeer.eclipse.jdt.ui;

import org.jboss.reddeer.jface.wizard.NewWizardDialog;

/**
 * Wizard dialog for creating a java class.
 */
public class NewJavaClassWizardDialog extends NewWizardDialog {
	
	/**
	 * Constructs the wizard with Java > Class.
	 */
	public NewJavaClassWizardDialog() {
		super("Java", "Class");
	}
	
	@Deprecated
	public NewJavaClassWizardPage getFirstPage() {
		return new NewJavaClassWizardPage();
	}
}

source code

Example

Example of using wizards in Red Deer framework

package org.jboss.reddeer.snippet.test.example;

import org.jboss.reddeer.eclipse.jdt.ui.NewJavaClassWizardDialog;
import org.jboss.reddeer.eclipse.jdt.ui.NewJavaClassWizardPage;
import org.junit.Test;

public class JavaWizardExample {

	@Test
	public void testJavaWizardDialogAndPage() {
		NewJavaClassWizardDialog wizard = new NewJavaClassWizardDialog();
		wizard.open();

		NewJavaClassWizardPage page = new NewJavaClassWizardPage();
		page.setName("MyClass");
		page.setPackage("org.reddeer.example");

		wizard.finish();
	}
	
}

source code

Clone this wiki locally