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.mercurial.operators;
042:
043: import org.netbeans.jellytools.NbDialogOperator;
044: import org.netbeans.jellytools.nodes.Node;
045: import org.netbeans.jemmy.operators.JButtonOperator;
046: import org.netbeans.jemmy.operators.JComboBoxOperator;
047: import org.netbeans.jemmy.operators.JLabelOperator;
048: import org.netbeans.jemmy.operators.JTableOperator;
049: import org.netbeans.jemmy.operators.JTextAreaOperator;
050: import org.netbeans.test.mercurial.operators.actions.CommitAction;
051:
052: /** Class implementing all necessary methods for handling "Commit" dialog.
053: * <br>
054: * Usage:<br>
055: * <pre>
056: * new CommitAction().perform(node);
057: * CommitOperator co = new CommitOperator();
058: * co.setCommitMessage("Commit message.");
059: * co.selectCommitAction("MyFile", "Exclude from Commit");
060: * co.commit();
061: * </pre>
062: *
063: * @see VersioningOperator
064: * @see org.netbeans.jellytools.modules.javacvs.actions.CommitAction
065: * @see org.netbeans.jellytools.modules.javacvs.actions.ShowChangesAction
066: *
067: */
068: public class CommitOperator extends NbDialogOperator {
069:
070: /** Waits for "Commit" dialog. It can have title "Commit - <object>"
071: * or "Commit files" if there is no file to commit.
072: */
073: public CommitOperator() {
074: super ("Commit");
075: }
076:
077: /** Selects nodes and call commit action on them.
078: * @param nodes an array of nodes
079: * @return CommitOperator instance
080: */
081: public static CommitOperator invoke(Node[] nodes) {
082: new CommitAction().perform(nodes);
083: return new CommitOperator();
084: }
085:
086: /** Selects node and call commit action on it.
087: * @param node node to be selected
088: * @return CommitOperator instance
089: */
090: public static CommitOperator invoke(Node node) {
091: return invoke(new Node[] { node });
092: }
093:
094: private JLabelOperator _lblCommitMessage;
095: private JTextAreaOperator _txtCommitMessage;
096: private JLabelOperator _lblFilesToCommit;
097: private JTableOperator _tabFiles;
098: private JButtonOperator _btCommit;
099: private JButtonOperator _btCancel;
100: private JButtonOperator _btHelp;
101:
102: //******************************
103: // Subcomponents definition part
104: //******************************
105:
106: /** Tries to find "Commit Message:" JLabel in this dialog.
107: * @return JLabelOperator
108: */
109: public JLabelOperator lblCommitMessage() {
110: if (_lblCommitMessage == null) {
111: _lblCommitMessage = new JLabelOperator(this ,
112: "Commit Message");
113: }
114: return _lblCommitMessage;
115: }
116:
117: /** Tries to find "Commit Message:" TextArea in this dialog.
118: * @return JTextAreaOperator
119: */
120: public JTextAreaOperator txtCommitMessage() {
121: if (_txtCommitMessage == null) {
122: _txtCommitMessage = new JTextAreaOperator(this );
123: }
124: return _txtCommitMessage;
125: }
126:
127: /** Tries to find "Files to Commit:" JLabel in this dialog.
128: * @return JLabelOperator
129: */
130: public JLabelOperator lblFilesToCommit() {
131: if (_lblFilesToCommit == null) {
132: _lblFilesToCommit = new JLabelOperator(this ,
133: "Files to Commit");
134: }
135: return _lblFilesToCommit;
136: }
137:
138: /** Tries to find files JTable in this dialog.
139: * @return JTableOperator
140: */
141: public JTableOperator tabFiles() {
142: if (_tabFiles == null) {
143: _tabFiles = new JTableOperator(this );
144: }
145: return _tabFiles;
146: }
147:
148: /** Tries to find "Commit" JButton in this dialog.
149: * @return JButtonOperator
150: */
151: public JButtonOperator btCommit() {
152: if (_btCommit == null) {
153: _btCommit = new JButtonOperator(this , "Commit");
154: }
155: return _btCommit;
156: }
157:
158: /** Tries to find "Cancel" JButton in this dialog.
159: * @return JButtonOperator
160: */
161: public JButtonOperator btCancel() {
162: if (_btCancel == null) {
163: _btCancel = new JButtonOperator(this , "Cancel");
164: }
165: return _btCancel;
166: }
167:
168: /** Tries to find "Help" JButton in this dialog.
169: * @return JButtonOperator
170: */
171: public JButtonOperator btHelp() {
172: if (_btHelp == null) {
173: _btHelp = new JButtonOperator(this , "Help");
174: }
175: return _btHelp;
176: }
177:
178: //****************************************
179: // Low-level functionality definition part
180: //****************************************
181:
182: /** gets text for txtCommitMessage
183: * @return String text
184: */
185: public String getCommitMessage() {
186: return txtCommitMessage().getText();
187: }
188:
189: /** sets text for txtCommitMessage
190: * @param text String text
191: */
192: public void setCommitMessage(String text) {
193: txtCommitMessage().clearText();
194: txtCommitMessage().typeText(text);
195: }
196:
197: /** clicks on "Commit" JButton
198: */
199: public void commit() {
200: btCommit().push();
201: }
202:
203: /** Selects specified commit action for given row.
204: * @param rowIndex index of row to be selected
205: * @param action name of action to be selected
206: */
207: public void selectCommitAction(int rowIndex, String action) {
208: tabFiles().clickOnCell(rowIndex, 2);
209: JComboBoxOperator combo = new JComboBoxOperator(tabFiles());
210: combo.selectItem(action);
211: }
212:
213: /** Selects specified commit action for given row.
214: * @param filename name of file to be selected
215: * @param action name of action to be selected
216: */
217: public void selectCommitAction(String filename, String action) {
218: selectCommitAction(tabFiles().findCellRow(filename), action);
219: }
220:
221: //*****************************************
222: // High-level functionality definition part
223: //*****************************************
224:
225: /** Performs verification of CommitOperator by accessing all its components.
226: */
227: public void verify() {
228: lblCommitMessage();
229: txtCommitMessage();
230: // lblFilesToCommit();
231: tabFiles();
232: btCommit();
233: btCancel();
234: btHelp();
235: }
236: }
|