Source Code Cross Referenced for DialogWaiter.java in  » IDE-Netbeans » jemmy » org » netbeans » jemmy » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » jemmy » org.netbeans.jemmy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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): Alexandre Iline.
025:         *
026:         * The Original Software is the Jemmy library.
027:         * The Initial Developer of the Original Software is Alexandre Iline.
028:         * 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:         * $Id$ $Revision$ $Date$
044:         *
045:         */
046:
047:        package org.netbeans.jemmy;
048:
049:        import java.awt.Component;
050:        import java.awt.Dialog;
051:        import java.awt.Window;
052:
053:        /**
054:         * A DialogWaiter is a utility class used to look or wait for Dialogs.
055:         * It contains methods to search for a Dialog among the currently
056:         * showing Dialogs as well as methods that wait for a Diaog to show
057:         * within an allotted time period.
058:         *
059:         * Searches and waits can either involve search criteria applied by a
060:         * ComponentChooser instance or a search criteria based on the Dialog
061:         * title.  Searches and waits can both be restricted to dialogs owned
062:         * by a given window.
063:         *
064:         * <BR><BR>Timeouts used: <BR>
065:         * DialogWaiter.WaitDialogTimeout - time to wait dialog displayed <BR>
066:         * DialogWaiter.AfterDialogTimeout - time to sleep after dialog has been dispayed <BR>
067:         *
068:         * @see org.netbeans.jemmy.Timeouts
069:         * 
070:         * @author Alexandre Iline (alexandre.iline@sun.com)
071:         */
072:
073:        public class DialogWaiter extends WindowWaiter implements  Timeoutable,
074:                Outputable {
075:
076:            private final static long WAIT_TIME = 60000;
077:            private final static long AFTER_WAIT_TIME = 0;
078:
079:            private Timeouts timeouts;
080:            private TestOut output;
081:
082:            /**
083:             * Constructor.
084:             */
085:            public DialogWaiter() {
086:                super ();
087:                setTimeouts(JemmyProperties.getProperties().getTimeouts());
088:            }
089:
090:            /**
091:             * Searches for a dialog.
092:             * Search among the currently showing dialogs for one that meets the search
093:             * criteria applied by the <code>ComponentChooser</code> parameter.
094:             * @param cc A component chooser used to define and apply the search criteria.
095:             * @return a reference to the first dialog that is showing and that
096:             * meets the search criteria.  If no such dialog can be found, a
097:             * <code>null</code> reference is returned.
098:             */
099:            public static Dialog getDialog(ComponentChooser cc) {
100:                return ((Dialog) WindowWaiter
101:                        .getWindow(new DialogSubChooser(cc)));
102:            }
103:
104:            /**
105:             * Searches for a dialog.
106:             * The search proceeds among the currently showing dialogs for the
107:             * <code>index+1</code>'th dialog that meets the criteria defined and
108:             * applied by the <code>ComonentChooser</code> parameter.
109:             * @param cc A component chooser used to define and apply the search criteria.
110:             * @param index The ordinal index of the dialog in the set of currently displayed
111:             * dialogs.  The first index is 0.
112:             * @return a reference to the <code>index+1</code>'th dialog that is showing
113:             * and that meets the search criteria.  If there are fewer than
114:             * <code>index+1</code> dialogs, a <code>null</code> reference is returned.
115:             */
116:            public static Dialog getDialog(ComponentChooser cc, int index) {
117:                return ((Dialog) WindowWaiter.getWindow(
118:                        new DialogSubChooser(cc), index));
119:            }
120:
121:            /**
122:             * Searches for a dialog by title.
123:             * The search proceeds among the currently showing dialogs for the first
124:             * with a suitable title.
125:             * @param title Dialog title or subtitle.
126:             * @param ce If <code>true</code> and the search is case sensitive, then a
127:             * match occurs when the <code>title</code> argument is a substring of a
128:             * dialog title.  If <code>false</code> and the search is case sensitive,
129:             * then the <code>title</code> argument and the dialog title must be the same.
130:             * If <code>true</code> and the search is case insensitive, then a match occurs
131:             * when the <code>title</code> argument is a substring of the dialog title after
132:             * changing both to upper case.  If <code>false</code> and the search is case
133:             * insensitive, then a match occurs when the <code>title</code> argument is a
134:             * substring of the dialog title after changing both to upper case.
135:             * @param cc If <code>true</code> the search is case sensitive; otherwise, the
136:             * search is case insensitive. 
137:             * @return a reference to the first dialog that is showing and that has a
138:             * suitable title.  If no such dialog can be found, a <code>null</code>
139:             * reference is returned.
140:             */
141:            public static Dialog getDialog(String title, boolean ce, boolean cc) {
142:                return ((Dialog) WindowWaiter
143:                        .getWindow(new DialogByTitleChooser(title, ce, cc)));
144:            }
145:
146:            /**
147:             * Searches for a dialog by title.
148:             * The search is for the <code>index+1</code>'th dialog among the currently
149:             * showing dialogs that possess a suitable title.
150:             * 
151:             * @param	title Dialog title or subtitle.
152:             * @param	ce If <code>true</code> and the search is case sensitive, then a
153:             * match occurs when the <code>title</code> argument is a substring of a
154:             * dialog title.  If <code>false</code> and the search is case sensitive,
155:             * then the <code>title</code> argument and the dialog title must be the same.
156:             * If <code>true</code> and the search is case insensitive, then a match occurs
157:             * when the <code>title</code> argument is a substring of the dialog title after
158:             * changing both to upper case.  If <code>false</code> and the search is case
159:             * insensitive, then a match occurs when the <code>title</code> argument is a
160:             * substring of the dialog title after changing both to upper case.
161:             * @param	cc If <code>true</code> the search is case sensitive; otherwise, the
162:             * search is case insensitive. 
163:             * @param	index Ordinal index between appropriate dialogs
164:             * @return	a reference to the <code>index+1</code>'th dialog that is showing
165:             * and that has a suitable title.  If there are fewer than
166:             * <code>index+1</code> dialogs, a <code>null</code> reference is returned.
167:             */
168:            public static Dialog getDialog(String title, boolean ce,
169:                    boolean cc, int index) {
170:                return (getDialog(new DialogByTitleChooser(title, ce, cc),
171:                        index));
172:            }
173:
174:            /**
175:             * Searches for a dialog.
176:             * Search among the currently showing dialogs for the first that is both
177:             * owned by the <code>java.awt.Window</code> <code>owner</code> and that
178:             * meets the search criteria applied by the <code>ComponentChooser</code>
179:             * parameter.
180:             * @param owner The owner window of the dialogs to be searched.
181:             * @param cc A component chooser used to define and apply the search criteria.
182:             * @return a reference to the first dialog that is showing, has a proper
183:             * owner window, and that meets the search criteria.  If no such dialog
184:             * can be found, a <code>null</code> reference is returned.
185:             */
186:            public static Dialog getDialog(Window owner, ComponentChooser cc) {
187:                return ((Dialog) WindowWaiter.getWindow(owner,
188:                        new DialogSubChooser(cc)));
189:            }
190:
191:            /**
192:             * Searches for a dialog.
193:             * The search proceeds among the currently showing dialogs 
194:             * for the <code>index+1</code>'th dialog that is both owned by the
195:             * <code>java.awt.Window</code> <code>owner</code> and that meets the
196:             * criteria defined and applied by the <code>ComponentChooser</code> parameter.
197:             * @param owner The owner window of all the dialogs to be searched.
198:             * @param cc A component chooser used to define and apply the search criteria.
199:             * @param index Ordinal index between appropriate dialogs
200:             * @return a reference to the <code>index+1</code>'th dialog that is showing,
201:             * has the proper window ownership, and that meets the search criteria.
202:             * If there are fewer than <code>index+1</code> dialogs, a <code>null</code>
203:             * reference is returned.
204:             */
205:            public static Dialog getDialog(Window owner, ComponentChooser cc,
206:                    int index) {
207:                return ((Dialog) WindowWaiter.getWindow(owner,
208:                        new DialogSubChooser(cc), index));
209:            }
210:
211:            /**
212:             * Searches for a dialog by title.
213:             * The search proceeds among the currently showing dialogs that are owned
214:             * by the <code>java.awt.Window</code> <code>owner</code> for the first with
215:             * a suitable title.
216:             * @param owner A window - owner of a dialods to be checked.
217:             * @param title Dialog title or subtitle.
218:             * @param ce If <code>true</code> and the search is case sensitive, then a
219:             * match occurs when the <code>title</code> argument is a substring of a
220:             * dialog title.  If <code>false</code> and the search is case sensitive,
221:             * then the <code>title</code> argument and the dialog title must be the same.
222:             * If <code>true</code> and the search is case insensitive, then a match occurs
223:             * when the <code>title</code> argument is a substring of the dialog title after
224:             * changing both to upper case.  If <code>false</code> and the search is case
225:             * insensitive, then a match occurs when the <code>title</code> argument is a
226:             * substring of the dialog title after changing both to upper case.
227:             * @param cc If <code>true</code> the search is case sensitive; otherwise, the
228:             * search is case insensitive. 
229:             * @return a reference to the first dialog that is showing, has the proper
230:             * window ownership, and a suitable title.  If no such dialog can be found,
231:             * a <code>null</code> reference is returned.
232:             */
233:            public static Dialog getDialog(Window owner, String title,
234:                    boolean ce, boolean cc) {
235:                return ((Dialog) WindowWaiter.getWindow(owner,
236:                        new DialogByTitleChooser(title, ce, cc)));
237:            }
238:
239:            /**
240:             * Searches for a dialog by title.
241:             * The search is for the <code>index+1</code>'th dialog among the currently
242:             * showing dialogs that are owned by the <code>java.awt.Window</code>
243:             * <code>owner</code> and that have a suitable title.
244:             * 
245:             * @param	owner ?title? Dialog title or subtitle.
246:             * @param	title ?ce? If <code>true</code> and the search is case sensitive, then a
247:             * match occurs when the <code>title</code> argument is a substring of a
248:             * dialog title.  If <code>false</code> and the search is case sensitive,
249:             * then the <code>title</code> argument and the dialog title must be the same.
250:             * If <code>true</code> and the search is case insensitive, then a match occurs
251:             * when the <code>title</code> argument is a substring of the dialog title after
252:             * changing both to upper case.  If <code>false</code> and the search is case
253:             * insensitive, then a match occurs when the <code>title</code> argument is a
254:             * substring of the dialog title after changing both to upper case.
255:             * @param	ce ?cc? If <code>true</code> the search is case sensitive; otherwise, the
256:             * search is case insensitive.
257:             * @param	cc ?index? The ordinal index of the dialog in the set of currently displayed
258:             * dialogs with the proper window ownership and a suitable title.  The
259:             * first index is 0.
260:             * @param	index Ordinal index between appropriate dialogs
261:             * @return	a reference to the <code>index+1</code>'th dialog that is showing, has
262:             * the proper window ownership, and a suitable title.  If there are fewer than
263:             * <code>index+1</code> dialogs, a <code>null</code> reference is returned.
264:             */
265:            public static Dialog getDialog(Window owner, String title,
266:                    boolean ce, boolean cc, int index) {
267:                return (getDialog(owner,
268:                        new DialogByTitleChooser(title, ce, cc), index));
269:            }
270:
271:            static {
272:                Timeouts.initDefault("DialogWaiter.WaitDialogTimeout",
273:                        WAIT_TIME);
274:                Timeouts.initDefault("DialogWaiter.AfterDialogTimeout",
275:                        AFTER_WAIT_TIME);
276:            }
277:
278:            /**
279:             * Defines current timeouts.
280:             * 
281:             * @param	timeouts ?t? A collection of timeout assignments.
282:             * @see	org.netbeans.jemmy.Timeouts
283:             * @see	org.netbeans.jemmy.Timeoutable
284:             * @see #getTimeouts
285:             */
286:            public void setTimeouts(Timeouts timeouts) {
287:                this .timeouts = timeouts;
288:                Timeouts times = timeouts.cloneThis();
289:                times.setTimeout("WindowWaiter.WaitWindowTimeout", timeouts
290:                        .getTimeout("DialogWaiter.WaitDialogTimeout"));
291:                times.setTimeout("WindowWaiter.AfterWindowTimeout", timeouts
292:                        .getTimeout("DialogWaiter.AfterDialogTimeout"));
293:                super .setTimeouts(times);
294:            }
295:
296:            /**
297:             * Return current timeouts.
298:             * @return the collection of current timeout assignments.
299:             * @see org.netbeans.jemmy.Timeouts
300:             * @see org.netbeans.jemmy.Timeoutable
301:             * @see #setTimeouts
302:             */
303:            public Timeouts getTimeouts() {
304:                return (timeouts);
305:            }
306:
307:            /**
308:             * Defines print output streams or writers.
309:             * 
310:             * @param	output ?out? Identify the streams or writers used for print output.
311:             * @see	org.netbeans.jemmy.TestOut
312:             * @see	org.netbeans.jemmy.Outputable
313:             * @see #getOutput
314:             */
315:            public void setOutput(TestOut output) {
316:                this .output = output;
317:                super .setOutput(output);
318:            }
319:
320:            /**
321:             * Returns print output streams or writers.
322:             * @return an object that contains references to objects for
323:             * printing to output and err streams.
324:             * @see org.netbeans.jemmy.TestOut
325:             * @see org.netbeans.jemmy.Outputable
326:             * @see #setOutput
327:             */
328:            public TestOut getOutput() {
329:                return (output);
330:            }
331:
332:            /**
333:             * Waits for a dialog to show.
334:             * Wait for the <code>index+1</code>'th dialog that meets the criteria
335:             * defined and applied by the <code>ComonentChooser</code> parameter to
336:             * show up.
337:             * 
338:             * @param	ch A component chooser used to define and apply the search criteria.
339:             * @param	index The ordinal index of the dialog in the set of currently displayed
340:             * dialogs.  The first index is 0.
341:             * @return	a reference to the <code>index+1</code>'th dialog that shows
342:             * and that meets the search criteria.  If fewer than
343:             * <code>index+1</code> dialogs show up in the allotted time period then
344:             * a <code>null</code> reference is returned.
345:             * @throws	TimeoutExpiredException
346:             * @see	org.netbeans.jemmy.WindowWaiter#actionProduced(Object)
347:             * @exception	InterruptedException
348:             */
349:            public Dialog waitDialog(ComponentChooser ch, int index)
350:                    throws InterruptedException {
351:                setTimeouts(timeouts);
352:                return ((Dialog) waitWindow(new DialogSubChooser(ch), index));
353:            }
354:
355:            /**
356:             * Waits for a dialog to show.
357:             * Wait for a dialog that meets the search criteria applied by the
358:             * <code>ComponentChooser</code> parameter to show up.
359:             * 
360:             * @param	ch A component chooser used to define and apply the search criteria.
361:             * @return	a reference to the first dialog that shows and that
362:             * meets the search criteria.  If no such dialog can be found within the
363:             * time period allotted, a <code>null</code> reference is returned.
364:             * @throws	TimeoutExpiredException
365:             * @see	org.netbeans.jemmy.WindowWaiter#actionProduced(Object)
366:             * @exception	InterruptedException
367:             */
368:            public Dialog waitDialog(ComponentChooser ch)
369:                    throws InterruptedException {
370:                return (waitDialog(ch, 0));
371:            }
372:
373:            /**
374:             * Waits for a dialog to show.
375:             * Wait for the <code>index+1</code>'th dialog to show with a suitable title.
376:             * 
377:             * @param	title Dialog title or subtitle.
378:             * @param	compareExactly If <code>true</code> and the search is case sensitive, then a
379:             * match occurs when the <code>title</code> argument is a substring of a
380:             * dialog title.  If <code>false</code> and the search is case sensitive,
381:             * then the <code>title</code> argument and the dialog title must be the same.
382:             * If <code>true</code> and the search is case insensitive, then a match occurs
383:             * when the <code>title</code> argument is a substring of the dialog title after
384:             * changing both to upper case.  If <code>false</code> and the search is case
385:             * insensitive, then a match occurs when the <code>title</code> argument is a
386:             * substring of the dialog title after changing both to upper case.
387:             * @param	compareCaseSensitive If <code>true</code> the search is case sensitive;
388:             * otherwise, the search is case insensitive.
389:             * @param	index The ordinal index of the dialog in the set of currently displayed
390:             * dialogs with the proper window ownership and a suitable title.  The
391:             * first index is 0.
392:             * @return	a reference to the <code>index+1</code>'th dialog to show and that has a
393:             * suitable title.  If no such dialog can be found within the time period
394:             * allotted, a <code>null</code> reference is returned.
395:             * @throws	TimeoutExpiredException
396:             * @see	org.netbeans.jemmy.WindowWaiter#actionProduced(Object)
397:             * @exception	InterruptedException
398:             */
399:            public Dialog waitDialog(String title, boolean compareExactly,
400:                    boolean compareCaseSensitive, int index)
401:                    throws InterruptedException {
402:                return (waitDialog(new DialogByTitleChooser(title,
403:                        compareExactly, compareCaseSensitive), index));
404:            }
405:
406:            /**
407:             * Waits for a dialog to show.
408:             * Wait for the first dialog to show with a suitable title.
409:             * 
410:             * @param	title Dialog title or subtitle.
411:             * @param	compareExactly If <code>true</code> and the search is case sensitive, then a
412:             * match occurs when the <code>title</code> argument is a substring of a
413:             * dialog title.  If <code>false</code> and the search is case sensitive,
414:             * then the <code>title</code> argument and the dialog title must be the same.
415:             * If <code>true</code> and the search is case insensitive, then a match occurs
416:             * when the <code>title</code> argument is a substring of the dialog title after
417:             * changing both to upper case.  If <code>false</code> and the search is case
418:             * insensitive, then a match occurs when the <code>title</code> argument is a
419:             * substring of the dialog title after changing both to upper case.
420:             * @param	compareCaseSensitive If <code>true</code> the search is case sensitive;
421:             * otherwise, the search is case insensitive.
422:             * @return	a reference to the first dialog to show and that has a
423:             * suitable title.  If no such dialog can be found within the time period
424:             * allotted, a <code>null</code> reference is returned.
425:             * @throws	TimeoutExpiredException
426:             * @see	org.netbeans.jemmy.WindowWaiter#actionProduced(Object)
427:             * @exception	InterruptedException
428:             */
429:            public Dialog waitDialog(String title, boolean compareExactly,
430:                    boolean compareCaseSensitive) throws InterruptedException {
431:                return (waitDialog(title, compareExactly, compareCaseSensitive,
432:                        0));
433:            }
434:
435:            /**
436:             * Waits for a dialog to show.
437:             * Wait for the <code>index+1</code>'th dialog to show that is both owned by the
438:             * <code>java.awt.Window</code> <code>owner</code> and that meets the
439:             * criteria defined and applied by the <code>ComponentChooser</code> parameter.
440:             * 
441:             * @param	owner The owner window of all the dialogs to be searched.
442:             * @param	ch A component chooser used to define and apply the search criteria.
443:             * @param	index The ordinal index of the dialog in the set of currently displayed
444:             * dialogs with the proper window ownership and a suitable title.  The first
445:             * index is 0.
446:             * @return	a reference to the <code>index+1</code>'th dialog to show that
447:             * has the proper window ownership, and that meets the search criteria.
448:             * If there are fewer than <code>index+1</code> dialogs, a <code>null</code>
449:             * reference is returned.
450:             * @throws	TimeoutExpiredException
451:             * @see	org.netbeans.jemmy.WindowWaiter#actionProduced(Object)
452:             * @exception	InterruptedException
453:             */
454:            public Dialog waitDialog(Window owner, ComponentChooser ch,
455:                    int index) throws InterruptedException {
456:                setTimeouts(timeouts);
457:                return ((Dialog) waitWindow(owner, new DialogSubChooser(ch),
458:                        index));
459:            }
460:
461:            /**
462:             * Waits for a dialog to show.
463:             * Wait for the first dialog to show that is both owned by the
464:             * <code>java.awt.Window</code> <code>owner</code> and that meets the
465:             * criteria defined and applied by the <code>ComponentChooser</code> parameter.
466:             * 
467:             * @param	owner The owner window of all the dialogs to be searched.
468:             * @param	ch A component chooser used to define and apply the search criteria.
469:             * @return	a reference to the first dialog to show that
470:             * has the proper window ownership, and that meets the search criteria.
471:             * If there is no such dialog, a <code>null</code> reference is returned.
472:             * @throws	TimeoutExpiredException
473:             * @see	org.netbeans.jemmy.WindowWaiter#actionProduced(Object)
474:             * @exception	InterruptedException
475:             */
476:            public Dialog waitDialog(Window owner, ComponentChooser ch)
477:                    throws InterruptedException {
478:                return (waitDialog(owner, ch, 0));
479:            }
480:
481:            /**
482:             * Waits for a dialog to show.
483:             * Wait for the <code>index+1</code>'th dialog to show with the proper owner
484:             * and a suitable title.
485:             * 
486:             * @param	owner The owner window of all the dialogs to be searched.
487:             * @param	title Dialog title or subtitle.
488:             * @param	compareExactly If <code>true</code> and the search is case sensitive, then a
489:             * match occurs when the <code>title</code> argument is a substring of a
490:             * dialog title.  If <code>false</code> and the search is case sensitive,
491:             * then the <code>title</code> argument and the dialog title must be the same.
492:             * If <code>true</code> and the search is case insensitive, then a match occurs
493:             * when the <code>title</code> argument is a substring of the dialog title after
494:             * changing both to upper case.  If <code>false</code> and the search is case
495:             * insensitive, then a match occurs when the <code>title</code> argument is a
496:             * substring of the dialog title after changing both to upper case.
497:             * @param	compareCaseSensitive If <code>true</code> the search is case sensitive;
498:             * otherwise, the search is case insensitive.
499:             * @param index Ordinal index between appropriate dialogs
500:             * @return	a reference to the <code>index+1</code>'th dialog to show that has
501:             * both the proper owner window and a suitable title.  If no such dialog can be found
502:             * within the time period allotted, a <code>null</code> reference is returned.
503:             * @throws	TimeoutExpiredException
504:             * @see	org.netbeans.jemmy.WindowWaiter#actionProduced(Object)
505:             * @exception	InterruptedException
506:             */
507:            public Dialog waitDialog(Window owner, String title,
508:                    boolean compareExactly, boolean compareCaseSensitive,
509:                    int index) throws InterruptedException {
510:                return (waitDialog(owner, new DialogByTitleChooser(title,
511:                        compareExactly, compareCaseSensitive), index));
512:            }
513:
514:            /**
515:             * Waits for a dialog to show.
516:             * Wait for the first dialog to show with the proper owner and a suitable title.
517:             * 
518:             * @see	org.netbeans.jemmy.WindowWaiter#actionProduced(Object)
519:             * @param	owner The owner window of all the dialogs to be searched.
520:             * @param	title Dialog title or subtitle.
521:             * @param	compareExactly If <code>true</code> and the search is case sensitive, then a
522:             * match occurs when the <code>title</code> argument is a substring of a
523:             * dialog title.  If <code>false</code> and the search is case sensitive,
524:             * then the <code>title</code> argument and the dialog title must be the same.
525:             * If <code>true</code> and the search is case insensitive, then a match occurs
526:             * when the <code>title</code> argument is a substring of the dialog title after
527:             * changing both to upper case.  If <code>false</code> and the search is case
528:             * insensitive, then a match occurs when the <code>title</code> argument is a
529:             * substring of the dialog title after changing both to upper case.
530:             * @param	compareCaseSensitive If <code>true</code> the search is case sensitive;
531:             * otherwise, the search is case insensitive.
532:             * @return	a reference to the first dialog to show and that has both the proper
533:             * owner and a suitable title.  If no such dialog can be found within the time period
534:             * allotted, a <code>null</code> reference is returned.
535:             * @throws	TimeoutExpiredException
536:             * @exception	InterruptedException
537:             */
538:            public Dialog waitDialog(Window owner, String title,
539:                    boolean compareExactly, boolean compareCaseSensitive)
540:                    throws InterruptedException {
541:                return (waitDialog(owner, title, compareExactly,
542:                        compareCaseSensitive, 0));
543:            }
544:
545:            /**
546:             * @see org.netbeans.jemmy.Waiter#getWaitingStartedMessage()
547:             */
548:            protected String getWaitingStartedMessage() {
549:                return ("Start to wait dialog \""
550:                        + getComponentChooser().getDescription() + "\" opened");
551:            }
552:
553:            /**
554:             * Overrides WindowWaiter.getTimeoutExpiredMessage.
555:             * Returns the timeout expired message value.
556:             * @see	org.netbeans.jemmy.Waiter#getTimeoutExpiredMessage(long)
557:             * @param	spendedTime Time spent for waiting
558:             * @return A message string.
559:             */
560:            protected String getTimeoutExpiredMessage(long spendedTime) {
561:                return ("Dialog \"" + getComponentChooser().getDescription()
562:                        + "\" has not been opened in "
563:                        + (new Long(spendedTime)).toString() + " milliseconds");
564:            }
565:
566:            /**
567:             * Overrides WindowWaiter.getActionProducedMessage.
568:             * Returns the action produced message value.
569:             * @see	org.netbeans.jemmy.Waiter#getActionProducedMessage(long, Object)
570:             * @param	spendedTime Time spent for waiting
571:             * @param	result A result of the action
572:             * @return A message string.
573:             */
574:            protected String getActionProducedMessage(long spendedTime,
575:                    final Object result) {
576:                String resultToString;
577:                if (result instanceof  Component) {
578:                    // run toString in dispatch thread
579:                    resultToString = (String) new QueueTool()
580:                            .invokeSmoothly(new QueueTool.QueueAction(
581:                                    "result.toString()") {
582:                                public Object launch() {
583:                                    return result.toString();
584:                                }
585:                            });
586:                } else {
587:                    resultToString = result.toString();
588:                }
589:                return ("Dialog \"" + getComponentChooser().getDescription()
590:                        + "\" has been opened in "
591:                        + (new Long(spendedTime)).toString() + " milliseconds"
592:                        + "\n    " + resultToString);
593:            }
594:
595:            /**
596:             * @see org.netbeans.jemmy.Waiter#getGoldenWaitingStartedMessage()
597:             */
598:            protected String getGoldenWaitingStartedMessage() {
599:                return ("Start to wait dialog \""
600:                        + getComponentChooser().getDescription() + "\" opened");
601:            }
602:
603:            /**
604:             * @see org.netbeans.jemmy.Waiter#getGoldenTimeoutExpiredMessage()
605:             */
606:            protected String getGoldenTimeoutExpiredMessage() {
607:                return ("Dialog \"" + getComponentChooser().getDescription() + "\" has not been opened");
608:            }
609:
610:            /**
611:             * @see org.netbeans.jemmy.Waiter#getGoldenActionProducedMessage()
612:             */
613:            protected String getGoldenActionProducedMessage() {
614:                return ("Dialog \"" + getComponentChooser().getDescription() + "\" has been opened");
615:            }
616:
617:            private Dialog waitDialog() throws InterruptedException {
618:                return ((Dialog) waitAction(""));
619:            }
620:
621:            private static class DialogSubChooser implements  ComponentChooser {
622:                private ComponentChooser chooser;
623:
624:                public DialogSubChooser(ComponentChooser c) {
625:                    super ();
626:                    chooser = c;
627:                }
628:
629:                public boolean checkComponent(Component comp) {
630:                    if (comp instanceof  Dialog) {
631:                        return (comp.isShowing() && comp.isVisible() && chooser
632:                                .checkComponent(comp));
633:                    } else {
634:                        return (false);
635:                    }
636:                }
637:
638:                public String getDescription() {
639:                    return (chooser.getDescription());
640:                }
641:            }
642:
643:            private static class DialogByTitleChooser implements 
644:                    ComponentChooser {
645:                String title;
646:                boolean compareExactly;
647:                boolean compareCaseSensitive;
648:
649:                public DialogByTitleChooser(String t, boolean ce, boolean cc) {
650:                    super ();
651:                    title = t;
652:                    compareExactly = ce;
653:                    compareCaseSensitive = cc;
654:                }
655:
656:                public boolean checkComponent(Component comp) {
657:                    if (comp instanceof  Dialog) {
658:                        if (((Dialog) comp).isShowing() && comp.isVisible()
659:                                && ((Dialog) comp).getTitle() != null) {
660:                            String titleToComp = ((Dialog) comp).getTitle();
661:                            String contextToComp = title;
662:                            if (compareCaseSensitive) {
663:                                titleToComp = titleToComp.toUpperCase();
664:                                contextToComp = contextToComp.toUpperCase();
665:                            }
666:                            if (compareExactly) {
667:                                return (titleToComp.equals(contextToComp));
668:                            } else {
669:                                return (titleToComp.indexOf(contextToComp) != -1);
670:                            }
671:                        }
672:                    }
673:                    return (false);
674:                }
675:
676:                public String getDescription() {
677:                    return (title);
678:                }
679:            }
680:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.