KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gui > debuggercore > Utilities


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  * The Original Software is NetBeans.
15  * The Initial Developer of the Original Software is Sun Microsystems, Inc.
16  * Portions created by Sun Microsystems, Inc. are Copyright (C) 2003
17  * All Rights Reserved.
18  *
19  * Contributor(s): Sun Microsystems, Inc.
20  */

21
22 package gui.debuggercore;
23
24 import java.awt.Component JavaDoc;
25 import java.awt.event.KeyEvent JavaDoc;
26 import javax.swing.JComponent JavaDoc;
27 import javax.swing.JEditorPane JavaDoc;
28 import javax.swing.JScrollPane JavaDoc;
29 import javax.swing.KeyStroke JavaDoc;
30 import org.netbeans.jellytools.*;
31 import org.netbeans.jellytools.actions.Action;
32 import org.netbeans.jellytools.actions.DebugProjectAction;
33 import org.netbeans.jellytools.modules.debugger.actions.FinishDebuggerAction;
34 import org.netbeans.jellytools.modules.debugger.actions.NewBreakpointAction;
35 import org.netbeans.jellytools.modules.debugger.actions.ToggleBreakpointAction;
36 import org.netbeans.jellytools.nodes.Node;
37 import org.netbeans.jemmy.ComponentChooser;
38 import org.netbeans.jemmy.EventTool;
39 import org.netbeans.jemmy.JemmyException;
40 import org.netbeans.jemmy.JemmyProperties;
41 import org.netbeans.jemmy.TimeoutExpiredException;
42 import org.netbeans.jemmy.Waitable;
43 import org.netbeans.jemmy.Waiter;
44 import org.netbeans.jemmy.operators.ContainerOperator;
45 import org.netbeans.jemmy.operators.JPopupMenuOperator;
46 import org.netbeans.jemmy.operators.JTableOperator;
47 import org.openide.awt.StatusDisplayer;
48
49
50
51
52 public class Utilities {
53     
54     public static String JavaDoc windowMenu = Bundle.getStringTrimmed("org.netbeans.core.Bundle", "Menu/Window");
55     public static String JavaDoc runMenu = Bundle.getStringTrimmed("org.netbeans.modules.project.ui.Bundle", "Menu/RunProject");
56     public static String JavaDoc debugMenu = Bundle.getStringTrimmed("org.netbeans.modules.debugger.resources.Bundle", "Menu/Window/Debug");
57     public static String JavaDoc runFileMenu = Bundle.getString("org.netbeans.modules.java.project.Bundle", "LBL_RunFile_Action");
58     public static String JavaDoc debugToolbarLabel = Bundle.getString("org.netbeans.modules.debugger.jpda.ui.Bundle", "Toolbars/Debug");
59     
60     public static String JavaDoc toggleBreakpointItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_Toggle_breakpoint");
61     public static String JavaDoc newBreakpointItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_AddBreakpoint");
62     public static String JavaDoc newWatchItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_New_Watch");
63     public static String JavaDoc debugMainProjectItem = Bundle.getStringTrimmed("org.netbeans.modules.project.ui.actions.Bundle", "LBL_DebugMainProjectAction_Name");
64     public static String JavaDoc stepIntoItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_Step_into_action_name");
65     public static String JavaDoc stepOverItem = Bundle.getString("org.netbeans.modules.debugger.jpda.ui.Bundle", "CTL_Step_Over");
66     public static String JavaDoc stepOutItem = Bundle.getString("org.netbeans.modules.debugger.jpda.ui.Bundle", "CTL_Step_Out");
67     public static String JavaDoc stepOverExpresItem = Bundle.getString("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_Step_operation_action_name");
68     public static String JavaDoc runIntoMethodItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_Run_into_method_action_name");
69     public static String JavaDoc continueItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_Continue_action_name");
70     public static String JavaDoc pauseItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_Pause_action_name");
71     public static String JavaDoc finishSessionsItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_KillAction_name");
72     public static String JavaDoc runToCursorItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_Run_to_cursor_action_name");
73     public static String JavaDoc applyCodeChangesItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_Fix_action_name");
74     public static String JavaDoc evaluateExpressionItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.jpda.ui.actions.Bundle", "CTL_Evaluate");
75     
76     public static String JavaDoc localVarsItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_LocalVariablesAction");
77     public static String JavaDoc watchesItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_WatchesAction");
78     public static String JavaDoc callStackItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_CallStackAction");
79     public static String JavaDoc classesItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.jpda.ui.actions.Bundle", "CTL_ClassesAction");
80     public static String JavaDoc sourcesItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.jpda.ui.actions.Bundle", "CTL_SourcesViewAction");
81     public static String JavaDoc breakpointsItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_BreakpointsAction");
82     public static String JavaDoc sessionsItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_SessionsAction");
83     public static String JavaDoc threadsItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_ThreadsAction");
84     
85     public static String JavaDoc localVarsViewTitle = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.views.Bundle", "CTL_Variables_view");
86     public static String JavaDoc watchesViewTitle = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.views.Bundle", "CTL_Watches_view");
87     public static String JavaDoc callStackViewTitle = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.views.Bundle", "CTL_Call_stack_view");
88     public static String JavaDoc classesViewTitle = Bundle.getStringTrimmed("org.netbeans.modules.debugger.jpda.ui.views.Bundle", "CTL_Classes_view");
89     public static String JavaDoc sourcesViewTitle = Bundle.getStringTrimmed("org.netbeans.modules.debugger.jpda.ui.views.Bundle", "CTL_Sourcess_view");
90     public static String JavaDoc breakpointsViewTitle = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.views.Bundle", "CTL_Breakpoints_view");
91     public static String JavaDoc sessionsViewTitle = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.views.Bundle", "CTL_Sessions_view");
92     public static String JavaDoc threadsViewTitle = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.views.Bundle", "CTL_Threads_view");
93     
94     public static String JavaDoc customizeBreakpointTitle = Bundle.getString("org.netbeans.modules.debugger.jpda.ui.models.Bundle", "CTL_Breakpoint_Customizer_Title");
95     public static String JavaDoc newBreakpointTitle = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_Breakpoint_Title");
96     public static String JavaDoc newWatchTitle = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_WatchDialog_Title");
97     public static String JavaDoc debuggerConsoleTitle = Bundle.getString("org.netbeans.modules.debugger.jpda.ui.Bundle", "CTL_DebuggerConsole_Title");
98     
99     
100     public static String JavaDoc runningStatusBarText = Bundle.getStringTrimmed("org.netbeans.modules.debugger.jpda.ui.Bundle", "CTL_Debugger_running");
101     public static String JavaDoc stoppedStatusBarText = Bundle.getStringTrimmed("org.netbeans.modules.debugger.jpda.ui.Bundle", "CTL_Debugger_stopped");
102     public static String JavaDoc finishedStatusBarText = Bundle.getStringTrimmed("org.netbeans.modules.debugger.jpda.ui.Bundle", "CTL_Debugger_finished");
103     public static String JavaDoc buildCompleteStatusBarText = "Finished building";
104     public static String JavaDoc evaluatingPropertyText = Bundle.getString("org.netbeans.modules.viewmodel.Bundle", "EvaluatingProp");
105     
106     public static String JavaDoc openSourceAction = Bundle.getStringTrimmed("org.openide.actions.Bundle", "Open");
107     public static String JavaDoc setMainProjectAction = Bundle.getStringTrimmed("org.netbeans.modules.project.ui.actions.Bundle", "LBL_SetAsMainProjectAction_Name");
108     public static String JavaDoc projectPropertiesAction = Bundle.getStringTrimmed("org.netbeans.modules.project.ui.actions.Bundle", "LBL_CustomizeProjectAction_Popup_Name");
109     public static String JavaDoc projectPropertiesTitle = Bundle.getStringTrimmed("org.netbeans.modules.java.j2seproject.ui.Bundle", "LBL_Customizer_Title");
110     // public static String runningProjectTreeItem = Bundle.getStringTrimmed("org.netbeans.modules.java.j2seproject.ui.customizer.Bundle", "LBL_Config_Run");
111

112     public static String JavaDoc testProjectName = "debugTestProject";
113     
114     public static KeyStroke JavaDoc toggleBreakpointShortcut = KeyStroke.getKeyStroke(KeyEvent.VK_F8, KeyEvent.CTRL_MASK);
115     public static KeyStroke JavaDoc newBreakpointShortcut = KeyStroke.getKeyStroke(KeyEvent.VK_F8, KeyEvent.CTRL_MASK|KeyEvent.SHIFT_MASK);
116     public static KeyStroke JavaDoc newWatchShortcut = KeyStroke.getKeyStroke(KeyEvent.VK_F7, KeyEvent.CTRL_MASK|KeyEvent.SHIFT_MASK);
117     public static KeyStroke JavaDoc debugProjectShortcut = KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0);
118     public static KeyStroke JavaDoc debugFileShortcut = KeyStroke.getKeyStroke(KeyEvent.VK_F5, KeyEvent.CTRL_MASK|KeyEvent.SHIFT_MASK);
119     public static KeyStroke JavaDoc runToCursorShortcut = KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0);
120     public static KeyStroke JavaDoc stepIntoShortcut = KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0);
121     public static KeyStroke JavaDoc stepOutShortcut = KeyStroke.getKeyStroke(KeyEvent.VK_F7, KeyEvent.CTRL_MASK);
122     public static KeyStroke JavaDoc stepOverShortcut = KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0);
123     public static KeyStroke JavaDoc continueShortcut = KeyStroke.getKeyStroke(KeyEvent.VK_F5, KeyEvent.CTRL_MASK);
124     public static KeyStroke JavaDoc killSessionShortcut = KeyStroke.getKeyStroke(KeyEvent.VK_F5, KeyEvent.SHIFT_MASK);
125     public static KeyStroke JavaDoc buildProjectShortcut = KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0);
126     public static KeyStroke JavaDoc openBreakpointsShortcut = KeyStroke.getKeyStroke(KeyEvent.VK_5, KeyEvent.ALT_MASK|KeyEvent.SHIFT_MASK);
127     
128     
129     
130     public Utilities() {}
131     
132     public static boolean verifyMainMenu(String JavaDoc actionPath, boolean expected) {
133         if (expected == MainWindowOperator.getDefault().menuBar().showMenuItem(actionPath).isEnabled())
134             return MainWindowOperator.getDefault().menuBar().showMenuItem(actionPath).isEnabled();
135         else {
136             for (int i = 0; i < 10; i++) {
137                 if(MainWindowOperator.getDefault().menuBar().showMenuItem(actionPath).isEnabled() == expected) {
138                     MainWindowOperator.getDefault().menuBar().closeSubmenus();
139                     return expected;
140                 }
141                 MainWindowOperator.getDefault().menuBar().closeSubmenus();
142                 new EventTool().waitNoEvent(500);
143                 System.err.println("waiting on "+actionPath);
144             }
145             return MainWindowOperator.getDefault().menuBar().showMenuItem(actionPath).isEnabled();
146         }
147     }
148     
149     public static boolean verifyPopup(Node node, String JavaDoc[] menus) {
150         //invocation of root popup
151
JPopupMenuOperator popup=node.callPopup();
152         return verifyPopup(popup, menus);
153     }
154     
155     public static boolean verifyPopup(final JPopupMenuOperator popup, String JavaDoc[] menus) {
156         for (int i=0;i < menus.length;i++) {
157             try {
158                 popup.showMenuItem(menus[i]);
159             } catch (NullPointerException JavaDoc npe) {
160                 throw new JemmyException("Popup path ["+menus[i]+"] not found.");
161             }
162         }
163         //close popup and wait until is not visible
164
popup.waitState(new ComponentChooser() {
165             public boolean checkComponent(Component JavaDoc comp) {
166                 popup.pushKey(KeyEvent.VK_ESCAPE);
167                 return !popup.isVisible();
168             }
169             public String JavaDoc getDescription() {
170                 return "Popup menu closed";
171             }
172         });
173         return true;
174     }
175     
176     public static boolean checkAnnotation(EditorOperator operator, int line, String JavaDoc annotationType) {
177         Object JavaDoc[] annotations = operator.getAnnotations(line);
178         boolean found = false;
179         JemmyProperties.getProperties().getOutput().print(">>>>> Annotations on line: "+line+"\n");
180         for (int i=0;i < annotations.length;i++) {
181             JemmyProperties.getProperties().getOutput().print(" "+operator.getAnnotationType(annotations[i])+"\n");
182             if (annotationType.equals(operator.getAnnotationType(annotations[i]))) found=true;
183         }
184         return found;
185     }
186     
187     public static void deleteAllBreakpoints() {
188         showDebuggerView(breakpointsViewTitle);
189         JTableOperator jTableOperator = new JTableOperator(new TopComponentOperator(breakpointsViewTitle));
190         if (jTableOperator.getRowCount() > 0)
191             new JPopupMenuOperator(jTableOperator.callPopupOnCell(0, 0)).pushMenu("Delete All");
192     }
193     
194     public static void deleteAllWatches() {
195         showDebuggerView(watchesViewTitle);
196         JTableOperator jTableOperator = new JTableOperator(new TopComponentOperator(watchesViewTitle));
197         if (jTableOperator.getRowCount() > 0)
198             new JPopupMenuOperator(jTableOperator.callPopupOnCell(0, 0)).pushMenu("Delete All");
199     }
200     
201     public static void closeZombieSessions() {
202         MainWindowOperator mwo = MainWindowOperator.getDefault();
203         showDebuggerView(sessionsViewTitle);
204         TopComponentOperator sessionsOper = new TopComponentOperator(sessionsViewTitle);
205         JTableOperator jTableOperator = new JTableOperator(sessionsOper);
206         
207         for (int i = 0; i < jTableOperator.getRowCount(); i++) {
208             //new Action(new StringBuffer(Utilities.runMenu).append("|").append(Utilities.killSessionsItem).toString(), null).perform();
209
new Action(null, null, Utilities.killSessionShortcut).performShortcut();
210             //Utilities.sleep(1000);
211
}
212         
213         jTableOperator = new JTableOperator(sessionsOper);
214         if (jTableOperator.getRowCount() > 0) {
215             for (int i = 0; i < jTableOperator.getRowCount(); i++) {
216                 jTableOperator.selectCell(i,0);
217                 javax.swing.JPopupMenu JavaDoc jPopupMenu = jTableOperator.callPopupOnCell(jTableOperator.getRowCount() - 1,0);
218                 new JPopupMenuOperator(jPopupMenu).pushMenu("Finish");
219                 mwo.waitStatusText("User program finished");
220             }
221         }
222         sessionsOper.close();
223     }
224     
225     public static void showDebuggerView(String JavaDoc viewName) {
226         new Action(windowMenu + "|" + debugMenu + "|" + viewName, null).perform();
227         new TopComponentOperator(viewName);
228         new EventTool().waitNoEvent(500);
229     }
230     
231     public static String JavaDoc removeTags(String JavaDoc in) {
232         String JavaDoc out = "";
233         in = in.trim();
234         if (in.indexOf('<') == -1) {
235             out = in;
236         } else {
237             while (in.indexOf('<') >= 0) {
238                 if (in.indexOf('<') == 0) {
239                     in = in.substring(in.indexOf('>')+1, in.length());
240                 } else {
241                     out += in.substring(0, in.indexOf('<'));
242                     in = in.substring(in.indexOf('<'), in.length());
243                 }
244             }
245         }
246         return out;
247     }
248     
249     public static void endAllSessions() {
250         String JavaDoc finishPath = runMenu+"|"+finishSessionsItem;
251         while (MainWindowOperator.getDefault().menuBar().showMenuItem(finishPath).isEnabled()) {
252             new FinishDebuggerAction().performShortcut();
253             new EventTool().waitNoEvent(500);
254         }
255         MainWindowOperator.getDefault().menuBar().closeSubmenus();
256     }
257     
258     public static void startDebugger() {
259         // "Set as Main Project"
260
String JavaDoc setAsMainProjectItem = Bundle.getStringTrimmed("org.netbeans.modules.project.ui.actions.Bundle", "LBL_SetAsMainProjectAction_Name");
261         new Action(null, setAsMainProjectItem).perform(new ProjectsTabOperator().getProjectRootNode(testProjectName));
262         new DebugProjectAction().performShortcut();
263         getDebugToolbar().waitComponentVisible(true);
264     }
265     
266     public static ContainerOperator getDebugToolbar() {
267         return MainWindowOperator.getDefault().getToolbar(debugToolbarLabel);
268     }
269     
270     public static void setCaret(EditorOperator eo, final int line) {
271         eo.makeComponentVisible();
272         eo.setCaretPositionToLine(line);
273         new EventTool().waitNoEvent(500);
274         
275         try {
276             new Waiter(new Waitable() {
277                 public Object JavaDoc actionProduced(Object JavaDoc editorOper) {
278                     EditorOperator op = (EditorOperator)editorOper;
279                     if (op.getLineNumber() == line) {
280                         return Boolean.TRUE;
281                     }
282                     return null;
283                 }
284                 
285                 public String JavaDoc getDescription() {
286                     return "Wait caret position on line " + line;
287                 }
288             }).waitAction(eo);
289         } catch (InterruptedException JavaDoc ex) {
290             ex.printStackTrace();
291         }
292     }
293     
294     public static NbDialogOperator newBreakpoint(int line, int column) {
295         EditorOperator eo = new EditorOperator("MemoryView.java");
296         eo.setCaretPosition(line, column);
297         new NewBreakpointAction().perform();
298         NbDialogOperator dialog = new NbDialogOperator(newBreakpointTitle);
299         new EventTool().waitNoEvent(1000l);
300         return dialog;
301     }
302     
303     public static NbDialogOperator newBreakpoint(int line) {
304         Node projectNode = ProjectsTabOperator.invoke().getProjectRootNode(testProjectName);
305         EditorOperator eo = new EditorOperator("MemoryView.java");
306         setCaret(eo, line);
307         new NewBreakpointAction().perform();
308         NbDialogOperator dialog = new NbDialogOperator(newBreakpointTitle);
309         new EventTool().waitNoEvent(1000l);
310         return dialog;
311     }
312     
313     public static void toggleBreakpoint(EditorOperator eo, final int line) {
314         toggleBreakpoint(eo, line, true);
315     }
316     
317     public static void toggleBreakpoint(EditorOperator eo, final int line, final boolean newBreakpoint) {
318         setCaret(eo, line);
319         
320         new ToggleBreakpointAction().perform();
321         try {
322             new Waiter(new Waitable() {
323                 public Object JavaDoc actionProduced(Object JavaDoc editorOper) {
324                     Object JavaDoc[] annotations = ((EditorOperator) editorOper).getAnnotations(line);
325                     boolean found =false;
326                     for (int i = 0; i < annotations.length; i++) {
327                         if ("Breakpoint".equals(((EditorOperator) editorOper).getAnnotationType(annotations[i]))) {
328                             found=true;
329                             if (newBreakpoint) {
330                                 return Boolean.TRUE;
331                             }
332                         }
333                     }
334                     if (!found && !newBreakpoint) {
335                         return Boolean.TRUE;
336                     }
337                     return null;
338                 }
339                 
340                 public String JavaDoc getDescription() {
341                     return "Wait breakpoint established on line " + line;
342                 }
343             }).waitAction(eo);
344         } catch (InterruptedException JavaDoc ex) {
345             ex.printStackTrace();
346         }
347     }
348     
349     public static void waitFinished(JellyTestCase test, String JavaDoc projectName, String JavaDoc target) {
350         long oldTimeout = MainWindowOperator.getDefault().getTimeouts().getTimeout("Waiter.WaitingTime");
351         try {
352             // increase time to wait to 240 second (it fails on slower machines)
353
MainWindowOperator.getDefault().getTimeouts().setTimeout("Waiter.WaitingTime", 240000);
354             MainWindowOperator.getDefault().waitStatusText("Finished building "+projectName+" ("+target+")");
355         } finally {
356             // start status text tracer again because we use it further
357
MainWindowOperator.getDefault().getStatusTextTracer().start();
358             // restore default timeout
359
MainWindowOperator.getDefault().getTimeouts().setTimeout("Waiter.WaitingTime", oldTimeout);
360             // log messages from output
361
test.getLog("RunOutput").print(new OutputTabOperator(projectName).getText()); // NOI18N
362
}
363     }
364     
365     public static void waitStatusText(String JavaDoc text) {
366         long oldTimeout = MainWindowOperator.getDefault().getTimeouts().getTimeout("Waiter.WaitingTime");
367         try {
368             // increase time to wait to 240 second (it fails on slower machines)
369
MainWindowOperator.getDefault().getTimeouts().setTimeout("Waiter.WaitingTime", 240000);
370             MainWindowOperator.getDefault().waitStatusText(text);
371         } finally {
372             // start status text tracer again because we use it further
373
MainWindowOperator.getDefault().getStatusTextTracer().start();
374             // restore default timeout
375
MainWindowOperator.getDefault().getTimeouts().setTimeout("Waiter.WaitingTime", oldTimeout);
376         }
377     }
378     
379     public static void waitStatusTextPrefix(final String JavaDoc text) {
380         try {
381             new Waiter(new Waitable() {
382                 public Object JavaDoc actionProduced(Object JavaDoc anObject) {
383                     JemmyProperties.getProperties().getOutput().print(">>>>> status text: "+StatusDisplayer.getDefault().getStatusText()+" > "+anObject+"\n");
384                     if (StatusDisplayer.getDefault().getStatusText().startsWith(text))
385                         return Boolean.TRUE;
386                     return null;
387                 }
388                 public String JavaDoc getDescription() {
389                     return("Wait status text prefix: "+text);
390                 }
391             }).waitAction(StatusDisplayer.getDefault());
392         } catch (InterruptedException JavaDoc ex) {
393             ex.printStackTrace();
394         }
395     }
396     
397     public static int getDebuggerConsoleStatus() {
398         return new OutputTabOperator(debuggerConsoleTitle).getLineCount();
399     }
400     
401     public static int waitDebuggerConsole(final String JavaDoc text, final int status) {
402         OutputTabOperator op = new OutputTabOperator(debuggerConsoleTitle);
403         ConsoleChooser cch = new ConsoleChooser(op, text, status);
404         JemmyProperties.getCurrentOutput().printLine("Waiting on text in debugger console '"+text+"' from line "+status);
405         JemmyProperties.setCurrentTimeout("ComponentOperator.WaitStateTimeout", 30000l);
406         try {
407             op.waitState(cch);
408         } catch (TimeoutExpiredException ex) {
409             JemmyProperties.getCurrentOutput().printLine("Not found text in debugger console:");
410             JemmyProperties.getCurrentOutput().printLine(op.getText());
411             throw ex;
412         }
413         JemmyProperties.getCurrentOutput().printLine("Found text in debugger console '"+text+"' at line "+cch.getLastIndex());
414         return cch.getLastIndex();
415     }
416     
417     static class ConsoleChooser implements ComponentChooser {
418         int lastIndex = 0;
419         OutputTabOperator op;
420         String JavaDoc text;
421         int status;
422         public ConsoleChooser(OutputTabOperator op, String JavaDoc text, int status) {
423             this.op = op;
424             this.text = text;
425             this.status = status;
426         }
427         public boolean checkComponent(Component JavaDoc comp) {
428             for(int i = status; i < op.getLineCount(); i++) {
429                 if(op.getLine(i).startsWith(text)) {
430                     lastIndex = i;
431                     return true;
432                 }
433             }
434             return false;
435         }
436         public String JavaDoc getDescription() {
437             return("\"" + text + "\" text");
438         }
439         public int getLastIndex() {
440             return lastIndex;
441         }
442     }
443 }
444
445
Popular Tags