KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > localhistory > operators > ShowLocalHistoryOperator


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.localhistory.operators;
20
21 import java.awt.Component JavaDoc;
22 import java.awt.Point JavaDoc;
23 import javax.swing.JComponent JavaDoc;
24 import javax.swing.JPopupMenu JavaDoc;
25 import org.netbeans.jellytools.TopComponentOperator;
26 import org.netbeans.jellytools.TreeTableOperator;
27 import org.netbeans.jellytools.nodes.Node;
28 import org.netbeans.jemmy.ComponentChooser;
29 import org.netbeans.jemmy.operators.JButtonOperator;
30 import org.netbeans.jemmy.operators.JListOperator;
31 import org.netbeans.jemmy.operators.JPopupMenuOperator;
32 import org.netbeans.test.localhistory.actions.ShowLocalHistoryAction;
33
34 /** Class implementing all necessary methods for handling "Local History" view.
35  */

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

50     public static ShowLocalHistoryOperator invoke(Node[] nodes) {
51         new ShowLocalHistoryAction().perform(nodes);
52         return new ShowLocalHistoryOperator();
53     }
54     
55     /** Selects node and call Local History action on it.
56      * @param node node to be selected
57      * @return SearchHistoryOperator instance
58      */

59     public static ShowLocalHistoryOperator invoke(Node node) {
60         return invoke(new Node[] {node});
61     }
62     
63     private JButtonOperator _btNext;
64     private JButtonOperator _btPrevious;
65     private TreeTableOperator _treeTable;
66     
67     //******************************
68
// Subcomponents definition part
69
//******************************
70

71     
72     
73     /** Tries to find Go to Next Difference JButton in this dialog.
74      * @return JButtonOperator
75      */

76     public JButtonOperator btNext() {
77         if (_btNext==null) {
78             String JavaDoc tooltip = "Go to next difference";
79             _btNext = new JButtonOperator(this, new TooltipChooser(tooltip, getComparator()));
80         }
81         return _btNext;
82     }
83     
84     /** Tries to find Go to Previous Difference JButton in this dialog.
85      * @return JButtonOperator
86      */

87     public JButtonOperator btPrevious() {
88         if (_btPrevious==null) {
89             String JavaDoc tooltip = "Go to previous difference";
90             _btPrevious = new JButtonOperator(this, new TooltipChooser(tooltip, getComparator()));
91         }
92         return _btPrevious;
93     }
94     
95     /** Tries to find History JList in this dialog.
96      * @return JListOperator
97      */

98     public TreeTableOperator treeTableHistory() {
99         if (_treeTable == null) {
100             _treeTable = new TreeTableOperator(this);
101         }
102         return _treeTable;
103     }
104     
105     
106     //****************************************
107
// Low-level functionality definition part
108
//****************************************
109

110     /** clicks on Go to Next Difference JButton
111      */

112     public void next() {
113         btNext().push();
114     }
115     
116     /** clicks on Go to Previous Difference JButton
117      */

118     public void previous() {
119         btPrevious().push();
120     }
121     
122     /** Selects a folder denoted by path.
123      * @param path path to folder without root (e.g. "folder|subfolder")
124      */

125     public void selectFolder(String JavaDoc path) {
126         new Node(treeTableHistory().tree(), path).select();
127     }
128     
129     public void performPopupAction(int rowIndex, String JavaDoc path) {
130         JPopupMenu JavaDoc popup = treeTableHistory().callPopupOnCell(rowIndex, 0);
131         JPopupMenuOperator popupOperator = new JPopupMenuOperator(popup);
132         popupOperator.pushMenu(path);
133     }
134     
135     //*****************************************
136
// High-level functionality definition part
137
//*****************************************
138

139     /** Performs verification of SearchHistoryOperator by accessing all its components.
140      */

141     public void verify() {
142         btNext();
143         btPrevious();
144         treeTableHistory();
145     }
146     
147     /** SubChooser to determine TopComponent is instance of
148      * org.netbeans.modules.versioning.system.cvss.ui.history.SearchHistoryTopComponent
149      * Used in constructor.
150      */

151     private static final class LocalHistorySubchooser implements ComponentChooser {
152         public boolean checkComponent(Component JavaDoc comp) {
153             return comp.getClass().getName().endsWith("LocalHistoryTopComponent");
154         }
155         
156         public String JavaDoc getDescription() {
157             return "org.netbeans.modules.localhistory.ui.view.LocalHistoryTopComponent";
158         }
159     }
160     
161     /** Chooser which can be used to find a component with given tooltip,
162      * for example a button.
163      */

164     private static class TooltipChooser implements ComponentChooser {
165         private String JavaDoc buttonTooltip;
166         private StringComparator comparator;
167         
168         public TooltipChooser(String JavaDoc buttonTooltip, StringComparator comparator) {
169             this.buttonTooltip = buttonTooltip;
170             this.comparator = comparator;
171         }
172         
173         public boolean checkComponent(Component JavaDoc comp) {
174             return comparator.equals(((JComponent JavaDoc)comp).getToolTipText(), buttonTooltip);
175         }
176         
177         public String JavaDoc getDescription() {
178             return "Button with tooltip \""+buttonTooltip+"\".";
179         }
180     }
181 }
182
Popular Tags