-
Notifications
You must be signed in to change notification settings - Fork 44
Wizards
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).
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
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
/*******************************************************************************
* Copyright (c) 2016 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
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 {
/**
* Instantiates a new new java class wizard page.
*/
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();
}
}
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).
/*******************************************************************************
* Copyright (c) 2016 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
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");
}
}
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();
}
}