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.jellytools.modules.javacvs;
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: * @see org.netbeans.jellytools.modules.javacvs.actions.ShowChangesAction
073: *
074: * @author Jiri.Skrivanek@sun.com
075: */
076: public class VersioningOperator extends TopComponentOperator {
077:
078: /** "Versioning" */
079: static final String VERSIONING_TITLE = Bundle
080: .getStringTrimmed(
081: "org.netbeans.modules.versioning.system.cvss.ui.syncview.Bundle",
082: "CTL_Synchronize_TopComponent_Title");
083:
084: /** Waits for Versioning TopComponent within whole IDE. */
085: public VersioningOperator() {
086: super (waitTopComponent(null, VERSIONING_TITLE, 0,
087: new VersioningSubchooser()));
088: }
089:
090: /** Invokes Window|Versioning|CVS main menu item and returns new instance of
091: * VersioningOperator.
092: * @return new instance of VersioningOperator */
093: public static VersioningOperator invoke() {
094: String windowItem = Bundle.getStringTrimmed(
095: "org.netbeans.core.Bundle", "Menu/Window");
096: String versioningItem = Bundle.getStringTrimmed(
097: "org.netbeans.modules.versioning.Bundle",
098: "Menu/Window/Versioning");
099: String cvsItem = Bundle
100: .getString(
101: "org.netbeans.modules.versioning.system.cvss.ui.actions.Bundle",
102: "CTL_MenuItem_CVSCommands_Label");
103: new Action(windowItem + "|" + versioningItem + "|" + cvsItem,
104: null).perform();
105: return new VersioningOperator();
106: }
107:
108: private JToggleButtonOperator _tbAll;
109: private JToggleButtonOperator _tbLocal;
110: private JToggleButtonOperator _tbRemote;
111: private JButtonOperator _btRefresh;
112: private JButtonOperator _btDiff;
113: private JButtonOperator _btUpdate;
114: private JButtonOperator _btCommit;
115: private JTableOperator _tabFiles;
116:
117: //******************************
118: // Subcomponents definition part
119: //******************************
120:
121: /** Tries to find "All" JToggleButton in this dialog.
122: * @return JToggleButtonOperator
123: */
124: public JToggleButtonOperator tbAll() {
125: if (_tbAll == null) {
126: _tbAll = new JToggleButtonOperator(
127: this ,
128: Bundle
129: .getStringTrimmed(
130: "org.netbeans.modules.versioning.system.cvss.ui.syncview.Bundle",
131: "CTL_Synchronize_Action_All_Label"));
132: }
133: return _tbAll;
134: }
135:
136: /** Tries to find "Local" JToggleButton in this dialog.
137: * @return JToggleButtonOperator
138: */
139: public JToggleButtonOperator tbLocal() {
140: if (_tbLocal == null) {
141: _tbLocal = new JToggleButtonOperator(
142: this ,
143: Bundle
144: .getStringTrimmed(
145: "org.netbeans.modules.versioning.system.cvss.ui.syncview.Bundle",
146: "CTL_Synchronize_Action_Local_Label"));
147: }
148: return _tbLocal;
149: }
150:
151: /** Tries to find "Remote" JToggleButton in this dialog.
152: * @return JToggleButtonOperator
153: */
154: public JToggleButtonOperator tbRemote() {
155: if (_tbRemote == null) {
156: _tbRemote = new JToggleButtonOperator(
157: this ,
158: Bundle
159: .getStringTrimmed(
160: "org.netbeans.modules.versioning.system.cvss.ui.syncview.Bundle",
161: "CTL_Synchronize_Action_Remote_Label"));
162: }
163: return _tbRemote;
164: }
165:
166: /** Tries to find Refresh Status JButton in this dialog.
167: * @return JButtonOperator
168: */
169: public JButtonOperator btRefresh() {
170: if (_btRefresh == null) {
171: _btRefresh = new JButtonOperator(
172: this ,
173: new TooltipChooser(
174: Bundle
175: .getString(
176: "org.netbeans.modules.versioning.system.cvss.ui.syncview.Bundle",
177: "CTL_Synchronize_Action_Refresh_Tooltip"),
178: this .getComparator()));
179: }
180: return _btRefresh;
181: }
182:
183: /** Tries to find Diff All JButton in this dialog.
184: * @return JButtonOperator
185: */
186: public JButtonOperator btDiff() {
187: if (_btDiff == null) {
188: _btDiff = new JButtonOperator(
189: this ,
190: new TooltipChooser(
191: Bundle
192: .getString(
193: "org.netbeans.modules.versioning.system.cvss.ui.syncview.Bundle",
194: "CTL_Synchronize_Action_Diff_Tooltip"),
195: this .getComparator()));
196: }
197: return _btDiff;
198: }
199:
200: /** Tries to find Update All JButton in this dialog.
201: * @return JButtonOperator
202: */
203: public JButtonOperator btUpdate() {
204: if (_btUpdate == null) {
205: _btUpdate = new JButtonOperator(
206: this ,
207: new TooltipChooser(
208: Bundle
209: .getString(
210: "org.netbeans.modules.versioning.system.cvss.ui.syncview.Bundle",
211: "CTL_Synchronize_Action_Update_Tooltip"),
212: this .getComparator()));
213: }
214: return _btUpdate;
215: }
216:
217: /** Tries to find Commit All JButton in this dialog.
218: * @return JButtonOperator
219: */
220: public JButtonOperator btCommit() {
221: if (_btCommit == null) {
222: _btCommit = new JButtonOperator(
223: this ,
224: new TooltipChooser(
225: Bundle
226: .getString(
227: "org.netbeans.modules.versioning.system.cvss.ui.syncview.Bundle",
228: "CTL_CommitForm_Action_Commit_Tooltip"),
229: this .getComparator()));
230: }
231: return _btCommit;
232: }
233:
234: /** Tries to find files JTable in this dialog.
235: * @return JTableOperator
236: */
237: public JTableOperator tabFiles() {
238: if (_tabFiles == null) {
239: _tabFiles = new JTableOperator(this );
240: }
241: return _tabFiles;
242: }
243:
244: //****************************************
245: // Low-level functionality definition part
246: //****************************************
247:
248: /** checks or unchecks given JToggleButton
249: * @param state boolean requested state
250: */
251: public void checkAll(boolean state) {
252: if (tbAll().isSelected() != state) {
253: tbAll().push();
254: }
255: }
256:
257: /** checks or unchecks given JToggleButton
258: * @param state boolean requested state
259: */
260: public void checkLocal(boolean state) {
261: if (tbLocal().isSelected() != state) {
262: tbLocal().push();
263: }
264: }
265:
266: /** checks or unchecks given JToggleButton
267: * @param state boolean requested state
268: */
269: public void checkRemote(boolean state) {
270: if (tbRemote().isSelected() != state) {
271: tbRemote().push();
272: }
273: }
274:
275: /** clicks on Refresh Status JButton
276: */
277: public void refresh() {
278: btRefresh().push();
279: }
280:
281: /** clicks on Diff All JButton
282: */
283: public void diff() {
284: btDiff().push();
285: }
286:
287: /** clicks on Update All JButton
288: */
289: public void update() {
290: btUpdate().push();
291: }
292:
293: /** clicks on Commit JButton and returns CommitOperator.
294: * @return CommitOperator instance
295: */
296: public CommitOperator commit() {
297: btCommit().pushNoBlock();
298: return new CommitOperator();
299: }
300:
301: /** Performs popup menu on specified row.
302: * @param row row number to be selected (starts from 0)
303: * @param popupPath popup menu path
304: */
305: public void performPopup(int row, String popupPath) {
306: tabFiles().selectCell(row, 0);
307: JPopupMenuOperator popup = new JPopupMenuOperator(tabFiles()
308: .callPopupOnCell(row, 0));
309: popup.pushMenu(popupPath);
310: }
311:
312: /** Performs popup menu on specified file.
313: * @param filename name of file to be selected
314: * @param popupPath popup menu path
315: */
316: public void performPopup(String filename, String popupPath) {
317: performPopup(tabFiles().findCellRow(filename), popupPath);
318: }
319:
320: /** Performs popup menu on specified row and no block further execution.
321: * @param row row number to be selected (starts from 0)
322: * @param popupPath popup menu path
323: */
324: public void performPopupNoBlock(int row, String popupPath) {
325: tabFiles().selectCell(row, 0);
326: JPopupMenuOperator popup = new JPopupMenuOperator(tabFiles()
327: .callPopupOnCell(row, 0));
328: popup.pushMenuNoBlock(popupPath);
329: }
330:
331: /** Performs popup menu on specified file and no block further execution.
332: * @param filename name of file to be selected
333: * @param popupPath popup menu path
334: */
335: public void performPopupNoBlock(String filename, String popupPath) {
336: performPopupNoBlock(tabFiles().findCellRow(filename), popupPath);
337: }
338:
339: //*****************************************
340: // High-level functionality definition part
341: //*****************************************
342:
343: /** Performs verification of VersioningOperator by accessing all its components.
344: */
345: public void verify() {
346: tbAll();
347: tbLocal();
348: tbRemote();
349: btRefresh();
350: btDiff();
351: btUpdate();
352: btCommit();
353: tabFiles();
354: }
355:
356: /** SubChooser to determine TopComponent is instance of
357: * org.netbeans.modules.versioning.system.cvss.ui.syncview.CvsSynchronizeTopComponent
358: * Used in constructor.
359: */
360: private static final class VersioningSubchooser implements
361: ComponentChooser {
362: public boolean checkComponent(Component comp) {
363: return comp.getClass().getName().endsWith(
364: "CvsSynchronizeTopComponent");
365: }
366:
367: public String getDescription() {
368: return "org.netbeans.modules.versioning.system.cvss.ui.syncview.CvsSynchronizeTopComponent";
369: }
370: }
371:
372: /** Chooser which can be used to find a component with given tooltip,
373: * for example a button.
374: */
375: private static class TooltipChooser implements ComponentChooser {
376: private String buttonTooltip;
377: private StringComparator comparator;
378:
379: public TooltipChooser(String buttonTooltip,
380: StringComparator comparator) {
381: this .buttonTooltip = buttonTooltip;
382: this .comparator = comparator;
383: }
384:
385: public boolean checkComponent(Component comp) {
386: return comparator.equals(((JComponent) comp)
387: .getToolTipText(), buttonTooltip);
388: }
389:
390: public String getDescription() {
391: return "Button with tooltip \"" + buttonTooltip + "\".";
392: }
393: }
394: }
|