KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > subversion > operators > SearchHistoryOperator


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  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.test.subversion.operators;
20
21 import java.awt.Component JavaDoc;
22 import java.awt.Point JavaDoc;
23 import javax.swing.JComponent JavaDoc;
24 import javax.swing.JTextField JavaDoc;
25 import org.netbeans.jellytools.TopComponentOperator;
26 import org.netbeans.jellytools.nodes.Node;
27 import org.netbeans.jemmy.ComponentChooser;
28 import org.netbeans.jemmy.operators.JButtonOperator;
29 import org.netbeans.jemmy.operators.JLabelOperator;
30 import org.netbeans.jemmy.operators.JListOperator;
31 import org.netbeans.jemmy.operators.JPopupMenuOperator;
32 import org.netbeans.jemmy.operators.JTextFieldOperator;
33 import org.netbeans.jemmy.operators.JToggleButtonOperator;
34 import org.netbeans.test.subversion.operators.actions.SearchHistoryAction;
35
36 /** Class implementing all necessary methods for handling "Search History" view.
37  */

38 public class SearchHistoryOperator extends TopComponentOperator {
39     
40     /** "Search History" */
41     static final String JavaDoc SEARCH_HISTORY_TITLE = "Search History";
42     
43     /** Waits for Search History TopComponent within whole IDE. */
44     public SearchHistoryOperator() {
45         super(waitTopComponent(null, SEARCH_HISTORY_TITLE, 0, new SearchHistorySubchooser()));
46     }
47     
48     /** Selects nodes and call search history action on them.
49      * @param nodes an array of nodes
50      * @return SearchHistoryOperator instance
51      */

52     public static SearchHistoryOperator invoke(Node[] nodes) {
53         new SearchHistoryAction().perform(nodes);
54         return new SearchHistoryOperator();
55     }
56     
57     /** Selects node and call search history action on it.
58      * @param node node to be selected
59      * @return SearchHistoryOperator instance
60      */

61     public static SearchHistoryOperator invoke(Node node) {
62         return invoke(new Node[] {node});
63     }
64     
65     private JLabelOperator _lblMessage;
66     private JTextFieldOperator _txtMessage;
67     private JLabelOperator _lblUsername;
68     private JTextFieldOperator _txtUsername;
69     private JLabelOperator _lblFrom;
70     private JTextFieldOperator _txtFrom;
71     private JButtonOperator _btBrowseFrom;
72     private JLabelOperator _lblTo;
73     private JTextFieldOperator _txtTo;
74     private JButtonOperator _btBrowseTo;
75     private JButtonOperator _btSearch;
76     private JToggleButtonOperator _tbSummary;
77     private JToggleButtonOperator _tbDiff;
78     private JButtonOperator _btNext;
79     private JButtonOperator _btPrevious;
80     private JListOperator _lstHistory;
81     
82     //******************************
83
// Subcomponents definition part
84
//******************************
85

86     /** Tries to find "Message:" JLabel in this dialog.
87      * @return JLabelOperator
88      */

89     public JLabelOperator lblMessage() {
90         if (_lblMessage==null) {
91             _lblMessage = new JLabelOperator(this, "Message:");
92         }
93         return _lblMessage;
94     }
95     
96     /** Tries to find null JTextField in this dialog.
97      * @return JTextFieldOperator
98      */

99     public JTextFieldOperator txtMessage() {
100         if (_txtMessage==null) {
101             _txtMessage = new JTextFieldOperator(
102                     (JTextField JavaDoc)lblMessage().getLabelFor());
103         }
104         return _txtMessage;
105     }
106     
107     /** Tries to find "Username:" JLabel in this dialog.
108      * @return JLabelOperator
109      */

110     public JLabelOperator lblUsername() {
111         if (_lblUsername==null) {
112             _lblUsername = new JLabelOperator(this, "Username:");
113         }
114         return _lblUsername;
115     }
116     
117     /** Tries to find null JTextField in this dialog.
118      * @return JTextFieldOperator
119      */

120     public JTextFieldOperator txtUsername() {
121         if (_txtUsername==null) {
122             _txtUsername = new JTextFieldOperator(
123                     (JTextField JavaDoc)lblUsername().getLabelFor());
124         }
125         return _txtUsername;
126     }
127     
128     /** Tries to find "From:" JLabel in this dialog.
129      * @return JLabelOperator
130      */

131     public JLabelOperator lblFrom() {
132         if (_lblFrom==null) {
133             _lblFrom = new JLabelOperator(this, "From:");
134         }
135         return _lblFrom;
136     }
137     
138     /** Tries to find null JTextField in this dialog.
139      * @return JTextFieldOperator
140      */

141     public JTextFieldOperator txtFrom() {
142         if (_txtFrom==null) {
143             _txtFrom = new JTextFieldOperator(
144                     (JTextField JavaDoc)lblFrom().getLabelFor());
145         }
146         return _txtFrom;
147     }
148     
149     /** Tries to find "Browse..." JButton in this dialog.
150      * @return JButtonOperator
151      */

152     public JButtonOperator btBrowseFrom() {
153         if (_btBrowseFrom==null) {
154             _btBrowseFrom = new JButtonOperator(this, "Browse");
155         }
156         return _btBrowseFrom;
157     }
158     
159     /** Tries to find "To:" JLabel in this dialog.
160      * @return JLabelOperator
161      */

162     public JLabelOperator lblTo() {
163         if (_lblTo==null) {
164             _lblTo = new JLabelOperator(this, "To:");
165         }
166         return _lblTo;
167     }
168     
169     /** Tries to find null JTextField in this dialog.
170      * @return JTextFieldOperator
171      */

172     public JTextFieldOperator txtTo() {
173         if (_txtTo==null) {
174             _txtTo = new JTextFieldOperator(
175                     (JTextField JavaDoc)lblTo().getLabelFor());
176         }
177         return _txtTo;
178     }
179     
180     /** Tries to find "Browse..." JButton in this dialog.
181      * @return JButtonOperator
182      */

183     public JButtonOperator btBrowseTo() {
184         if (_btBrowseTo==null) {
185             _btBrowseTo = new JButtonOperator(this, "Browse", 1);
186         }
187         return _btBrowseTo;
188     }
189     
190     /** Tries to find "Search" JButton in this dialog.
191      * @return JButtonOperator
192      */

193     public JButtonOperator btSearch() {
194         if (_btSearch==null) {
195             _btSearch = new JButtonOperator(this, "Search");
196         }
197         return _btSearch;
198     }
199     
200     /** Tries to find "Summary" JToggleButton in this dialog.
201      * @return JToggleButtonOperator
202      */

203     public JToggleButtonOperator tbSummary() {
204         if (_tbSummary==null) {
205             _tbSummary = new JToggleButtonOperator(this, "Summary");
206         }
207         return _tbSummary;
208     }
209     
210     /** Tries to find "Diff" JToggleButton in this dialog.
211      * @return JToggleButtonOperator
212      */

213     public JToggleButtonOperator tbDiff() {
214         if (_tbDiff==null) {
215             _tbDiff = new JToggleButtonOperator(this, "Diff");
216         }
217         return _tbDiff;
218     }
219     
220     /** Tries to find Go to Next Difference JButton in this dialog.
221      * @return JButtonOperator
222      */

223     public JButtonOperator btNext() {
224         if (_btNext==null) {
225             String JavaDoc tooltip = "Go to next difference";
226             _btNext = new JButtonOperator(this, new TooltipChooser(tooltip, getComparator()));
227         }
228         return _btNext;
229     }
230     
231     /** Tries to find Go to Previous Difference JButton in this dialog.
232      * @return JButtonOperator
233      */

234     public JButtonOperator btPrevious() {
235         if (_btPrevious==null) {
236             String JavaDoc tooltip = "Go to previous difference";
237             _btPrevious = new JButtonOperator(this, new TooltipChooser(tooltip, getComparator()));
238         }
239         return _btPrevious;
240     }
241     
242     /** Tries to find History JList in this dialog.
243      * @return JListOperator
244      */

245     public JListOperator lstHistory() {
246         if (_lstHistory==null) {
247             _lstHistory = new JListOperator(this);
248         }
249         return _lstHistory;
250     }
251     
252     
253     //****************************************
254
// Low-level functionality definition part
255
//****************************************
256

257     /** gets text for txtMessage
258      * @return String text
259      */

260     public String JavaDoc getMessage() {
261         return txtMessage().getText();
262     }
263     
264     /** sets text for txtMessage
265      * @param text String text
266      */

267     public void setMessage(String JavaDoc text) {
268         txtMessage().clearText();
269         txtMessage().typeText(text);
270     }
271     
272     /** gets text for txtUsername
273      * @return String text
274      */

275     public String JavaDoc getUsername() {
276         return txtUsername().getText();
277     }
278     
279     /** sets text for txtUsername
280      * @param text String text
281      */

282     public void setUsername(String JavaDoc text) {
283         txtUsername().clearText();
284         txtUsername().typeText(text);
285     }
286     
287     /** gets text for txtFrom
288      * @return String text
289      */

290     public String JavaDoc getFrom() {
291         return txtFrom().getText();
292     }
293     
294     /** sets text for txtFrom
295      * @param text String text
296      */

297     public void setFrom(String JavaDoc text) {
298         txtFrom().clearText();
299         txtFrom().typeText(text);
300     }
301     
302     /** gets text for txtTo
303      * @return String text
304      */

305     public String JavaDoc getTo() {
306         return txtTo().getText();
307     }
308     
309     /** sets text for txtTo
310      * @param text String text
311      */

312     public void setTo(String JavaDoc text) {
313         txtTo().clearText();
314         txtTo().typeText(text);
315     }
316     
317     /** clicks on "Search" JButton
318      */

319     public void search() {
320         btSearch().push();
321     }
322     
323     /** checks or unchecks Summary JToggleButton
324      * @param state boolean requested state
325      */

326     public void checkSummary(boolean state) {
327         if (tbSummary().isSelected()!=state) {
328             tbSummary().push();
329         }
330     }
331     
332     /** checks or unchecks Diff JToggleButton
333      * @param state boolean requested state
334      */

335     public void checkDiff(boolean state) {
336         if (tbDiff().isSelected()!=state) {
337             tbDiff().push();
338         }
339     }
340     
341     /** clicks on Go to Next Difference JButton
342      */

343     public void next() {
344         btNext().push();
345     }
346     
347     /** clicks on Go to Previous Difference JButton
348      */

349     public void previous() {
350         btPrevious().push();
351     }
352     
353     public RepositoryBrowserOperator getRevisionFrom() {
354         btBrowseFrom().pushNoBlock();
355         return new RepositoryBrowserOperator();
356     }
357     
358     public RepositoryBrowserOperator getRevisionTo() {
359         btBrowseTo().pushNoBlock();
360         return new RepositoryBrowserOperator();
361     }
362     
363     /** Performs popup menu on specified row in history list.
364      * @param rowIndex index of row (starts at 0)
365      * @param popupPath popup menu path
366      */

367     public void performPopup(int rowIndex, String JavaDoc popupPath) {
368         Point JavaDoc point = lstHistory().getClickPoint(rowIndex);
369         lstHistory().clickForPopup(point.x, point.y);
370         JPopupMenuOperator popup = new JPopupMenuOperator();
371         popup.pushMenu(popupPath);
372     }
373     
374     //*****************************************
375
// High-level functionality definition part
376
//*****************************************
377

378     /** Performs verification of SearchHistoryOperator by accessing all its components.
379      */

380     public void verify() {
381         lblMessage();
382         txtMessage();
383         lblUsername();
384         txtUsername();
385         lblFrom();
386         txtFrom();
387         btBrowseFrom();
388         lblTo();
389         txtTo();
390         btBrowseTo();
391         btSearch();
392         tbSummary();
393         tbDiff();
394         btNext();
395         btPrevious();
396         lstHistory();
397     }
398     
399     /** SubChooser to determine TopComponent is instance of
400      * org.netbeans.modules.versioning.system.cvss.ui.history.SearchHistoryTopComponent
401      * Used in constructor.
402      */

403     private static final class SearchHistorySubchooser implements ComponentChooser {
404         public boolean checkComponent(Component JavaDoc comp) {
405             return comp.getClass().getName().endsWith("SearchHistoryTopComponent");
406         }
407         
408         public String JavaDoc getDescription() {
409             return "org.netbeans.modules.subversion.ui.history.SearchHistoryTopComponent";
410         }
411     }
412     
413     /** Chooser which can be used to find a component with given tooltip,
414      * for example a button.
415      */

416     private static class TooltipChooser implements ComponentChooser {
417         private String JavaDoc buttonTooltip;
418         private StringComparator comparator;
419         
420         public TooltipChooser(String JavaDoc buttonTooltip, StringComparator comparator) {
421             this.buttonTooltip = buttonTooltip;
422             this.comparator = comparator;
423         }
424         
425         public boolean checkComponent(Component JavaDoc comp) {
426             return comparator.equals(((JComponent JavaDoc)comp).getToolTipText(), buttonTooltip);
427         }
428         
429         public String JavaDoc getDescription() {
430             return "Button with tooltip \""+buttonTooltip+"\".";
431         }
432     }
433 }
434
Popular Tags