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