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.umllib;
043:
044: import java.awt.AWTException;
045: import java.awt.Point;
046: import java.awt.event.InputEvent;
047: import javax.swing.JList;
048: import javax.swing.JTextField;
049: import org.netbeans.jemmy.operators.JButtonOperator;
050: import org.netbeans.jemmy.operators.JComboBoxOperator;
051: import org.netbeans.jemmy.operators.JDialogOperator;
052: import org.netbeans.jemmy.operators.JLabelOperator;
053: import org.netbeans.jemmy.operators.JListOperator;
054: import org.netbeans.jemmy.operators.JTextFieldOperator;
055: import org.netbeans.test.umllib.exceptions.NotFoundException;
056:
057: public class NewDiagramWizardOperator extends JDialogOperator {
058: public final static String TITLE = "Create New Diagram";
059: public final static String FINISH_BTN = "Finish";
060: /**
061: * @deprecated ok button was replaced with finish button
062: */
063: public final static String OK_BTN = FINISH_BTN;
064: public final static String CANCEL_BTN = "Cancel";
065:
066: public final static String CLASS_DIAGRAM = "Class Diagram";
067: public final static String SEQUENCE_DIAGRAM = "Sequence Diagram";
068: public final static String COMPONENT_DIAGRAM = "Component Diagram";
069: public final static String COLLABORATION_DIAGRAM = "Collaboration Diagram";
070: public final static String ACTIVITY_DIAGRAM = "Activity Diagram";
071: public final static String DEPLOYMENT_DIAGRAM = "Deployment Diagram";
072: public final static String STATE_DIAGRAM = "State Diagram";
073: public final static String USECASE_DIAGRAM = "Use Case Diagram";
074: //
075: private String DIAGRAM_NAME_LABEL = "Diagram Name:";
076: private String NAMESPACE_LABEL = "Namespace:";
077: private String DIAGRAM_TYPE_LABEL = "Diagram Type:";
078:
079: public NewDiagramWizardOperator() {
080: super (TITLE);
081: }
082:
083: /**
084: *
085: * @param diagramName
086: */
087: public void setDiagramName(String diagramName) {
088: JLabelOperator dnLbl = new JLabelOperator(this ,
089: DIAGRAM_NAME_LABEL);
090: JTextFieldOperator txtName = new JTextFieldOperator(
091: (JTextField) (dnLbl.getLabelFor()));
092: //
093: txtName.waitComponentShowing(true);
094: try {
095: Thread.sleep(100);
096: } catch (Exception ex) {
097: }
098: //
099: //txtName.moveMouse(5,5);
100: //txtName.clickMouse(5,5,1);
101:
102: java.awt.Robot rb = null;
103: try {
104: rb = new java.awt.Robot();
105: Point p = txtName.getLocationOnScreen();
106: rb.mouseMove(p.x + 5, p.y + 5);
107: rb.mousePress(InputEvent.BUTTON1_MASK);
108: rb.mouseRelease(InputEvent.BUTTON1_MASK);
109: } catch (AWTException ex) {
110: ex.printStackTrace();
111: }
112:
113: try {
114: Thread.sleep(100);
115: } catch (Exception ex) {
116: }
117: //
118: try {
119: txtName.clearText();
120: } catch (org.netbeans.jemmy.TimeoutExpiredException ex) {
121: org.netbeans.test.umllib.util.Utils.makeScreenShotCustom(
122: null, "textClearing_");
123: throw ex;
124: }
125: txtName.typeText(diagramName);
126: txtName.waitText(diagramName);
127: }
128:
129: /**
130: * @deprecated ok button was replaced with finish button
131: */
132: public void clickOK() {
133: clickFinish();
134: }
135:
136: public void clickFinish() {
137: new JButtonOperator(this , FINISH_BTN).push();
138: this .waitClosed();
139: }
140:
141: public void clickCancel() {
142: new JButtonOperator(this , CANCEL_BTN).push();
143: this .waitClosed();
144: }
145:
146: /**
147: *
148: * @param diagramType
149: * @return
150: */
151: public boolean isDiagramAllowed(String diagramType) {
152: JLabelOperator dtLbl = new JLabelOperator(this ,
153: DIAGRAM_TYPE_LABEL);
154: return (new JListOperator((JList) (dtLbl.getLabelFor()))
155: .findItemIndex(diagramType) > -1);
156: }
157:
158: /**
159: *
160: * @param diagramType
161: */
162: public void setDiagramType(String diagramType) {
163: JLabelOperator dtLbl = new JLabelOperator(this ,
164: DIAGRAM_TYPE_LABEL);
165: JListOperator typeLst = new JListOperator((JList) (dtLbl
166: .getLabelFor()));
167: int index = typeLst.findItemIndex(diagramType);
168: if (index < 0) {
169: String listInfo = "Items:\n";
170: for (int i = 0; i < typeLst.getModel().getSize(); i++) {
171: listInfo += typeLst.getModel().getElementAt(i) + "\n";
172: }
173: throw new NotFoundException("Can't find " + diagramType
174: + " in List, all elemnts: " + listInfo);
175: }
176: typeLst.selectItem(index);
177: typeLst.waitItemSelection(index, true);
178: }
179:
180: /**
181: *
182: * @param path
183: */
184: public void setNamespace(String path) {
185: JComboBoxOperator namespaceCmb = new JComboBoxOperator(this);
186: namespaceCmb.selectItem(path);
187: namespaceCmb.waitItemSelected(path);
188: }
189: }
|