001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.test.subversion.operators;
042:
043: import java.awt.Component;
044: import javax.swing.JComponent;
045: import org.netbeans.jellytools.Bundle;
046: import org.netbeans.jellytools.TopComponentOperator;
047: import org.netbeans.jellytools.actions.Action;
048: import org.netbeans.jemmy.ComponentChooser;
049: import org.netbeans.jemmy.operators.JButtonOperator;
050: import org.netbeans.jemmy.operators.JPopupMenuOperator;
051: import org.netbeans.jemmy.operators.JTableOperator;
052: import org.netbeans.jemmy.operators.JToggleButtonOperator;
053:
054: /** Class implementing all necessary methods for handling "Versioning" view.
055: * <br>
056: * Usage:<br>
057: * <pre>
058: * VersioningOperator vo = VersioningOperator.invoke();
059: * vo.checkLocal(true);
060: * vo.checkRemote(true);
061: * vo.checkAll(true);
062: * vo.refresh();
063: * vo.diff();
064: * vo.update();
065: * vo.performPopup("MyFile", "Exclude from Commit");
066: * CommitOperator co = vo.commit();
067: * co.setCommitMessage("Commit message.");
068: * co.commit();
069: * </pre>
070: *
071: * @see CommitOperator
072: *
073: */
074: public class VersioningOperator extends TopComponentOperator {
075:
076: /** "Versioning" */
077: static final String VERSIONING_TITLE = "Versioning";
078: static final String SUBVERSION_TITLE = "Subversion";
079:
080: /** Waits for Versioning TopComponent within whole IDE. */
081: public VersioningOperator() {
082: super (waitTopComponent(null, SUBVERSION_TITLE, 0,
083: new VersioningSubchooser()));
084: }
085:
086: /** Invokes Window|Versioning main menu item and returns new instance of
087: * VersioningOperator.
088: * @return new instance of VersioningOperator */
089: public static VersioningOperator invoke() {
090: String windowItem = Bundle.getStringTrimmed(
091: "org.netbeans.core.Bundle", "Menu/Window");
092: String versioningItem = "Subversion";
093: new Action(windowItem + "|" + VERSIONING_TITLE + "|"
094: + versioningItem, null).perform();
095: return new VersioningOperator();
096: }
097:
098: private JToggleButtonOperator _tbAll;
099: private JToggleButtonOperator _tbLocal;
100: private JToggleButtonOperator _tbRemote;
101: private JButtonOperator _btRefresh;
102: private JButtonOperator _btDiff;
103: private JButtonOperator _btUpdate;
104: private JButtonOperator _btCommit;
105: private JTableOperator _tabFiles;
106:
107: //******************************
108: // Subcomponents definition part
109: //******************************
110:
111: /** Tries to find "All" JToggleButton in this dialog.
112: * @return JToggleButtonOperator
113: */
114: public JToggleButtonOperator tbAll() {
115: if (_tbAll == null) {
116: _tbAll = new JToggleButtonOperator(this , "All");
117: }
118: return _tbAll;
119: }
120:
121: /** Tries to find "Local" JToggleButton in this dialog.
122: * @return JToggleButtonOperator
123: */
124: public JToggleButtonOperator tbLocal() {
125: if (_tbLocal == null) {
126: _tbLocal = new JToggleButtonOperator(this , "Local");
127: }
128: return _tbLocal;
129: }
130:
131: /** Tries to find "Remote" JToggleButton in this dialog.
132: * @return JToggleButtonOperator
133: */
134: public JToggleButtonOperator tbRemote() {
135: if (_tbRemote == null) {
136: _tbRemote = new JToggleButtonOperator(this , "Remote");
137: }
138: return _tbRemote;
139: }
140:
141: /** Tries to find Refresh Status JButton in this dialog.
142: * @return JButtonOperator
143: */
144: public JButtonOperator btRefresh() {
145: if (_btRefresh == null) {
146: _btRefresh = new JButtonOperator(this , new TooltipChooser(
147: "Refresh Status", this .getComparator()));
148: }
149: return _btRefresh;
150: }
151:
152: /** Tries to find Diff All JButton in this dialog.
153: * @return JButtonOperator
154: */
155: public JButtonOperator btDiff() {
156: if (_btDiff == null) {
157: _btDiff = new JButtonOperator(this , new TooltipChooser(
158: "Diff All", this .getComparator()));
159: }
160: return _btDiff;
161: }
162:
163: /** Tries to find Update All JButton in this dialog.
164: * @return JButtonOperator
165: */
166: public JButtonOperator btUpdate() {
167: if (_btUpdate == null) {
168: _btUpdate = new JButtonOperator(this , new TooltipChooser(
169: "Update All", this .getComparator()));
170: }
171: return _btUpdate;
172: }
173:
174: /** Tries to find Commit All JButton in this dialog.
175: * @return JButtonOperator
176: */
177: public JButtonOperator btCommit() {
178: if (_btCommit == null) {
179: _btCommit = new JButtonOperator(this , new TooltipChooser(
180: "Commit All", this .getComparator()));
181: }
182: return _btCommit;
183: }
184:
185: /** Tries to find files JTable in this dialog.
186: * @return JTableOperator
187: */
188: public JTableOperator tabFiles() {
189: if (_tabFiles == null) {
190: _tabFiles = new JTableOperator(this );
191: }
192: return _tabFiles;
193: }
194:
195: //****************************************
196: // Low-level functionality definition part
197: //****************************************
198:
199: /** checks or unchecks given JToggleButton
200: * @param state boolean requested state
201: */
202: public void checkAll(boolean state) {
203: if (tbAll().isSelected() != state) {
204: tbAll().push();
205: }
206: }
207:
208: /** checks or unchecks given JToggleButton
209: * @param state boolean requested state
210: */
211: public void checkLocal(boolean state) {
212: if (tbLocal().isSelected() != state) {
213: tbLocal().push();
214: }
215: }
216:
217: /** checks or unchecks given JToggleButton
218: * @param state boolean requested state
219: */
220: public void checkRemote(boolean state) {
221: if (tbRemote().isSelected() != state) {
222: tbRemote().push();
223: }
224: }
225:
226: /** clicks on Refresh Status JButton
227: */
228: public void refresh() {
229: btRefresh().push();
230: }
231:
232: /** clicks on Diff All JButton
233: */
234: public void diff() {
235: btDiff().push();
236: }
237:
238: /** clicks on Update All JButton
239: */
240: public void update() {
241: btUpdate().push();
242: }
243:
244: /** clicks on Commit JButton and returns CommitOperator.
245: * @return CommitOperator instance
246: */
247: public CommitOperator commit() {
248: btCommit().pushNoBlock();
249: return new CommitOperator();
250: }
251:
252: /** Performs popup menu on specified row.
253: * @param row row number to be selected (starts from 0)
254: * @param popupPath popup menu path
255: */
256: public void performPopup(int row, String popupPath) {
257: tabFiles().selectCell(row, 0);
258: JPopupMenuOperator popup = new JPopupMenuOperator(tabFiles()
259: .callPopupOnCell(row, 0));
260: popup.pushMenu(popupPath);
261: }
262:
263: /** Performs popup menu on specified file.
264: * @param filename name of file to be selected
265: * @param popupPath popup menu path
266: */
267: public void performPopup(String filename, String popupPath) {
268: performPopup(tabFiles().findCellRow(filename), popupPath);
269: }
270:
271: /** Performs popup menu on specified row and no block further execution.
272: * @param row row number to be selected (starts from 0)
273: * @param popupPath popup menu path
274: */
275: public void performPopupNoBlock(int row, String popupPath) {
276: tabFiles().selectCell(row, 0);
277: JPopupMenuOperator popup = new JPopupMenuOperator(tabFiles()
278: .callPopupOnCell(row, 0));
279: popup.pushMenuNoBlock(popupPath);
280: }
281:
282: /** Performs popup menu on specified file and no block further execution.
283: * @param filename name of file to be selected
284: * @param popupPath popup menu path
285: */
286: public void performPopupNoBlock(String filename, String popupPath) {
287: performPopupNoBlock(tabFiles().findCellRow(filename), popupPath);
288: }
289:
290: //*****************************************
291: // High-level functionality definition part
292: //*****************************************
293:
294: /** Performs verification of VersioningOperator by accessing all its components.
295: */
296: public void verify() {
297: tbAll();
298: tbLocal();
299: tbRemote();
300: btRefresh();
301: btDiff();
302: btUpdate();
303: btCommit();
304: tabFiles();
305: }
306:
307: /** SubChooser to determine TopComponent is instance of
308: * org.netbeans.modules.subversion.ui.status.SvnVersioningTopComponent
309: * Used in constructor.
310: */
311: private static final class VersioningSubchooser implements
312: ComponentChooser {
313: public boolean checkComponent(Component comp) {
314: return comp.getClass().getName().endsWith(
315: "SvnVersioningTopComponent");
316: }
317:
318: public String getDescription() {
319: return "org.netbeans.modules.subversion.ui.status.SvnVersioningTopComponent";
320: }
321: }
322:
323: /** Chooser which can be used to find a component with given tooltip,
324: * for example a button.
325: */
326: private static class TooltipChooser implements ComponentChooser {
327: private String buttonTooltip;
328: private StringComparator comparator;
329:
330: public TooltipChooser(String buttonTooltip,
331: StringComparator comparator) {
332: this .buttonTooltip = buttonTooltip;
333: this .comparator = comparator;
334: }
335:
336: public boolean checkComponent(Component comp) {
337: return comparator.equals(((JComponent) comp)
338: .getToolTipText(), buttonTooltip);
339: }
340:
341: public String getDescription() {
342: return "Button with tooltip \"" + buttonTooltip + "\".";
343: }
344: }
345: }
|