KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.swing.JComponent JavaDoc;
23 import org.netbeans.jellytools.Bundle;
24 import org.netbeans.jellytools.TopComponentOperator;
25 import org.netbeans.jellytools.actions.Action;
26 import org.netbeans.jemmy.ComponentChooser;
27 import org.netbeans.jemmy.operators.JButtonOperator;
28 import org.netbeans.jemmy.operators.JPopupMenuOperator;
29 import org.netbeans.jemmy.operators.JTableOperator;
30 import org.netbeans.jemmy.operators.JToggleButtonOperator;
31
32 /** Class implementing all necessary methods for handling "Versioning" view.
33  * <br>
34  * Usage:<br>
35  * <pre>
36  * VersioningOperator vo = VersioningOperator.invoke();
37  * vo.checkLocal(true);
38  * vo.checkRemote(true);
39  * vo.checkAll(true);
40  * vo.refresh();
41  * vo.diff();
42  * vo.update();
43  * vo.performPopup("MyFile", "Exclude from Commit");
44  * CommitOperator co = vo.commit();
45  * co.setCommitMessage("Commit message.");
46  * co.commit();
47  * </pre>
48  *
49  * @see CommitOperator
50  *
51  */

52 public class VersioningOperator extends TopComponentOperator {
53     
54     /** "Versioning" */
55     static final String JavaDoc VERSIONING_TITLE = "Versioning";
56     static final String JavaDoc SUBVERSION_TITLE = "Subversion";
57     
58     /** Waits for Versioning TopComponent within whole IDE. */
59     public VersioningOperator() {
60         super(waitTopComponent(null, SUBVERSION_TITLE, 0, new VersioningSubchooser()));
61     }
62     
63     /** Invokes Window|Versioning main menu item and returns new instance of
64      * VersioningOperator.
65      * @return new instance of VersioningOperator */

66     public static VersioningOperator invoke() {
67         String JavaDoc windowItem = Bundle.getStringTrimmed("org.netbeans.core.Bundle", "Menu/Window");
68         String JavaDoc versioningItem = "Subversion";
69         new Action(windowItem + "|" + VERSIONING_TITLE + "|" + versioningItem, null).perform();
70         return new VersioningOperator();
71     }
72     
73     private JToggleButtonOperator _tbAll;
74     private JToggleButtonOperator _tbLocal;
75     private JToggleButtonOperator _tbRemote;
76     private JButtonOperator _btRefresh;
77     private JButtonOperator _btDiff;
78     private JButtonOperator _btUpdate;
79     private JButtonOperator _btCommit;
80     private JTableOperator _tabFiles;
81     
82     
83     //******************************
84
// Subcomponents definition part
85
//******************************
86

87     /** Tries to find "All" JToggleButton in this dialog.
88      * @return JToggleButtonOperator
89      */

90     public JToggleButtonOperator tbAll() {
91         if (_tbAll==null) {
92             _tbAll = new JToggleButtonOperator(this, "All");
93         }
94         return _tbAll;
95     }
96     
97     /** Tries to find "Local" JToggleButton in this dialog.
98      * @return JToggleButtonOperator
99      */

100     public JToggleButtonOperator tbLocal() {
101         if (_tbLocal==null) {
102             _tbLocal = new JToggleButtonOperator(this, "Local");
103         }
104         return _tbLocal;
105     }
106     
107     /** Tries to find "Remote" JToggleButton in this dialog.
108      * @return JToggleButtonOperator
109      */

110     public JToggleButtonOperator tbRemote() {
111         if (_tbRemote==null) {
112             _tbRemote = new JToggleButtonOperator(this, "Remote");
113         }
114         return _tbRemote;
115     }
116     
117     /** Tries to find Refresh Status JButton in this dialog.
118      * @return JButtonOperator
119      */

120     public JButtonOperator btRefresh() {
121         if (_btRefresh==null) {
122             _btRefresh = new JButtonOperator(this, new TooltipChooser(
123                     "Refresh Status",
124                     this.getComparator()));
125         }
126         return _btRefresh;
127     }
128     
129     /** Tries to find Diff All JButton in this dialog.
130      * @return JButtonOperator
131      */

132     public JButtonOperator btDiff() {
133         if (_btDiff==null) {
134             _btDiff = new JButtonOperator(this, new TooltipChooser(
135                     "Diff All",
136                     this.getComparator()));
137         }
138         return _btDiff;
139     }
140     
141     /** Tries to find Update All JButton in this dialog.
142      * @return JButtonOperator
143      */

144     public JButtonOperator btUpdate() {
145         if (_btUpdate==null) {
146             _btUpdate = new JButtonOperator(this, new TooltipChooser(
147                     "Update All",
148                     this.getComparator()));
149         }
150         return _btUpdate;
151     }
152     
153     /** Tries to find Commit All JButton in this dialog.
154      * @return JButtonOperator
155      */

156     public JButtonOperator btCommit() {
157         if (_btCommit==null) {
158             _btCommit = new JButtonOperator(this, new TooltipChooser(
159                     "Commit All",
160                     this.getComparator()));
161         }
162         return _btCommit;
163     }
164     
165     /** Tries to find files JTable in this dialog.
166      * @return JTableOperator
167      */

168     public JTableOperator tabFiles() {
169         if (_tabFiles==null) {
170             _tabFiles = new JTableOperator(this);
171         }
172         return _tabFiles;
173     }
174     
175     
176     //****************************************
177
// Low-level functionality definition part
178
//****************************************
179

180     /** checks or unchecks given JToggleButton
181      * @param state boolean requested state
182      */

183     public void checkAll(boolean state) {
184         if (tbAll().isSelected()!=state) {
185             tbAll().push();
186         }
187     }
188     
189     /** checks or unchecks given JToggleButton
190      * @param state boolean requested state
191      */

192     public void checkLocal(boolean state) {
193         if (tbLocal().isSelected()!=state) {
194             tbLocal().push();
195         }
196     }
197     
198     /** checks or unchecks given JToggleButton
199      * @param state boolean requested state
200      */

201     public void checkRemote(boolean state) {
202         if (tbRemote().isSelected()!=state) {
203             tbRemote().push();
204         }
205     }
206     
207     /** clicks on Refresh Status JButton
208      */

209     public void refresh() {
210         btRefresh().push();
211     }
212     
213     /** clicks on Diff All JButton
214      */

215     public void diff() {
216         btDiff().push();
217     }
218     
219     /** clicks on Update All JButton
220      */

221     public void update() {
222         btUpdate().push();
223     }
224     
225     /** clicks on Commit JButton and returns CommitOperator.
226      * @return CommitOperator instance
227      */

228     public CommitOperator commit() {
229         btCommit().pushNoBlock();
230         return new CommitOperator();
231     }
232     
233     /** Performs popup menu on specified row.
234      * @param row row number to be selected (starts from 0)
235      * @param popupPath popup menu path
236      */

237     public void performPopup(int row, String JavaDoc popupPath) {
238         tabFiles().selectCell(row, 0);
239         JPopupMenuOperator popup = new JPopupMenuOperator(tabFiles().callPopupOnCell(row, 0));
240         popup.pushMenu(popupPath);
241     }
242     
243     /** Performs popup menu on specified file.
244      * @param filename name of file to be selected
245      * @param popupPath popup menu path
246      */

247     public void performPopup(String JavaDoc filename, String JavaDoc popupPath) {
248         performPopup(tabFiles().findCellRow(filename), popupPath);
249     }
250
251     /** Performs popup menu on specified row and no block further execution.
252      * @param row row number to be selected (starts from 0)
253      * @param popupPath popup menu path
254      */

255     public void performPopupNoBlock(int row, String JavaDoc popupPath) {
256         tabFiles().selectCell(row, 0);
257         JPopupMenuOperator popup = new JPopupMenuOperator(tabFiles().callPopupOnCell(row, 0));
258         popup.pushMenuNoBlock(popupPath);
259     }
260     
261     /** Performs popup menu on specified file and no block further execution.
262      * @param filename name of file to be selected
263      * @param popupPath popup menu path
264      */

265     public void performPopupNoBlock(String JavaDoc filename, String JavaDoc popupPath) {
266         performPopupNoBlock(tabFiles().findCellRow(filename), popupPath);
267     }
268
269     //*****************************************
270
// High-level functionality definition part
271
//*****************************************
272

273     /** Performs verification of VersioningOperator by accessing all its components.
274      */

275     public void verify() {
276         tbAll();
277         tbLocal();
278         tbRemote();
279         btRefresh();
280         btDiff();
281         btUpdate();
282         btCommit();
283         tabFiles();
284     }
285     
286     /** SubChooser to determine TopComponent is instance of
287      * org.netbeans.modules.subversion.ui.status.SvnVersioningTopComponent
288      * Used in constructor.
289      */

290     private static final class VersioningSubchooser implements ComponentChooser {
291         public boolean checkComponent(Component JavaDoc comp) {
292             return comp.getClass().getName().endsWith("SvnVersioningTopComponent");
293         }
294         
295         public String JavaDoc getDescription() {
296             return "org.netbeans.modules.subversion.ui.status.SvnVersioningTopComponent";
297         }
298     }
299     
300     /** Chooser which can be used to find a component with given tooltip,
301      * for example a button.
302      */

303     private static class TooltipChooser implements ComponentChooser {
304         private String JavaDoc buttonTooltip;
305         private StringComparator comparator;
306         
307         public TooltipChooser(String JavaDoc buttonTooltip, StringComparator comparator) {
308             this.buttonTooltip = buttonTooltip;
309             this.comparator = comparator;
310         }
311         
312         public boolean checkComponent(Component JavaDoc comp) {
313             return comparator.equals(((JComponent JavaDoc)comp).getToolTipText(), buttonTooltip);
314         }
315         
316         public String JavaDoc getDescription() {
317             return "Button with tooltip \""+buttonTooltip+"\".";
318         }
319     }
320 }
321
322
Popular Tags