1 19 20 package org.netbeans.test.java.gui; 21 22 import org.netbeans.jellytools.*; 23 import org.netbeans.jellytools.nodes.*; 24 import org.netbeans.jemmy.operators.*; 25 26 import java.io.File ; 27 import javax.swing.tree.TreeModel ; 28 import org.netbeans.jemmy.JemmyException; 29 import org.netbeans.jemmy.JemmyProperties; 30 import org.netbeans.jemmy.Waitable; 31 import org.netbeans.jemmy.Waiter; 32 import org.netbeans.test.java.Utilities; 33 34 36 40 public class GuiUtilities { 41 42 private static final String JAVA_BUNDLE_PATH = "org.netbeans.modules.java.project.Bundle"; 43 44 50 public static String createProject(String projectName, String workDir) { 51 NewProjectWizardOperator opc = NewProjectWizardOperator.invoke(); 52 53 ProjectsTabOperator pto = new ProjectsTabOperator(); 55 JTreeOperator tree = pto.tree(); 56 57 TreeModel tm = tree.getModel(); 58 Object root = tm.getRoot(); 59 for (int i=0; i<tm.getChildCount(root); i++) { 60 if ((tm.getChild(root, i).toString().equals(projectName)) || 63 (tm.getChild(root, i).toString().equals(projectName+" [Main]"))) { 64 Node pn = new ProjectsTabOperator().getProjectRootNode( 65 tm.getChild(root, i).toString()); 66 pn.select(); 67 pn.performPopupAction( 68 org.netbeans.jellytools.Bundle.getString( 69 "org.openide.nodes.Bundle", "Button_close")+" " 70 +org.netbeans.jellytools.Bundle.getString( 71 "org.netbeans.modules.project.ui.Bundle", 72 "ACSN_jLabel1")); 73 i--; 74 Utilities.takeANap(1000); 75 } 76 } 77 78 File f = new File (workDir); 80 if (f.exists()) { 81 Utilities.deleteDirectory(f); 82 } 83 84 JDialogOperator jdo = new JDialogOperator( 86 org.netbeans.jellytools.Bundle.getString( 87 "org.netbeans.modules.project.ui.Bundle", 88 "LBL_NewProjectWizard_Title")); 89 JTreeOperator jto = new JTreeOperator(jdo, 0); 90 91 boolean exitLoop = false; 92 System.out.println("Waiting for 'General'"); 93 for (int i=0; i<20; i++) { 94 System.out.println("Round "+i); 95 Utilities.takeANap(2000); 96 for (int j=0; j<jto.getChildCount(jto.getRoot()); j++) { 97 if (jto.getChild(jto.getRoot(), j).toString() == Bundle.getString( 98 "org.netbeans.modules.java.j2seproject.ui.wizards.Bundle", 99 "Templates/Project/Standard")) { 100 exitLoop = true; 101 System.out.println("General found"); 102 break; 103 } 104 } 105 if (exitLoop) break; 106 } 107 108 new Node(jto, Bundle.getString( 109 "org.netbeans.modules.java.j2seproject.ui.wizards.Bundle", 110 "Templates/Project/Standard")).select(); 111 opc.selectProject(Bundle.getString( 113 "org.netbeans.modules.java.j2seproject.ui.wizards.Bundle", 114 "Templates/Project/Standard/emptyJ2SE.xml")); 115 opc.next(); 116 117 NewProjectNameLocationStepOperator npnlso = new 119 NewProjectNameLocationStepOperator(); 120 npnlso.txtProjectName().setText(projectName); 121 npnlso.cbCreateMainClass().setSelected(false); 122 npnlso.txtProjectLocation().setText(workDir); 123 npnlso.finish(); 124 125 String projectDir = workDir+"/"+projectName; 126 127 129 139 140 new ProjectsTabOperator().getProjectRootNode(projectName); 142 143 return projectDir; 144 } 145 146 147 152 public static void createPackage(String projectName, String packageName) { 153 Node pn = new ProjectsTabOperator().getProjectRootNode( 155 projectName); 156 pn.select(); 157 158 NewFileWizardOperator op = NewFileWizardOperator.invoke(); 159 160 JDialogOperator jdo = new JDialogOperator( 162 org.netbeans.jellytools.Bundle.getString( 163 "org.netbeans.modules.project.ui.Bundle", 164 "LBL_NewFileWizard_Title")); 165 JTreeOperator jto = new JTreeOperator(jdo, 0); 166 boolean exitLoop = false; 167 for (int i=0; i<10; i++) { 168 for (int j=0; j<jto.getChildCount(jto.getRoot()); j++) { 169 if (jto.getChild(jto.getRoot(), j).toString()== 170 Bundle.getString("org.netbeans.modules.java.project.Bundle", 171 "Templates/Classes")) { 172 exitLoop = true; 173 break; 174 } 175 } 176 if (exitLoop) break; 177 Utilities.takeANap(1000); 178 } 179 180 op.selectCategory(Bundle.getString(JAVA_BUNDLE_PATH, 181 "Templates/Classes")); 182 op.selectFileType(Bundle.getString(JAVA_BUNDLE_PATH, 183 "Templates/Classes/Package")); 184 op.next(); 185 186 JTextFieldOperator tfp = new JTextFieldOperator(op, 0); 187 tfp.setText(packageName); 188 189 NewFileNameLocationStepOperator nfnlso = 191 new NewFileNameLocationStepOperator(); 192 nfnlso.txtObjectName().setText(packageName); 193 for (int i=0; i<10; i++) { 194 if (nfnlso.btFinish().isEnabled()) break; 195 Utilities.takeANap(1000); 196 } 197 nfnlso.finish(); 198 199 Node sample1Node = new Node(new SourcePackagesNode(projectName), 201 packageName); 202 } 203 204 210 public static void createClass(String projectName, String packageName, 211 String className) { 212 Node pn2 = new ProjectsTabOperator().getProjectRootNode( 213 projectName); 214 pn2.select(); 215 216 NewFileWizardOperator op2 = NewFileWizardOperator.invoke(); 218 219 JDialogOperator jdo = new JDialogOperator( 221 org.netbeans.jellytools.Bundle.getString( 222 "org.netbeans.modules.project.ui.Bundle", 223 "LBL_NewFileWizard_Title")); 224 JTreeOperator jto = new JTreeOperator(jdo, 0); 225 boolean exitLoop = false; 226 for (int i=0; i<10; i++) { 227 for (int j=0; j<jto.getChildCount(jto.getRoot()); j++) { 228 if (jto.getChild(jto.getRoot(), j).toString()== 229 Bundle.getString(JAVA_BUNDLE_PATH, 230 "Templates/Classes")) { 231 exitLoop = true; 232 break; 233 } 234 } 235 if (exitLoop) break; 236 Utilities.takeANap(1000); 237 } 238 239 op2.selectCategory(Bundle.getString(JAVA_BUNDLE_PATH, 240 "Templates/Classes")); 241 op2.selectFileType(Bundle.getString(JAVA_BUNDLE_PATH, 242 "Templates/Classes/Class.java")); 243 op2.next(); 244 245 JTextFieldOperator tf = new JTextFieldOperator(op2); 246 tf.setText(className); 247 248 op2.finish(); 249 250 Node sample2Node = new Node(new Node(new SourcePackagesNode( 252 projectName), packageName), className); 253 } 254 255 261 public static void createInterface(String projectName, String packageName, 262 String ifaceName) { 263 Node pn2 = new ProjectsTabOperator().getProjectRootNode( 264 projectName); 265 pn2.select(); 266 267 NewFileWizardOperator op2 = NewFileWizardOperator.invoke(); 269 270 JDialogOperator jdo = new JDialogOperator( 272 org.netbeans.jellytools.Bundle.getString( 273 "org.netbeans.modules.project.ui.Bundle", 274 "LBL_NewFileWizard_Title")); 275 JTreeOperator jto = new JTreeOperator(jdo, 0); 276 boolean exitLoop = false; 277 for (int i=0; i<10; i++) { 278 for (int j=0; j<jto.getChildCount(jto.getRoot()); j++) { 279 if (jto.getChild(jto.getRoot(), j).toString()== 280 Bundle.getString(JAVA_BUNDLE_PATH, 281 "Templates/Classes")) { 282 exitLoop = true; 283 break; 284 } 285 } 286 if (exitLoop) break; 287 Utilities.takeANap(1000); 288 } 289 290 op2.selectCategory(Bundle.getString(JAVA_BUNDLE_PATH, 291 "Templates/Classes")); 292 op2.selectFileType(Bundle.getString(JAVA_BUNDLE_PATH, 293 "Templates/Classes/Interface.java")); 294 op2.next(); 295 296 JTextFieldOperator tf = new JTextFieldOperator(op2); 297 tf.setText(ifaceName); 298 299 op2.finish(); 300 301 Node sample2Node = new Node(new Node(new SourcePackagesNode( 303 projectName), packageName), ifaceName); 304 } 305 306 314 public static String createProjectAndPackageAndClass(String projectName, 315 String packageName, String className, String workDir) { 316 String projectDir = createProject(projectName, workDir); 317 createPackage(projectName, packageName); 318 createClass(projectName, packageName, className); 319 return projectDir; 320 } 321 322 329 public static void deleteProject(String projectName, String className, 330 String workDir, boolean closeFiles) { 331 332 if (closeFiles) { 333 EditorOperator.closeDiscardAll(); 334 } 335 336 Node pn = new ProjectsTabOperator().getProjectRootNode( 337 projectName); 338 pn.select(); 339 340 pn.performPopupAction(org.netbeans.jellytools.Bundle.getString( 341 "org.openide.nodes.Bundle", "Button_close")+" " 342 +org.netbeans.jellytools.Bundle.getString( 343 "org.netbeans.modules.project.ui.Bundle", "ACSN_jLabel1")); 344 345 348 } 349 350 357 public static void waitForChildNode(String projectName, String parentPath, 358 String childName) { 359 ProjectsTabOperator pto = new ProjectsTabOperator(); 360 ProjectRootNode prn = pto.getProjectRootNode(projectName); 361 prn.select(); 362 Node parent = new Node(prn, parentPath); 363 final String finalFileName = childName; 364 try { 365 JemmyProperties.setCurrentTimeout("Waiter.WaitingTime", 30000); 367 new Waiter(new Waitable() { 368 public Object actionProduced(Object parent) { 369 return ((Node)parent).isChildPresent(finalFileName) ? 370 Boolean.TRUE: null; 371 } 372 public String getDescription() { 373 return("Waiting for the tree to load."); 374 } 375 }).waitAction(parent); 376 } catch (InterruptedException e) { 377 throw new JemmyException("Interrupted.", e); 378 } 379 } 380 381 } 382 | Popular Tags |