1 29 30 package nextapp.echo2.testapp.interactive; 31 32 import nextapp.echo2.app.ApplicationInstance; 33 import nextapp.echo2.app.TaskQueueHandle; 34 import nextapp.echo2.app.Window; 35 import nextapp.echo2.webcontainer.ContainerContext; 36 import nextapp.echo2.webrender.ClientConfiguration; 37 38 52 public class InteractiveApp extends ApplicationInstance { 53 54 private static final String [] GHOST_SCRIPT_1 = new String [] { 55 "EnterTestApplication", 56 "StartTest:ButtonTest", 57 "StartTest:SplitPaneNestedTest", 58 "StartTest:ListBoxTest", 59 "StartTest:TextComponentTest", 60 "StartTest:StyleSheetTest", 61 "StartTest:ContainerContextTest", 62 "StartTest:GridTest", 63 "StartTest:HierarchyTest", 64 "ExitTestApplication" 65 }; 66 67 73 public static final boolean LIVE_DEMO_SERVER; 74 static { 75 boolean liveDemoServer; 76 try { 77 if ("true".equals(System.getProperties().getProperty("nextapp.echo2.demoserver"))) { 78 liveDemoServer = true; 79 } else { 80 liveDemoServer = false; 81 } 82 } catch (SecurityException ex) { 83 liveDemoServer = false; 84 } 85 LIVE_DEMO_SERVER = liveDemoServer; 86 } 87 88 95 public static InteractiveApp getApp() { 96 return (InteractiveApp) ApplicationInstance.getActive(); 97 } 98 99 private TaskQueueHandle ghostTaskQueue; 100 private Window mainWindow; 101 private ConsoleWindowPane console; 102 103 110 public void consoleWrite(String message) { 111 if (console == null) { 112 console = new ConsoleWindowPane(); 113 getDefaultWindow().getContent().add(console); 114 } else if (console.getParent() == null) { 115 getDefaultWindow().getContent().add(console); 116 } 117 console.writeMessage(message); 118 } 119 120 124 public void displayTestPane() { 125 mainWindow.setContent(new TestPane()); 126 } 127 128 132 public void displayWelcomePane() { 133 mainWindow.setContent(new WelcomePane()); 134 } 135 136 private String getRequestParameter(String parameterName) { 137 ContainerContext cc = (ContainerContext) getContextProperty(ContainerContext.CONTEXT_PROPERTY_NAME); 138 Object parameterValue = cc.getInitialRequestParameterMap().get(parameterName); 139 if (parameterValue instanceof String ) { 140 return (String ) parameterValue; 141 } else if (parameterValue instanceof String []) { 142 return ((String []) parameterValue).length == 0 ? null : ((String []) parameterValue)[0]; 143 } else { 144 return parameterValue == null ? null : parameterValue.toString(); 145 } 146 } 147 148 151 public Window init() { 152 setStyleSheet(Styles.DEFAULT_STYLE_SHEET); 153 mainWindow = new Window(); 154 mainWindow.setTitle("NextApp Echo2 Test Application"); 155 mainWindow.setContent(new WelcomePane()); 156 157 ContainerContext cc = (ContainerContext) getContextProperty(ContainerContext.CONTEXT_PROPERTY_NAME); 158 if (!LIVE_DEMO_SERVER) { 159 if (cc.getInitialRequestParameterMap().containsKey("ghost")) { 160 GhostTask ghostTask = new GhostTask(); 161 162 if ("1".equals(getRequestParameter("script"))) { 163 ghostTask.setScript(GHOST_SCRIPT_1); 164 } 165 if (cc.getInitialRequestParameterMap().containsKey("clicks")) { 166 ghostTask.setClicksPerIteration(Integer.parseInt(getRequestParameter("clicks"))); 167 } 168 if (cc.getInitialRequestParameterMap().containsKey("iterations")) { 169 ghostTask.setTotalIterations(Integer.parseInt(getRequestParameter("iterations"))); 170 } 171 startGhostTask(ghostTask, 0); 172 } 173 } 174 175 ClientConfiguration clientConfiguration = new ClientConfiguration(); 176 clientConfiguration.setProperty(ClientConfiguration.PROPERTY_SERVER_ERROR_MESSAGE, 177 "KA-BOOM! (test non-default server error message)"); 178 cc.setClientConfiguration(clientConfiguration); 179 180 return mainWindow; 181 } 182 183 190 public void setGhostIterationWindowTitle(int iteration) { 191 if (iteration < 0) { 192 mainWindow.setTitle("NextApp Echo2 Test Application"); 193 } else { 194 mainWindow.setTitle("Iteration #" + iteration); 195 } 196 } 197 198 205 public void startGhostTask(GhostTask ghostTask, int interval) { 206 if (ghostTaskQueue != null) { 207 return; 208 } 209 ghostTaskQueue = createTaskQueue(); 210 ContainerContext containerContext = 211 (ContainerContext) getContextProperty(ContainerContext.CONTEXT_PROPERTY_NAME); 212 containerContext.setTaskQueueCallbackInterval(ghostTaskQueue, interval); 213 ghostTask.startTask(this, ghostTaskQueue); 214 } 215 216 219 public void stopGhostTest() { 220 removeTaskQueue(ghostTaskQueue); 221 ghostTaskQueue = null; 222 } 223 } 224 | Popular Tags |