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: package org.netbeans.test.uml.dependencydiagram.utils;
043:
044: import org.netbeans.jellytools.ProjectsTabOperator;
045: import org.netbeans.jellytools.TreeTableOperator;
046: import org.netbeans.jellytools.nodes.Node;
047: import org.netbeans.jellytools.nodes.ProjectRootNode;
048: import org.netbeans.jellytools.properties.Property;
049: import org.netbeans.jellytools.properties.PropertySheetOperator;
050: import org.netbeans.jemmy.EventTool;
051: import org.netbeans.jemmy.JemmyProperties;
052: import org.netbeans.jemmy.operators.JButtonOperator;
053: import org.netbeans.test.umllib.DiagramOperator;
054: import org.netbeans.test.umllib.NewDiagramWizardOperator;
055: import org.netbeans.test.umllib.customelements.CollaborationDiagramOperator;
056: import org.netbeans.test.umllib.customelements.SequenceDiagramOperator;
057: import org.netbeans.test.umllib.project.ProjectType;
058: import org.netbeans.test.umllib.project.UMLProject;
059: import org.netbeans.test.umllib.util.OptionsOperator;
060: import org.netbeans.test.umllib.util.PopupConstants;
061:
062: public class DependencyUtils {
063:
064: private EventTool eventTool = new EventTool();
065:
066: public DependencyUtils() {
067: }
068:
069: public static DiagramOperator openDiagram(String pName,
070: String dName, String dType, String path) {
071: long timeout = JemmyProperties
072: .getCurrentTimeout("DiagramOperator.WaitDiagramOperator");
073: JemmyProperties.setCurrentTimeout(
074: "DiagramOperator.WaitDiagramOperator", 3000);
075: try {
076: DiagramOperator diagram = new DiagramOperator(dName);
077: return diagram;
078: } catch (Exception e) {
079: } finally {
080: JemmyProperties.setCurrentTimeout(
081: "DiagramOperator.WaitDiagramOperator", timeout);
082: }
083:
084: ProjectsTabOperator pto = ProjectsTabOperator.invoke();
085: ProjectRootNode root = null;
086: timeout = JemmyProperties
087: .getCurrentTimeout("JTreeOperator.WaitNextNodeTimeout");
088: JemmyProperties.setCurrentTimeout(
089: "JTreeOperator.WaitNextNodeTimeout", 3000);
090: try {
091: root = new ProjectRootNode(pto.tree(), pName);
092: } catch (Exception e) {
093: try {
094: UMLProject.createProject(pName,
095: ProjectType.UML_JAVA_PLATFORM_MODEL, path);
096: } catch (Exception e1) {
097: JemmyProperties.setCurrentTimeout(
098: "JTreeOperator.WaitNextNodeTimeout", timeout);
099: return null;
100: }
101: root = new ProjectRootNode(pto.tree(), pName);
102: }
103:
104: try {
105: Node nodeDiagrams = new Node(root, "Diagrams");
106: Node nodeDiagram = new Node(nodeDiagrams, dName);
107: pto.tree().clickOnPath(nodeDiagram.getTreePath(), 2);
108: } catch (Exception e) {
109: Node nodeModel = new Node(root, "Model");
110: nodeModel
111: .performPopupActionNoBlock(PopupConstants.ADD_DIAGRAM);
112: timeout = JemmyProperties
113: .getCurrentTimeout("DialogWaiter.WaitDialogTimeout");
114: JemmyProperties.setCurrentTimeout(
115: "DialogWaiter.WaitDialogTimeout", 3000);
116: NewDiagramWizardOperator wiz = new NewDiagramWizardOperator();
117: JemmyProperties.setCurrentTimeout(
118: "DialogWaiter.WaitDialogTimeout", timeout);
119: wiz.setDiagramType(dType);
120: wiz.setDiagramName(dName);
121: try {
122: Thread.sleep(100);
123: } catch (Exception ex) {
124: }
125: org.netbeans.test.umllib.util.Utils
126: .makeScreenShotCustom("createDiagram_");
127: wiz.clickFinish();
128: try {
129: Thread.sleep(500);
130: } catch (Exception ex) {
131: }
132: }
133: JemmyProperties.setCurrentTimeout(
134: "JTreeOperator.WaitNextNodeTimeout", timeout);
135: if (dType.equals(NewDiagramWizardOperator.SEQUENCE_DIAGRAM))
136: return new SequenceDiagramOperator(dName);
137: else if (dType
138: .equals(NewDiagramWizardOperator.COLLABORATION_DIAGRAM))
139: return new CollaborationDiagramOperator(dName);
140: else
141: return new DiagramOperator(dName);
142: }
143:
144: public static void setDefaultPreferences() {
145: OptionsOperator op = OptionsOperator.invoke();
146: op = op.invokeAdvanced();
147: TreeTableOperator tr = op.treeTable();
148: tr.tree().selectPath(tr.tree().findPath("UML|New Project"));
149: tr.tree().waitSelected(tr.tree().findPath("UML|New Project"));
150: new EventTool().waitNoEvent(1000);
151: PropertySheetOperator ps = new PropertySheetOperator(op);
152: Property pr = new Property(ps, "Create New Diagram");
153: pr.setValue(1);
154: if (pr.getValue().equalsIgnoreCase("yes"))
155: pr.setValue(0);
156: //autosave diagrams
157: tr.tree().selectPath(tr.tree().findPath("UML"));
158: tr.tree().waitSelected(tr.tree().findPath("UML"));
159: pr = new Property(ps, "Prompt to Save Diagram");
160: pr.setValue(1);
161: if (!pr.getValue().equalsIgnoreCase("No"))
162: pr.setValue(0);
163: //
164: new JButtonOperator(op, "Close").push();
165: }
166:
167: }
|