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: * EditControlOperator.java
044: *
045: */
046:
047: package org.netbeans.test.umllib;
048:
049: import java.awt.Frame;
050: import javax.swing.JComponent;
051: import javax.swing.JDialog;
052: import org.netbeans.jellytools.MainWindowOperator;
053: import org.netbeans.jemmy.ComponentChooser;
054: import org.netbeans.jemmy.Timeout;
055: import org.netbeans.jemmy.drivers.DriverManager;
056: import org.netbeans.jemmy.drivers.input.KeyRobotDriver;
057: import org.netbeans.jemmy.operators.JComponentOperator;
058: import org.netbeans.jemmy.operators.JDialogOperator;
059: import org.netbeans.jemmy.operators.JTextAreaOperator;
060: import org.netbeans.jemmy.operators.JTextFieldOperator;
061: import org.netbeans.modules.uml.ui.controls.editcontrol.EditControlImpl;
062:
063: /**
064: * class handles current EditControl
065: * @author psb
066: */
067: public class EditControlOperator extends JDialogOperator {
068:
069: static {
070: DriverManager.setKeyDriver(new KeyRobotDriver(new Timeout(
071: "autoDelay", 50)));
072: }
073:
074: private JDialogOperator ecFrame = null;
075:
076: /**
077: * Creates a new instance of first visible EditControlOperator
078: */
079: public EditControlOperator() {
080: super (new checkForEditControlDialog());
081: ecFrame = new JDialogOperator((JDialog) (this .getSource()));
082: }
083:
084: /**
085: * Creates a new instance of EditControlOperator
086: * use case insensitive an
087: * @param text in dialog
088: */
089: public EditControlOperator(String text) {
090: super (new checkForEditControlDialogByText(text));
091: ecFrame = new JDialogOperator((JDialog) (this .getSource()));
092: }
093:
094: /**
095: * Creates a new instance of EditControlOperator
096: * @param text in dialog
097: * @param ce -compare exactly
098: * @param cs - case sensitive
099: */
100: public EditControlOperator(String text, boolean ce, boolean cs) {
101: super (new checkForEditControlDialogByText(text, ce, cs));
102: ecFrame = new JDialogOperator((JDialog) (this .getSource()));
103: }
104:
105: /**
106: * Find textfield in edit control dialog
107: * we assume only one textfield in dialog for now
108: * @return JTextFieldOperator for first textfield in edit control dialog
109: */
110: public JTextFieldOperator getTextFieldOperator() {
111: return new JTextFieldOperator(this );
112: }
113:
114: /**
115: * Find textfield in edit control dialog
116: * we assume only one textfield in dialog for now
117: * @return JTextFieldOperator for first textfield in edit control dialog
118: */
119: public JTextAreaOperator getTextAreaOperator() {
120: return new JTextAreaOperator(this );
121: }
122:
123: /**
124: * TBD - check if there is TextAre instead of textfield
125: * @param text
126: */
127: public void typeText(String text) {
128: getTextFieldOperator().typeText(text);
129: getTextFieldOperator().typeKey('\n');
130: }
131:
132: };
133:
134: /**
135: * Findder for Edit Control dialog (based on current realization)
136: */
137: class checkForEditControlDialog implements ComponentChooser {
138: private String frameTitle = MainWindowOperator.getDefault()
139: .getTitle();
140:
141: /**
142: * chooser with all default values
143: */
144: checkForEditControlDialog() {
145: }
146:
147: //
148: /**
149: *
150: * @param comp
151: * @return
152: */
153: public boolean checkComponent(java.awt.Component comp) {
154: javax.swing.JDialog cmp = (javax.swing.JDialog) comp;
155: JComponent ec = JComponentOperator.findJComponent(cmp,
156: new checkETEditControlObject());
157: return ec != null
158: && cmp.isShowing()
159: && ((Frame) (comp.getParent())).getTitle().equals(
160: frameTitle);
161: }
162:
163: /**
164: *
165: * @return
166: */
167: public String getDescription() {
168: return "Try to find UML Edit Control Dialog.";
169: }
170: }
171:
172: class checkForEditControlDialogByText implements ComponentChooser {
173: private String text = null;
174: private boolean cs = false;
175: private boolean ce = false;
176: private String frameTitle = MainWindowOperator.getDefault()
177: .getTitle();
178:
179: /**
180: * find specific dialog with param name
181: * @param txt
182: */
183: checkForEditControlDialogByText(String txt) {
184: text = txt;
185: }
186:
187: /**
188: *
189: * @param txt
190: * @param e
191: * @param s
192: */
193: checkForEditControlDialogByText(String txt, boolean e, boolean s) {
194: ce = e;
195: cs = s;
196: text = txt;
197: }
198:
199: //
200: /**
201: *
202: * @param comp
203: * @return
204: */
205: public boolean checkComponent(java.awt.Component comp) {
206: javax.swing.JDialog cmp = (javax.swing.JDialog) comp;
207: JComponent ec = JComponentOperator.findJComponent(cmp,
208: new checkETEditControlObject());
209: return ec != null
210: && ((Frame) (comp.getParent())).getTitle().equals(
211: frameTitle)
212: && JTextFieldOperator.findJTextField(cmp, text, ce, cs) != null;
213: }
214:
215: /**
216: *
217: * @return
218: */
219: public String getDescription() {
220: return "Try to find UML Edit Control Dialog.";
221: }
222: }
223:
224: //-------------------
225: class checkETEditControlObject implements ComponentChooser {
226: /**
227: *
228: * @param comp
229: * @return
230: */
231: public boolean checkComponent(java.awt.Component comp) {
232: return comp.isShowing() && (comp instanceof EditControlImpl);
233: }
234:
235: /**
236: *
237: * @return
238: */
239: public String getDescription() {
240: return "Try to find showing ET EditControl Object.";
241: }
242: }
|