KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > j2ee > wizard > WizardUtils


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 /**
31  *
32  * @author jungi
33  */

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     /** Creates a new instance of WizardUtils */
45     private WizardUtils() {
46     }
47     
48     public static NewProjectWizardOperator createNewProject(String JavaDoc category,
49             String JavaDoc 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 JavaDoc name, String JavaDoc 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 JavaDoc category, String JavaDoc 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 JavaDoc name,
77             String JavaDoc pkg, String JavaDoc 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 JavaDoc 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 JavaDoc("Invalid module type");
110             }
111         boolean found = false;
112         int i = 0;
113         for (; i < jcbo.getItemCount(); i++) {
114             Object JavaDoc 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 JavaDoc("Version: '" + version + "' was not found.");
124         }
125         return op;
126     }
127
128 }
129
Popular Tags