KickJava   Java API By Example, From Geeks To Geeks.

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


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.JComboBoxOperator;
29 import org.netbeans.jemmy.operators.JPopupMenuOperator;
30 import org.netbeans.jemmy.operators.JTableOperator;
31 import org.netbeans.jemmy.operators.JToggleButtonOperator;
32 import org.netbeans.jemmy.operators.Operator;
33
34
35 public class DiffOperator extends TopComponentOperator {
36     
37     /** Waits for Diff TopComponent with specified file name.
38      * @param name name of 'diffed' file
39      */

40     public DiffOperator(String JavaDoc name) {
41         super(waitTopComponent(null, name, 0, new DiffSubchooser()));
42     }
43     
44     /** Waits for first open Diff TopComponent. */
45     public DiffOperator() {
46         this(null);
47     }
48     
49     private JButtonOperator _btNext;
50     private JButtonOperator _btPrevious;
51     private JToggleButtonOperator _tbRemoveLocal;
52     private JToggleButtonOperator _tbLocal;
53     private JToggleButtonOperator _tbRemote;
54     private JButtonOperator _btRefresh;
55     private JButtonOperator _btUpdate;
56     private JButtonOperator _btCommit;
57     private JComboBoxOperator _cbFiles;
58     
59     //******************************
60
// Subcomponents definition part
61
//******************************
62

63     /** Tries to find Go to Next Difference JButton in diff view.
64      * @return JButtonOperator
65      */

66     public JButtonOperator btNext() {
67         if (_btNext==null) {
68             String JavaDoc tooltip = "Go to next difference";
69             _btNext = new JButtonOperator(this, new TooltipChooser(tooltip, getComparator()));
70         }
71         return _btNext;
72     }
73     
74     /** Tries to find Go to Previous Difference JButton in diff view.
75      * @return JButtonOperator
76      */

77     public JButtonOperator btPrevious() {
78         if (_btPrevious==null) {
79             String JavaDoc tooltip = "Go to previous difference";
80             _btPrevious = new JButtonOperator(this, new TooltipChooser(tooltip, getComparator()));
81         }
82         return _btPrevious;
83     }
84     
85     /** Tries to find "Remove vs Local" JToggleButton in diff view.
86      * @return JToggleButtonOperator
87      */

88     public JToggleButtonOperator tbRemoteLocal() {
89         if (_tbRemoveLocal==null) {
90             _tbRemoveLocal = new JToggleButtonOperator(this, "Remote vs Local");
91         }
92         return _tbRemoveLocal;
93     }
94     
95     /** Tries to find "Local" JToggleButton in diff view.
96      * @return JToggleButtonOperator
97      */

98     public JToggleButtonOperator tbLocal() {
99         if (_tbLocal==null) {
100             Operator.StringComparator oldComparator = Operator.getDefaultStringComparator();
101             Operator.DefaultStringComparator comparator = new Operator.DefaultStringComparator(true, true);
102             try {
103                 this.setComparator(comparator);
104                 _tbLocal = new JToggleButtonOperator(this, "Local");
105             } finally {
106                 this.setComparator(oldComparator);
107             }
108         }
109         return _tbLocal;
110     }
111     
112     /** Tries to find "Remote" JToggleButton in diff view.
113      * @return JToggleButtonOperator
114      */

115     public JToggleButtonOperator tbRemote() {
116         if (_tbRemote==null) {
117             Operator.StringComparator oldComparator = Operator.getDefaultStringComparator();
118             Operator.DefaultStringComparator comparator = new Operator.DefaultStringComparator(true, true);
119             try {
120                 this.setComparator(comparator);
121                 _tbRemote = new JToggleButtonOperator(this, "Remote");
122             } finally {
123                 this.setComparator(oldComparator);
124             }
125         }
126         return _tbRemote;
127     }
128     
129     /** Tries to find Refresh Diff JButton in diff view.
130      * @return JButtonOperator
131      */

132     public JButtonOperator btRefresh() {
133         if (_btRefresh==null) {
134             _btRefresh = new JButtonOperator(this, new TooltipChooser("Refresh Diff", this.getComparator()));
135         }
136         return _btRefresh;
137     }
138     
139     /** Tries to find Update JButton in diff view.
140      * @return JButtonOperator
141      */

142     public JButtonOperator btUpdate() {
143         if (_btUpdate==null) {
144             _btUpdate = new JButtonOperator(this, new TooltipChooser("Update \"{0}\"", this.getComparator()));
145         }
146         return _btUpdate;
147     }
148     
149     /** Tries to find Commit JButton in diff view.
150      * @return JButtonOperator
151      */

152     public JButtonOperator btCommit() {
153         if (_btCommit==null) {
154             _btCommit = new JButtonOperator(this, new TooltipChooser("Commit \"{0}\"", this.getComparator()));
155         }
156         return _btCommit;
157     }
158     
159     /** Tries to find files JComboBoxOperator in diff view.
160      * @return JComboBoxOperator
161      */

162     public JComboBoxOperator cbFiles() {
163         if (_cbFiles == null) {
164             _cbFiles = new JComboBoxOperator(this);
165         }
166         return _cbFiles;
167     }
168     //****************************************
169
// Low-level functionality definition part
170
//****************************************
171

172     /** clicks on Go to Next Difference JButton
173      */

174     public void next() {
175         btNext().push();
176     }
177     
178     /** clicks on Go to Previous Difference JButton
179      */

180     public void previous() {
181         btPrevious().push();
182     }
183     
184     /** checks or unchecks given JToggleButton
185      * @param state boolean requested state
186      */

187     public void checkRemoteLocal(boolean state) {
188         if (tbRemoteLocal().isSelected()!=state) {
189             tbRemoteLocal().push();
190         }
191     }
192     
193     /** checks or unchecks given JToggleButton
194      * @param state boolean requested state
195      */

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

205     public void checkRemote(boolean state) {
206         if (tbRemote().isSelected()!=state) {
207             tbRemote().push();
208         }
209     }
210     
211     /** clicks on Refresh Diff JButton
212      */

213     public void refresh() {
214         btRefresh().push();
215     }
216     
217     /** clicks on Update JButton
218      */

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

226     public CommitOperator commit() {
227         btCommit().pushNoBlock();
228         return new CommitOperator();
229     }
230     
231     /** Selects specified file in combo box.
232      * @param name file name to be selected
233      */

234     public void selectFile(String JavaDoc name) {
235         cbFiles().selectItem(name);
236     }
237     
238     /** Selects index-th file in combo box.
239      * @param index index of file to be selected
240      */

241     public void selectFile(int index) {
242         cbFiles().selectItem(index);
243     }
244     
245     //*****************************************
246
// High-level functionality definition part
247
//*****************************************
248

249     /** Performs verification of VersioningOperator by accessing all its components.
250      */

251     public void verify() {
252         btNext();
253         btPrevious();
254         tbRemoteLocal();
255         tbLocal();
256         tbRemote();
257         btRefresh();
258         btUpdate();
259         btCommit();
260         cbFiles();
261     }
262     
263     /** SubChooser to determine TopComponent is instance of
264      * org.netbeans.modules.versioning.system.cvss.ui.actions.diff.DiffExecutor$DiffTopComponent
265      * Used in constructor.
266      */

267     private static final class DiffSubchooser implements ComponentChooser {
268         public boolean checkComponent(Component JavaDoc comp) {
269             return comp.getClass().getName().endsWith("DiffTopComponent"); // NOI18N
270
}
271         
272         public String JavaDoc getDescription() {
273             return "org.netbeans.modules.subversion.ui.diff.DiffTopComponent"; // NOI18N
274
}
275     }
276     
277     /** Chooser which can be used to find a component with given tooltip,
278      * for example a button.
279      */

280     private static class TooltipChooser implements ComponentChooser {
281         private String JavaDoc buttonTooltip;
282         private StringComparator comparator;
283         
284         public TooltipChooser(String JavaDoc buttonTooltip, StringComparator comparator) {
285             this.buttonTooltip = buttonTooltip;
286             this.comparator = comparator;
287         }
288         
289         public boolean checkComponent(Component JavaDoc comp) {
290             return comparator.equals(((JComponent JavaDoc)comp).getToolTipText(), buttonTooltip);
291         }
292         
293         public String JavaDoc getDescription() {
294             return "Button with tooltip \""+buttonTooltip+"\".";
295         }
296     }
297 }
298
299
Popular Tags