|
1 /* |
|
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 package org.netbeans.jemmy.drivers.menus; |
|
24 |
|
25 import java.awt.Component; |
|
26 |
|
27 import javax.swing.JMenu; |
|
28 import javax.swing.JMenuBar; |
|
29 import javax.swing.JMenuItem; |
|
30 |
|
31 import org.netbeans.jemmy.ComponentChooser; |
|
32 import org.netbeans.jemmy.JemmyException; |
|
33 import org.netbeans.jemmy.drivers.MenuDriver; |
|
34 import org.netbeans.jemmy.drivers.PathChooser; |
|
35 import org.netbeans.jemmy.operators.AbstractButtonOperator; |
|
36 import org.netbeans.jemmy.operators.ComponentOperator; |
|
37 import org.netbeans.jemmy.operators.JMenuItemOperator; |
|
38 import org.netbeans.jemmy.operators.JMenuOperator; |
|
39 |
|
40 public class APIJMenuDriver extends DefaultJMenuDriver implements MenuDriver { |
|
41 |
|
42 public APIJMenuDriver() { |
|
43 super(); |
|
44 } |
|
45 |
|
46 protected Object push(ComponentOperator oper, JMenuBar menuBar, |
|
47 PathChooser chooser, int depth, boolean pressMouse) { |
|
48 try { |
|
49 oper.waitComponentVisible(true); |
|
50 oper.waitComponentEnabled(); |
|
51 } catch (InterruptedException e) { |
|
52 throw (new JemmyException("Interrupted!", e)); |
|
53 } |
|
54 if (depth > chooser.getDepth() - 1) { |
|
55 if (oper instanceof JMenuOperator) { |
|
56 if (((JMenuOperator) oper).isPopupMenuVisible()) { |
|
57 ((JMenuOperator) oper).setPopupMenuVisible(false); |
|
58 } |
|
59 ((JMenuOperator) oper).setPopupMenuVisible(true); |
|
60 waitPopupMenu(oper); |
|
61 } |
|
62 ((AbstractButtonOperator) oper).doClick(); |
|
63 return oper.getSource(); |
|
64 } else { |
|
65 if (((JMenuOperator) oper).isPopupMenuVisible()) { |
|
66 ((JMenuOperator) oper).setPopupMenuVisible(false); |
|
67 } |
|
68 ((JMenuOperator) oper).setPopupMenuVisible(true); |
|
69 waitPopupMenu(oper); |
|
70 } |
|
71 oper.getTimeouts().sleep("JMenuOperator.WaitBeforePopupTimeout"); |
|
72 JMenuItem item = waitItem(oper, waitPopupMenu(oper), chooser, depth); |
|
73 if (item instanceof JMenu) { |
|
74 JMenuOperator mo = new JMenuOperator((JMenu) item); |
|
75 mo.copyEnvironment(oper); |
|
76 Object result = push(mo, null, chooser, depth + 1, false); |
|
77 if (result instanceof JMenu) { |
|
78 org.netbeans.jemmy.JemmyProperties.getCurrentOutput().printLine("IN HERE" + ((JMenu) result).getText()); |
|
79 org.netbeans.jemmy.JemmyProperties.getCurrentOutput().printLine("IN HERE" + Boolean.toString(((JMenu) result).isPopupMenuVisible())); |
|
80 if (!((JMenu) result).isPopupMenuVisible()) { |
|
81 ((JMenuOperator) oper).setPopupMenuVisible(false); |
|
82 } |
|
83 } else { |
|
84 ((JMenuOperator) oper).setPopupMenuVisible(false); |
|
85 waitNoPopupMenu(oper); |
|
86 } |
|
87 return result; |
|
88 } else { |
|
89 JMenuItemOperator mio = new JMenuItemOperator(item); |
|
90 mio.copyEnvironment(oper); |
|
91 try { |
|
92 mio.waitComponentEnabled(); |
|
93 } catch (InterruptedException e) { |
|
94 throw (new JemmyException("Interrupted!", e)); |
|
95 } |
|
96 mio.doClick(); |
|
97 ((JMenuOperator) oper).setPopupMenuVisible(false); |
|
98 waitNoPopupMenu(oper); |
|
99 return item; |
|
100 } |
|
101 } |
|
102 |
|
103 protected void waitNoPopupMenu(final ComponentOperator oper) { |
|
104 oper.waitState(new ComponentChooser() { |
|
105 @Override |
|
106 public boolean checkComponent(Component comp) { |
|
107 return !((JMenuOperator) oper).isPopupMenuVisible(); |
|
108 } |
|
109 |
|
110 @Override |
|
111 public String getDescription() { |
|
112 return ((JMenuOperator) oper).getText() + "'s popup"; |
|
113 } |
|
114 |
|
115 @Override |
|
116 public String toString() { |
|
117 return "waitNoPopupMenu.ComponentChooser{description = " + getDescription() + '}'; |
|
118 } |
|
119 }); |
|
120 } |
|
121 |
|
122 } |