001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * Utils.java
044: *
045: * Created on 31 ���� 2005 �., 19:11
046: * @author psb
047: */
048:
049: package org.netbeans.test.umllib.tests.utils;
050:
051: import java.awt.event.KeyEvent;
052: import javax.swing.JTextField;
053: import org.netbeans.jellytools.MainWindowOperator;
054: import org.netbeans.jellytools.NewProjectWizardOperator;
055: import org.netbeans.jellytools.TreeTableOperator;
056: import org.netbeans.jellytools.actions.NewProjectAction;
057: import org.netbeans.jellytools.properties.Property;
058: import org.netbeans.jellytools.properties.PropertySheetOperator;
059: import org.netbeans.jemmy.EventTool;
060: import org.netbeans.jemmy.Timeout;
061: import org.netbeans.jemmy.drivers.DriverManager;
062: import org.netbeans.jemmy.drivers.input.KeyRobotDriver;
063: import org.netbeans.jemmy.drivers.input.MouseRobotDriver;
064: import org.netbeans.jemmy.operators.JButtonOperator;
065: import org.netbeans.jemmy.operators.JDialogOperator;
066: import org.netbeans.jemmy.operators.JLabelOperator;
067: import org.netbeans.jemmy.operators.JMenuBarOperator;
068: import org.netbeans.jemmy.operators.JTextFieldOperator;
069: import org.netbeans.jemmy.operators.JTreeOperator;
070: import org.netbeans.test.umllib.util.LabelsAndTitles;
071: import org.netbeans.test.umllib.util.OptionsOperator;
072:
073: /**
074: *
075: * @author psb
076: */
077: public class Utils {
078: //
079: private static boolean innerCall = false;
080: //
081: public static String defaultNewElementName = "Unnamed";
082: public static String defaultReturnType = "void";
083: public static String defaultAttributeType = "int";
084: public static String defaultAttributeVisibility = "private";
085: public static String defaultAttributeValue = "";
086: public static String defaultOperationVisibility = "public";
087: //
088: private static int minWait = 50;
089: private static int longWait = 500;
090:
091: {
092: DriverManager.setMouseDriver(new MouseRobotDriver(new Timeout(
093: "", 10)));
094: DriverManager.setKeyDriver(new KeyRobotDriver(new Timeout(
095: "autoDelay", 50)));
096: }
097:
098: //
099: public static void setTextProperty(String pName, String pValue) {
100: PropertySheetOperator ps = new PropertySheetOperator();
101: Property nmProp = new Property(ps, pName);
102: double nmPntX = ps.tblSheet().getCellRect(nmProp.getRow(), 1,
103: false).getCenterX();
104: double nmPntY = ps.tblSheet().getCellRect(nmProp.getRow(), 1,
105: false).getCenterY();
106: ps.clickMouse((int) nmPntX, (int) nmPntY, 1);
107: for (int i = 0; i < pValue.length(); i++)
108: ps.typeKey(pValue.charAt(i));
109: ps.pushKey(KeyEvent.VK_ENTER);
110: }
111:
112: //
113: public static void setDefaultPreferences() {
114: setDefaultPreferences("No");
115: }
116:
117: public static void setDefaultPreferences(String promptToSave) {
118: OptionsOperator op = OptionsOperator.invoke();
119: op = op.invokeAdvanced();
120: TreeTableOperator tr = op.treeTable();
121: tr.tree().selectPath(tr.tree().findPath("UML|New Project"));
122: tr.tree().waitSelected(tr.tree().findPath("UML|New Project"));
123: new EventTool().waitNoEvent(1000);
124: PropertySheetOperator ps = new PropertySheetOperator(op);
125: Property pr = new Property(ps, "Create New Diagram");
126: pr.setValue(1);
127: if (pr.getValue().equalsIgnoreCase("yes"))
128: pr.setValue(0);
129: //autosave diagrams
130: tr.tree().selectPath(tr.tree().findPath("UML"));
131: tr.tree().waitSelected(tr.tree().findPath("UML"));
132: pr = new Property(ps, "Prompt to Save Diagram");
133: pr.setValue(1);
134: if (!pr.getValue().equalsIgnoreCase(promptToSave))
135: pr.setValue(0);
136: new JButtonOperator(op, "Close").push();
137: }
138:
139: public static void commonTestsSetup(String workdir, String prName) {
140: commonTestsSetup(workdir, prName, "No");
141: }
142:
143: public static void commonTestsSetup(String workdir, String prName,
144: String promptToSave) {
145: //setDefaultPreferences(promptToSave);
146: new NewProjectAction().performMenu();
147: NewProjectWizardOperator newWizardOper = new NewProjectWizardOperator();
148: new EventTool().waitNoEvent(500);
149: try {
150: Thread.sleep(2000);
151: } catch (Exception ex) {
152: }
153: JTreeOperator catTree = new JTreeOperator(newWizardOper);
154: java.awt.Rectangle pth = catTree.getPathBounds(catTree
155: .findPath(LabelsAndTitles.UML_PROJECTS_CATEGORY));
156: catTree
157: .moveMouse(pth.x + pth.width / 3, pth.y + pth.height
158: / 2);
159: catTree.selectPath(catTree
160: .findPath(LabelsAndTitles.UML_PROJECTS_CATEGORY));
161: catTree.waitSelected(catTree
162: .findPath(LabelsAndTitles.UML_PROJECTS_CATEGORY));
163: new EventTool().waitNoEvent(500);
164: newWizardOper
165: .selectProject(LabelsAndTitles.ANALYSIS_UML_PROJECT_LABEL);
166: newWizardOper.next();
167: JLabelOperator ploL = new JLabelOperator(newWizardOper,
168: "Project Location:");
169: JTextFieldOperator ploT = new JTextFieldOperator(
170: (JTextField) (ploL.getLabelFor()));
171: ploT.clearText();
172: ploT.typeText(workdir);
173: JLabelOperator pnmL = new JLabelOperator(newWizardOper,
174: "Project Name:");
175: JTextFieldOperator pnmT = new JTextFieldOperator(
176: (JTextField) (pnmL.getLabelFor()));
177: pnmT.clearText();
178: pnmT.typeText(prName);
179: new JButtonOperator(newWizardOper, "Finish").push();
180: new JButtonOperator(new JDialogOperator("Create New Diagram"),
181: "Cancel").push();
182:
183: //properties
184: new JMenuBarOperator(MainWindowOperator.getDefault())
185: .pushMenu("Window|Properties");
186: new PropertySheetOperator();
187: new EventTool().waitNoEvent(500);
188:
189: }
190: //
191:
192: }
|