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 javax.swing.JComboBox;
045: import javax.swing.JTextField;
046: import org.netbeans.jemmy.operators.CheckboxOperator;
047: import org.netbeans.jemmy.operators.JButtonOperator;
048: import org.netbeans.jemmy.operators.JCheckBoxOperator;
049: import org.netbeans.jemmy.operators.JComboBoxOperator;
050: import org.netbeans.jemmy.operators.JDialogOperator;
051: import org.netbeans.jemmy.operators.JLabelOperator;
052: import org.netbeans.jemmy.operators.JListOperator;
053: import org.netbeans.jemmy.operators.JTextFieldOperator;
054: import org.netbeans.jemmy.operators.Operator;
055:
056: public class NewPackageWizardOperator extends JDialogOperator {
057: public final static String TITLE = "New Package Wizard";
058: public final static String FINISH_BTN = "Finish";
059: public final static String CANCEL_BTN = "Cancel";
060:
061: public final static String CLASS_DIAGRAM = NewDiagramWizardOperator.CLASS_DIAGRAM;
062: public final static String SEQUENCE_DIAGRAM = NewDiagramWizardOperator.SEQUENCE_DIAGRAM;
063: public final static String COMPONENT_DIAGRAM = NewDiagramWizardOperator.COMPONENT_DIAGRAM;
064: public final static String COLLABORATION_DIAGRAM = NewDiagramWizardOperator.COLLABORATION_DIAGRAM;
065: public final static String ACTIVITY_DIAGRAM = NewDiagramWizardOperator.ACTIVITY_DIAGRAM;
066: public final static String DEPLOYMENT_DIAGRAM = NewDiagramWizardOperator.DEPLOYMENT_DIAGRAM;
067: public final static String STATE_DIAGRAM = NewDiagramWizardOperator.STATE_DIAGRAM;
068: public final static String USECASE_DIAGRAM = NewDiagramWizardOperator.USECASE_DIAGRAM;
069: //
070: private String DIAGRAM_NAME_LABEL = "Diagram Name:";
071: private String PACKAGE_NAME_LABEL = "Name:";
072: private String NAMESPACE_LABEL = "Namespace:";
073: private String DIAGRAM_TYPE_LABEL = "Diagram Type:";
074:
075: public NewPackageWizardOperator() {
076: super (TITLE);
077: }
078:
079: /**
080: *
081: * @param packageName
082: */
083: public void setPackageName(String packageName) {
084: JLabelOperator pnLbl = new JLabelOperator(
085: this ,
086: new JLabelOperator.JLabelByLabelFinder(
087: PACKAGE_NAME_LABEL,
088: new Operator.DefaultStringComparator(true, true)));
089: ;
090: JTextFieldOperator txtName = new JTextFieldOperator(
091: (JTextField) (pnLbl.getLabelFor()));
092: txtName.clearText();
093: txtName.typeText(packageName);
094: txtName.waitText(packageName);
095: }
096:
097: /**
098: *
099: * @param diagramName
100: */
101: public void setDiagramName(String diagramName) {
102: JLabelOperator dnLbl = new JLabelOperator(this ,
103: DIAGRAM_NAME_LABEL);
104: JTextFieldOperator txtName = new JTextFieldOperator(
105: (JTextField) (dnLbl.getLabelFor()));
106: txtName.clearText();
107: txtName.typeText(diagramName);
108: txtName.waitText(diagramName);
109: }
110:
111: /**
112: *
113: * @return
114: */
115: public boolean isDiagramCreationEnabled() {
116: JLabelOperator dnmL = new JLabelOperator(this ,
117: DIAGRAM_NAME_LABEL);
118: JTextFieldOperator dnmT = new JTextFieldOperator(
119: (JTextField) (dnmL.getLabelFor()));
120: return dnmT.isEnabled();
121: }
122:
123: /**
124: *
125: * @param create
126: */
127: public void setCreateDiagram(boolean create) {
128: //
129: if ((create && !isDiagramCreationEnabled())
130: || (!create && isDiagramCreationEnabled())) {
131: new JCheckBoxOperator(this ).clickMouse(1);
132: }
133: JLabelOperator dnLbl = new JLabelOperator(this ,
134: DIAGRAM_NAME_LABEL);
135: JTextFieldOperator txtName = new JTextFieldOperator(
136: (JTextField) (dnLbl.getLabelFor()));
137: try {
138: txtName.waitComponentEnabled();
139: } catch (InterruptedException ex) {
140: ex.printStackTrace();
141: }
142: }
143:
144: public void clickFinish() {
145: new JButtonOperator(this , FINISH_BTN).push();
146: this .waitClosed();
147: }
148:
149: public void clickCancel() {
150: new JButtonOperator(this , CANCEL_BTN).push();
151: this .waitClosed();
152: }
153:
154: /**
155: *
156: * @param diagramType
157: * @return
158: */
159: public boolean isDiagramAllowed(String diagramType) {
160: return (new JListOperator(this ).findItemIndex(diagramType) > -1);
161: }
162:
163: /**
164: *
165: * @param diagramType
166: */
167: public void setDiagramType(String diagramType) {
168: JLabelOperator dtLbl = new JLabelOperator(this ,
169: DIAGRAM_TYPE_LABEL);
170: JComboBoxOperator typeCmb = new JComboBoxOperator(
171: (JComboBox) (dtLbl.getLabelFor()));
172: typeCmb.selectItem(diagramType);
173: typeCmb.waitItemSelected(diagramType);
174: }
175:
176: /**
177: *
178: * @param path
179: */
180: public void setNamespace(String path) {
181: JLabelOperator nsLbl = new JLabelOperator(this , NAMESPACE_LABEL);
182: JComboBoxOperator namespaceCmb = new JComboBoxOperator(
183: (JComboBox) (nsLbl.getLabelFor()));
184: namespaceCmb.selectItem(path);
185: namespaceCmb.waitItemSelected(path);
186: }
187:
188: /**
189: *
190: * @param packageName
191: * @param diagramName
192: * @param diagramType
193: */
194: public void setScopedDiagram(String packageName,
195: String diagramName, String diagramType) {
196: setPackageName(packageName);
197: if (!isDiagramCreationEnabled()) {
198: setCreateDiagram(true);
199: }
200: setDiagramType(diagramType);
201: setDiagramName(diagramName);
202: }
203: }
|