1 19 package org.netbeans.test.j2ee.wizard; 20 21 import org.netbeans.api.project.Project; 22 import org.netbeans.jellytools.NewFileNameLocationStepOperator; 23 import org.netbeans.jellytools.NewFileWizardOperator; 24 import org.netbeans.jellytools.NewProjectNameLocationStepOperator; 25 import org.netbeans.jellytools.NewProjectWizardOperator; 26 import org.netbeans.jemmy.EventTool; 27 import org.netbeans.jemmy.operators.JComboBoxOperator; 28 import org.netbeans.jemmy.operators.JTextFieldOperator; 29 30 34 public class WizardUtils { 35 36 public static final int MODULE_WAR = 0; 37 public static final int MODULE_EJB = 1; 38 public static final int MODULE_EAR = 2; 39 public static final int MODULE_CAR = 3; 40 41 public static final int VERSION_1_4 = 0; 42 public static final int VERSION_5 = 1; 43 44 45 private WizardUtils() { 46 } 47 48 public static NewProjectWizardOperator createNewProject(String category, 49 String project) { 50 NewProjectWizardOperator npwo = NewProjectWizardOperator.invoke(); 51 npwo.selectCategory(category); 52 npwo.selectProject(project); 53 npwo.next(); 54 return npwo; 55 } 56 57 public static NewProjectNameLocationStepOperator setProjectNameLocation( 58 String name, String location) { 59 NewProjectNameLocationStepOperator op = new NewProjectNameLocationStepOperator(); 60 op.txtProjectName().setText(name); 61 op.txtProjectLocation().setText(location); 62 return op; 63 } 64 65 public static NewFileWizardOperator createNewFile(Project p, 66 String category, String filetype) { 67 NewFileWizardOperator nfwo = NewFileWizardOperator.invoke(); 68 new EventTool().waitNoEvent(500); 69 nfwo.cboProject().selectItem(p.toString()); 70 nfwo.selectCategory(category); 71 nfwo.selectFileType(filetype); 72 nfwo.next(); 73 return nfwo; 74 } 75 76 public static NewFileNameLocationStepOperator setFileNameLocation(String name, 77 String pkg, String srcRoot) { 78 NewFileNameLocationStepOperator op = new NewFileNameLocationStepOperator(); 79 new EventTool().waitNoEvent(500); 80 JTextFieldOperator jtfo = null; 81 if ((pkg.indexOf("entity") > -1) || (pkg.indexOf("websvc") > -1)) { 82 jtfo = new JTextFieldOperator(op, 1); 83 } else { 84 jtfo = new JTextFieldOperator(op, 0); 85 } 86 jtfo.clearText(); 87 jtfo.typeText(name); 88 new EventTool().waitNoEvent(1000); 89 JComboBoxOperator jcbo = null; 90 if (srcRoot != null) { 91 jcbo = new JComboBoxOperator(op, 0); 92 jcbo.selectItem(srcRoot); 93 } 94 new EventTool().waitNoEvent(1000); 95 jcbo = new JComboBoxOperator(op, 1); 96 jcbo.clearText(); 97 jcbo.typeText(pkg); 98 return op; 99 } 100 101 public static NewProjectNameLocationStepOperator setJ2eeSpecVersion( 102 NewProjectNameLocationStepOperator op, int moduleType, String version) { 103 JComboBoxOperator jcbo = null; 104 switch (moduleType) { 105 case MODULE_WAR: jcbo = new JComboBoxOperator(op, 3); break; 106 case MODULE_EJB: jcbo = new JComboBoxOperator(op, 0); break; 107 case MODULE_EAR: jcbo = new JComboBoxOperator(op, 1); break; 108 case MODULE_CAR: jcbo = new JComboBoxOperator(op, 2); break; 109 default: throw new IllegalArgumentException ("Invalid module type"); 110 } 111 boolean found = false; 112 int i = 0; 113 for (; i < jcbo.getItemCount(); i++) { 114 Object o = jcbo.getItemAt(i); 115 if (o.toString().indexOf(version) > 0) { 116 found = true; 117 break; 118 } 119 } 120 if (found) { 121 jcbo.selectItem(i); 122 } else { 123 throw new IllegalArgumentException ("Version: '" + version + "' was not found."); 124 } 125 return op; 126 } 127 128 } 129 | Popular Tags |