1 19 20 package org.netbeans.test.j2ee.lib; 21 22 import java.lang.reflect.Method ; 23 import javax.swing.JDialog ; 24 import org.netbeans.jemmy.JemmyException; 25 import org.netbeans.jemmy.Waitable; 26 import org.netbeans.jemmy.Waiter; 27 import org.netbeans.jemmy.operators.Operator; 28 29 34 public class ProgressOperator { 35 36 38 public static void waitStarted(final String name, long timeout) { 39 try { 40 Waiter waiter = new Waiter(new Waitable() { 41 public Object actionProduced(Object anObject) { 42 return processInProgress(name) ? Boolean.TRUE : null; 43 } 44 public String getDescription() { 45 return("Wait process "+name+" is started."); 46 } 47 }); 48 waiter.getTimeouts().setTimeout("Waiter.WaitingTime", timeout); 49 waiter.waitAction(null); 50 } catch (InterruptedException e) { 51 throw new JemmyException("Interrupted.", e); 52 } 53 54 } 55 56 58 public static void waitFinished(final String name, long timeout) { 59 try { 60 Waiter waiter = new Waiter(new Waitable() { 61 public Object actionProduced(Object anObject) { 62 return processInProgress(name) ? null : Boolean.TRUE; 63 } 64 public String getDescription() { 65 return("Wait process "+name+" is finished."); 66 } 67 }); 68 waiter.getTimeouts().setTimeout("Waiter.WaitingTime", timeout); 69 waiter.waitAction(null); 70 } catch (InterruptedException e) { 71 throw new JemmyException("Interrupted.", e); 72 } 73 74 } 75 76 78 public static void waitFinished(long timeout) { 79 waitFinished("", timeout); } 81 82 private static boolean processInProgress(String name) { 83 try { 84 Class clazz = Class.forName("org.netbeans.progress.module.Controller"); 85 Method getDefaultMethod = clazz.getDeclaredMethod("getDefault", (Class [])null); 86 getDefaultMethod.setAccessible(true); 87 Object controllerInstance = getDefaultMethod.invoke(null, (Object [])null); 88 89 Method getModelMethod = clazz.getDeclaredMethod("getModel", (Class [])null); 90 getModelMethod.setAccessible(true); 91 Object taskModelInstance = getModelMethod.invoke(controllerInstance, (Object [])null); 92 93 97 Method getHandlesMethod = taskModelInstance.getClass().getDeclaredMethod("getHandles", (Class [])null); 98 Object [] handles = (Object [])getHandlesMethod.invoke(taskModelInstance, (Object [])null); 99 100 for(int i=0;i<handles.length;i++) { 101 Method getDisplayNameMethod = handles[i].getClass().getDeclaredMethod("getDisplayName", (Class [])null); 102 String displayName = (String )getDisplayNameMethod.invoke(handles[i], (Object [])null); 103 if(Operator.getDefaultStringComparator().equals(displayName, name)) { 105 return true; 106 } 107 } 108 return false; 109 110 113 114 } catch (Exception e) { 115 throw new JemmyException("Reflection operation failed.", e); 116 } 117 } 118 } | Popular Tags |