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: * CLDUtils.java
044: *
045: * Created on April 20, 2005, 11:26 AM
046: *
047: * To change this template, choose Tools | Options and locate the template under
048: * the Source Creation and Management node. Right-click the template and choose
049: * Open. You can then make changes to the template in the Source Editor.
050: */
051:
052: package org.netbeans.test.uml.classdiagram.utils;
053:
054: import org.netbeans.jellytools.NewProjectWizardOperator;
055: import org.netbeans.jellytools.ProjectsTabOperator;
056: import org.netbeans.jellytools.TreeTableOperator;
057: import org.netbeans.jellytools.actions.DeleteAction;
058: import org.netbeans.jellytools.actions.OpenAction;
059: import org.netbeans.jellytools.actions.RenameAction;
060: import org.netbeans.jellytools.nodes.Node;
061: import org.netbeans.jellytools.nodes.ProjectRootNode;
062: import org.netbeans.jellytools.properties.Property;
063: import org.netbeans.jellytools.properties.PropertySheetOperator;
064: import org.netbeans.jemmy.EventTool;
065: import org.netbeans.jemmy.JemmyProperties;
066: import org.netbeans.jemmy.operators.JButtonOperator;
067: import org.netbeans.jemmy.operators.JDialogOperator;
068: import org.netbeans.jemmy.operators.JTextFieldOperator;
069: import org.netbeans.test.umllib.DiagramOperator;
070: import org.netbeans.test.umllib.ElementTypes;
071: import org.netbeans.test.umllib.LinkTypes;
072: import org.netbeans.test.umllib.NewDiagramWizardOperator;
073: import org.netbeans.test.umllib.NewUMLProjectStepOperator;
074: import org.netbeans.test.umllib.Utils;
075: import org.netbeans.test.umllib.actions.AddDiagramAction;
076: import org.netbeans.test.umllib.actions.CloseDiagramAction;
077: import org.netbeans.test.umllib.testcases.UMLTestCase;
078: import org.netbeans.test.umllib.util.LabelsAndTitles;
079: import org.netbeans.test.umllib.util.OptionsOperator;
080: import org.netbeans.test.umllib.util.PopupConstants;
081:
082: /**
083: *
084: * @author VijayaBabu Mummaneni
085: */
086: public class CLDUtils {
087:
088: public static String CDFS_XTEST_PROJECT_DIR = UMLTestCase.XTEST_PROJECT_DIR
089: + "/Projects-Class";
090:
091: /**
092: * Creates a new instance of CLDUtils
093: */
094: public CLDUtils() {
095: }
096:
097: public static void setProjectCreationPreferences() {
098: OptionsOperator op = OptionsOperator.invoke();
099: op = op.invokeAdvanced();
100: TreeTableOperator tr = op.treeTable();
101: tr.tree().selectPath(tr.tree().findPath("UML|New Project"));
102: tr.tree().waitSelected(tr.tree().findPath("UML|New Project"));
103: new EventTool().waitNoEvent(1000);
104: PropertySheetOperator ps = new PropertySheetOperator(op);
105: Property pr = new Property(ps, "Create New Diagram");
106: pr.setValue(1);
107: if (pr.getValue().equalsIgnoreCase("yes"))
108: pr.setValue(0);
109: new JButtonOperator(op, "Close").push();
110: }
111:
112: public static ProjectRootNode createNewUMLProject(String projName,
113: String folderName) {
114: //setProjectCreationPreferences();
115: ProjectRootNode root = null;
116: int repCount = 5;
117: try {
118: NewProjectWizardOperator wizard = NewProjectWizardOperator
119: .invoke();
120: while (repCount > 0) { //Very unstable due to Tootip NPE (From Collab ????)
121: try {
122: wizard
123: .selectCategory(LabelsAndTitles.UML_PROJECTS_CATEGORY);
124: repCount = 0;
125: } catch (Exception e) {
126: repCount--;
127: }
128: }
129: wizard
130: .selectProject(LabelsAndTitles.JAVA_UML_PROJECT_LABEL);
131: wizard.next();
132: NewUMLProjectStepOperator umlWizard = new NewUMLProjectStepOperator();
133: umlWizard.txtProjectName().setText(projName);
134: umlWizard.txtProjectLocation().setText(folderName);
135: //umlWizard.cbSetAsMainProject().changeSelection(false);
136: umlWizard.finish();
137: new JButtonOperator(new JDialogOperator(
138: "Create New Diagram"), "Cancel").push();
139: Thread.sleep(1000);
140:
141: ProjectsTabOperator pto = ProjectsTabOperator.invoke();
142: root = new ProjectRootNode(pto.tree(), projName);
143:
144: } catch (Exception e) {
145: e.printStackTrace();
146: throw new RuntimeException(e);
147: }
148:
149: return root;
150: }
151:
152: public static Node createNewClassDiagram(String classDiagramName,
153: String projName) throws Exception {
154: Node cldNode = null;
155: ProjectsTabOperator pto = ProjectsTabOperator.invoke();
156: ProjectRootNode root = new ProjectRootNode(pto.tree(), projName
157: + "|Model");
158: new AddDiagramAction().performPopup(root);
159: NewDiagramWizardOperator newDWO = new NewDiagramWizardOperator();
160: newDWO.setDiagramType(NewDiagramWizardOperator.CLASS_DIAGRAM);
161: newDWO.setDiagramName(classDiagramName);
162: newDWO.clickOK();
163: Thread.sleep(1000);
164: cldNode = new ProjectRootNode(pto.tree(), projName
165: + "|Diagrams|" + classDiagramName);
166: return cldNode;
167: }
168:
169: public static Node openDiagram(String classDiagramName,
170: String projName, String howToOpen) {
171: ProjectsTabOperator pto = ProjectsTabOperator.invoke();
172: new EventTool().waitNoEvent(1000);
173: ProjectRootNode root = new ProjectRootNode(pto.tree(), projName);
174: Node node = new Node(root, "Diagrams|" + classDiagramName);
175: if (howToOpen.equals("pop-up")) {
176: new OpenAction().performPopup(node);
177: } else if (howToOpen.equals("double-click")) {
178: pto.tree().clickOnPath(node.getTreePath(), 2);
179: } else if (howToOpen.equals("short-cut")) {
180: new OpenAction().performShortcut(node);
181: }
182: return node;
183: }
184:
185: public static Node closeDiagram(Node node, String howToClose) {
186: return closeDiagram(node, howToClose, "");
187: }
188:
189: public static Node closeDiagram(Node node, String howToClose,
190: String diagramName) {
191: if (howToClose.equals("pop-up")) {
192: // new CloseDiagramAction().performPopup(node); "Close" popup item doesn't exist
193:
194: new DiagramOperator(diagramName).close();
195: //new TopComponentOperator(diagramName).close();
196: } else if (howToClose.equals("double-click")) {
197: node.tree().clickOnPath(node.getTreePath(), 2);
198: } else if (howToClose.equals("short-cut")) {
199: new CloseDiagramAction().performShortcut(node);
200: }
201: return node;
202: }
203:
204: public static Node renameNode(Node node, String newName,
205: String howToRename) {
206: if (howToRename.equals("pop-up")) {
207: new RenameAction().performPopup(node);
208: } else if (howToRename.equals("double-click")) {
209: node.tree().clickOnPath(node.getTreePath(), 2);
210: } else if (howToRename.equals("short-cut")) {
211: new RenameAction().performShortcut(node);
212: }
213: JDialogOperator jdo = new JDialogOperator("Rename");
214: JTextFieldOperator tfOper = new JTextFieldOperator(jdo, 0);
215: // clear text field
216: tfOper.clearText();
217: // tfOper.setText("");
218: tfOper.typeText(newName);
219: JButtonOperator btOper = new JButtonOperator(jdo, "OK");
220: btOper.push();
221:
222: return node;
223: }
224:
225: public static Node deleteNode(Node node, String howToDelete) {
226: if (howToDelete.equals("pop-up")) {
227: new DeleteAction().performPopup(node);
228: } else if (howToDelete.equals("double-click")) {
229: node.tree().clickOnPath(node.getTreePath(), 2);
230: } else if (howToDelete.equals("short-cut")) {
231: new DeleteAction().performShortcut(node);
232: }
233: return node;
234: }
235:
236: public static DiagramOperator openDiagram(String pName,
237: String dName, String dType, String path) {
238: long timeout = JemmyProperties
239: .getCurrentTimeout("DiagramOperator.WaitDiagramOperator");
240: JemmyProperties.setCurrentTimeout(
241: "DiagramOperator.WaitDiagramOperator", 3000);
242: try {
243: DiagramOperator diagram = new DiagramOperator(dName);
244: return diagram;
245: } catch (Exception e) {
246: } finally {
247: JemmyProperties.setCurrentTimeout(
248: "DiagramOperator.WaitDiagramOperator", timeout);
249: }
250:
251: ProjectsTabOperator pto = ProjectsTabOperator.invoke();
252: ProjectRootNode root = null;
253: timeout = JemmyProperties
254: .getCurrentTimeout("JTreeOperator.WaitNextNodeTimeout");
255: JemmyProperties.setCurrentTimeout(
256: "JTreeOperator.WaitNextNodeTimeout", 3000);
257: try {
258: root = new ProjectRootNode(pto.tree(), pName);
259: } catch (Exception e) {
260: try {
261: Utils.createAnalysisUMLProject(pName, path);
262: } catch (Exception e1) {
263: JemmyProperties.setCurrentTimeout(
264: "JTreeOperator.WaitNextNodeTimeout", timeout);
265: return null;
266: }
267: root = new ProjectRootNode(pto.tree(), pName);
268: }
269:
270: try {
271: Node nodeDiagrams = new Node(root, "Diagrams");
272: Node nodeDiagram = new Node(nodeDiagrams, dName);
273: pto.tree().clickOnPath(nodeDiagram.getTreePath(), 2);
274: } catch (Exception e) {
275: Node nodeModel = new Node(root, "Model");
276: nodeModel
277: .performPopupActionNoBlock(PopupConstants.ADD_DIAGRAM);
278: NewDiagramWizardOperator wiz = new NewDiagramWizardOperator();
279: wiz.setDiagramType(dType);
280: wiz.setDiagramName(dName);
281: wiz.clickOK();
282: }
283: JemmyProperties.setCurrentTimeout(
284: "JTreeOperator.WaitNextNodeTimeout", timeout);
285: try {
286: Thread.sleep(500);
287: } catch (Exception ex) {
288: }
289: return new DiagramOperator(dName);
290: }
291:
292: public static ElementTypes[] getExpectedCLDPaletteElementTypes() {
293: ElementTypes[] et = { ElementTypes.CLASS,
294: ElementTypes.INTERFACE, ElementTypes.PACKAGE,
295: ElementTypes.COLLABORATION_LIFELINE,
296: ElementTypes.ENUMERATION, ElementTypes.NODE,
297: ElementTypes.DATATYPE, ElementTypes.ARTIFACT,
298: ElementTypes.ALIASED, ElementTypes.UTILITY_CLASS,
299: ElementTypes.ACTOR_LIFELINE,
300:
301: ElementTypes.BOUNDARY_CLASS,
302: ElementTypes.CONTROL_CLASS, ElementTypes.ENTITY_CLASS,
303:
304: ElementTypes.TEMPLATE_CLASS,
305: ElementTypes.DERIVATION_CLASSIFIER,
306:
307: ElementTypes.DESIGN_PATTERN, ElementTypes.ROLE,
308: ElementTypes.INTERFACE_ROLE, ElementTypes.ACTOR_ROLE,
309: ElementTypes.CLASS_ROLE, ElementTypes.USE_CASE_ROLE,
310: ElementTypes.ROLE_BINDING,
311:
312: ElementTypes.COMMENT, ElementTypes.LINK_COMMENT };
313:
314: return et;
315: }
316:
317: public static LinkTypes[] getExpectedCLDPaletteLinkTypes() {
318: LinkTypes[] lt = { LinkTypes.GENERALIZATION,
319: LinkTypes.IMPLEMENTATION, LinkTypes.NESTED_LINK,
320:
321: LinkTypes.DEPENDENCY, LinkTypes.REALIZE,
322: LinkTypes.USAGE, LinkTypes.PERMISSION,
323: LinkTypes.ABSTRACTION,
324:
325: LinkTypes.DERIVATION_EDGE,
326:
327: LinkTypes.ASSOCIATION, LinkTypes.COMPOSITION,
328: LinkTypes.NAVIGABLE_COMPOSITION, LinkTypes.AGGREGATION,
329: LinkTypes.NAVIGABLE_AGGREGATION,
330: LinkTypes.NAVIGABLE_ASSOCIATION,
331: LinkTypes.ASSOCIATION_CLASS, };
332:
333: return lt;
334: }
335:
336: public static Enum[] getExpectedCLDPaletteElements() {
337: Enum[] et = { ElementTypes.CLASS, ElementTypes.INTERFACE,
338: ElementTypes.PACKAGE,
339: ElementTypes.COLLABORATION_LIFELINE,
340: ElementTypes.ENUMERATION, ElementTypes.NODE,
341: ElementTypes.DATATYPE, ElementTypes.ARTIFACT,
342: ElementTypes.ALIASED, ElementTypes.UTILITY_CLASS,
343: ElementTypes.ACTOR, LinkTypes.GENERALIZATION,
344: LinkTypes.IMPLEMENTATION, LinkTypes.NESTED_LINK,
345:
346: ElementTypes.BOUNDARY_CLASS,
347: ElementTypes.CONTROL_CLASS, ElementTypes.ENTITY_CLASS,
348:
349: LinkTypes.DEPENDENCY, LinkTypes.REALIZE,
350: LinkTypes.USAGE, LinkTypes.PERMISSION,
351: LinkTypes.ABSTRACTION,
352:
353: ElementTypes.TEMPLATE_CLASS,
354: ElementTypes.DERIVATION_CLASSIFIER,
355: LinkTypes.DERIVATION_EDGE,
356:
357: LinkTypes.ASSOCIATION, LinkTypes.COMPOSITION,
358: LinkTypes.NAVIGABLE_COMPOSITION, LinkTypes.AGGREGATION,
359: LinkTypes.NAVIGABLE_AGGREGATION,
360: LinkTypes.NAVIGABLE_ASSOCIATION,
361: LinkTypes.ASSOCIATION_CLASS,
362:
363: ElementTypes.DESIGN_PATTERN, ElementTypes.ROLE,
364: ElementTypes.INTERFACE_ROLE, ElementTypes.ACTOR_ROLE,
365: ElementTypes.CLASS_ROLE, ElementTypes.USE_CASE_ROLE,
366: ElementTypes.ROLE_BINDING,
367:
368: ElementTypes.COMMENT, ElementTypes.LINK_COMMENT };
369:
370: return et;
371: }
372: }
|