KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > xml > schema > core > lib > util > Helpers


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.test.xml.schema.core.lib.util;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Container JavaDoc;
24 import org.netbeans.jellytools.TopComponentOperator;
25 import org.netbeans.jellytools.nodes.Node;
26 import org.netbeans.jemmy.ComponentChooser;
27 import org.netbeans.jemmy.EventTool;
28 import org.netbeans.jemmy.JemmyProperties;
29 import org.netbeans.jemmy.TimeoutExpiredException;
30 import org.netbeans.jemmy.Timeouts;
31 import org.netbeans.jemmy.operators.ContainerOperator;
32 import org.netbeans.jemmy.operators.JComponentOperator;
33 import org.netbeans.test.xml.schema.core.lib.SchemaMultiView;
34
35 /**
36  *
37  * @author ca@netbeans.org
38  */

39 public class Helpers {
40     
41     public static final String JavaDoc WAIT_COMPONENT_TIMEOUT = "ComponentOperator.WaitComponentTimeout";
42     public static final int NO_EVENT_TIMEOUT = 500;
43     public static EventTool et = new EventTool();
44     
45     public static void closeTopComponentIfOpened(String JavaDoc strName) {
46         Timeouts times = JemmyProperties.getCurrentTimeouts();
47         long to = times.setTimeout(WAIT_COMPONENT_TIMEOUT, 1000);
48         
49         try {
50             new TopComponentOperator("Navigator").close();
51             new EventTool().waitNoEvent(NO_EVENT_TIMEOUT);
52         } catch (TimeoutExpiredException e) {
53         } finally {
54             times.setTimeout(WAIT_COMPONENT_TIMEOUT, to);
55         }
56         
57     }
58     
59     public static void recurseColumns(int column, Node node, SchemaMultiView opView, final int maxColumnIndex) {
60         node.select();
61         
62         System.out.println("path: " + node.getPath());
63 /*
64         if (column < maxColumnIndex) {
65             JListOperator opList = opView.getColumnListOperator(column + 1);
66             Node nextColumnNode = opTree.getRootNode();
67             if (nextColumnNode != null) {
68                 recurseColumns(column + 1, nextColumnNode, opView, maxColumnIndex);
69             }
70         }
71  
72         for (int i = 0; i < node.getChildren().length; i++) {
73             Node childNode = new Node(node, i);
74             recurseColumns(column, childNode, opView, maxColumnIndex);
75         }
76  */

77     }
78     
79     public static void pause(int milliseconds) {
80         System.out.println("Paused for " + milliseconds);
81         try {
82             Thread.currentThread().sleep(milliseconds);
83         } catch (Exception JavaDoc e) {
84             
85         }
86     }
87     
88     public static void recurseComponent(int level, Component JavaDoc component) {
89         
90         JemmyProperties.getCurrentOutput().print("*");
91         System.out.print("*");
92         
93         for (int j = 0; j < level; j++) {
94             JemmyProperties.getCurrentOutput().print("|");
95             System.out.print("|");
96         }
97         
98         System.out.println("Name: " + component.getName() + ", Class: " + component.getClass());
99         JemmyProperties.getCurrentOutput().printLine("Name: " + component.getName() + ", Class: " + component.getClass());
100         
101 // System.out.println("Component: " + component);
102

103         if (component instanceof Container JavaDoc) {
104             Component JavaDoc[] comps = ((Container JavaDoc)component).getComponents();
105             for (int i = 0; i < comps.length; i++) {
106                 recurseComponent(level+1, comps[i]);
107             }
108         }
109     }
110     
111     public static JComponentOperator getComponent(ContainerOperator opContainer, final String JavaDoc strComponentClass) {
112         return new JComponentOperator(opContainer,
113                 new ComponentChooser() {
114             public boolean checkComponent(java.awt.Component JavaDoc comp) {
115                 return comp.getClass().toString().equals("class " + strComponentClass);
116             }
117             
118             public String JavaDoc getDescription() {
119                 return strComponentClass;
120             }
121         });
122     }
123     
124     public static void waitNoEvent() {
125         waitNoEvent(NO_EVENT_TIMEOUT);
126     }
127     
128     public static void waitNoEvent(int milliseconds) {
129         et.waitNoEvent(milliseconds);
130     }
131     
132     public static JComponentOperator getComponentOperator(ContainerOperator opContainer, final String JavaDoc strComponentClass, final int index) {
133         return getComponentOperator(opContainer, strComponentClass, index, 2000);
134     }
135     
136     public static JComponentOperator getComponentOperator(ContainerOperator opContainer, final String JavaDoc strComponentClass, final int index, final int timeout) {
137         
138         Timeouts times = JemmyProperties.getCurrentTimeouts();
139         long to = times.setTimeout(Helpers.WAIT_COMPONENT_TIMEOUT, timeout);
140         
141         JComponentOperator opJComponent = null;
142         
143         try {
144             opJComponent = new JComponentOperator(opContainer,
145                     new ComponentChooser() {
146                 
147                 public boolean checkComponent(java.awt.Component JavaDoc comp) {
148                     return comp.getClass().toString().equals("class " + strComponentClass);
149                 }
150                 
151                 public String JavaDoc getDescription() {
152                     return strComponentClass;
153                 }
154             }, index);
155         } catch (TimeoutExpiredException e) {
156         } finally {
157             times.setTimeout(Helpers.WAIT_COMPONENT_TIMEOUT, to);
158         }
159         
160         return opJComponent;
161     }
162     
163     public static void writeJemmyLog(String JavaDoc str) {
164         JemmyProperties.getCurrentOutput().printLine(str);
165     }
166     
167     public static String JavaDoc getUnqualifiedName(String JavaDoc qualifiedName) {
168         return qualifiedName.substring(qualifiedName.lastIndexOf(":")+1);
169     }
170     
171     public static String JavaDoc getFullTestName(String JavaDoc strName) {
172         return strName.replaceAll(" |:|,|#", "_");
173     }
174 }
175
Popular Tags