1 19 20 package org.netbeans.test.xml.schema.core.lib.util; 21 22 import java.awt.Component ; 23 import java.awt.Container ; 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 39 public class Helpers { 40 41 public static final String 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 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 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 e) { 84 85 } 86 } 87 88 public static void recurseComponent(int level, Component 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 103 if (component instanceof Container ) { 104 Component [] comps = ((Container )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 strComponentClass) { 112 return new JComponentOperator(opContainer, 113 new ComponentChooser() { 114 public boolean checkComponent(java.awt.Component comp) { 115 return comp.getClass().toString().equals("class " + strComponentClass); 116 } 117 118 public String 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 strComponentClass, final int index) { 133 return getComponentOperator(opContainer, strComponentClass, index, 2000); 134 } 135 136 public static JComponentOperator getComponentOperator(ContainerOperator opContainer, final String 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 comp) { 148 return comp.getClass().toString().equals("class " + strComponentClass); 149 } 150 151 public String 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 str) { 164 JemmyProperties.getCurrentOutput().printLine(str); 165 } 166 167 public static String getUnqualifiedName(String qualifiedName) { 168 return qualifiedName.substring(qualifiedName.lastIndexOf(":")+1); 169 } 170 171 public static String getFullTestName(String strName) { 172 return strName.replaceAll(" |:|,|#", "_"); 173 } 174 } 175 | Popular Tags |