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 javax.swing.JTextField;
044: import org.netbeans.jellytools.Bundle;
045: import org.netbeans.jellytools.NbDialogOperator;
046: import org.netbeans.jellytools.modules.javacvs.actions.BranchAction;
047: import org.netbeans.jellytools.nodes.Node;
048: import org.netbeans.jemmy.operators.JButtonOperator;
049: import org.netbeans.jemmy.operators.JCheckBoxOperator;
050: import org.netbeans.jemmy.operators.JLabelOperator;
051: import org.netbeans.jemmy.operators.JTextFieldOperator;
052:
053: /** Class implementing all necessary methods for handling "Branch" dialog.
054: * It is opened from main menu or from popup on versioned file.
055: * <br>
056: * Usage:<br>
057: * <pre>
058: * Node node = new Node(new SourcePackagesNode("MyProject"), "mypackage|MyFile");
059: * BranchOperator bro = BranchOperator.invoke(node);
060: * bro.setBranchName("mybranch");
061: * // or
062: * //BrowseTagsOperator bto = bro.browse();
063: * //bto.selectBranch("mybranch");
064: * //bto.ok();
065: * //bro.checkTagBeforeBranching(false);
066: * bro.setTagName("tagname");
067: * bro.checkSwitchToThisBranchAftewards(false);
068: * bro.branch();
069: *</pre>
070: *
071: * @see BrowseTagsOperator
072: * @see org.netbeans.jellytools.modules.javacvs.actions.BranchAction
073: *
074: * @author Jiri.Skrivanek@sun.com
075: */
076: public class BranchOperator extends NbDialogOperator {
077:
078: /** Waits for "Branch" dialog. */
079: public BranchOperator() {
080: super (
081: Bundle
082: .getStringTrimmed(
083: "org.netbeans.modules.versioning.system.cvss.ui.actions.tag.Bundle",
084: "CTL_BranchDialog_Title"));
085: }
086:
087: /** Selects nodes and call branch action on them.
088: * @param nodes an array of nodes
089: * @return BranchOperator instance
090: */
091: public static BranchOperator invoke(Node[] nodes) {
092: new BranchAction().perform(nodes);
093: return new BranchOperator();
094: }
095:
096: /** Selects node and call branch action on it.
097: * @param node node to be selected
098: * @return BranchOperator instance
099: */
100: public static BranchOperator invoke(Node node) {
101: return invoke(new Node[] { node });
102: }
103:
104: private JCheckBoxOperator _cbTagBeforeBranching;
105: private JCheckBoxOperator _cbSwitchToThisBranchAftewards;
106: private JLabelOperator _lblBranchName;
107: private JTextFieldOperator _txtBranchName;
108: private JButtonOperator _btBrowse;
109: private JLabelOperator _lblTagName;
110: private JTextFieldOperator _txtTagName;
111: private JButtonOperator _btBranch;
112:
113: //******************************
114: // Subcomponents definition part
115: //******************************
116:
117: /** Tries to find "Tag Before Branching" JCheckBox in this dialog.
118: * @return JCheckBoxOperator
119: */
120: public JCheckBoxOperator cbTagBeforeBranching() {
121: if (_cbTagBeforeBranching == null) {
122: _cbTagBeforeBranching = new JCheckBoxOperator(
123: this ,
124: Bundle
125: .getStringTrimmed(
126: "org.netbeans.modules.versioning.system.cvss.ui.actions.tag.Bundle",
127: "CTL_BranchForm_TagBase"));
128: }
129: return _cbTagBeforeBranching;
130: }
131:
132: /** Tries to find "Switch to This Branch Aftewards" JCheckBox in this dialog.
133: * @return JCheckBoxOperator
134: */
135: public JCheckBoxOperator cbSwitchToThisBranchAftewards() {
136: if (_cbSwitchToThisBranchAftewards == null) {
137: _cbSwitchToThisBranchAftewards = new JCheckBoxOperator(
138: this ,
139: Bundle
140: .getStringTrimmed(
141: "org.netbeans.modules.versioning.system.cvss.ui.actions.tag.Bundle",
142: "CTL_BranchForm_UpdateToBranch"));
143: }
144: return _cbSwitchToThisBranchAftewards;
145: }
146:
147: /** Tries to find "Branch Name:" JLabel in this dialog.
148: * @return JLabelOperator
149: */
150: public JLabelOperator lblBranchName() {
151: if (_lblBranchName == null) {
152: _lblBranchName = new JLabelOperator(
153: this ,
154: Bundle
155: .getStringTrimmed(
156: "org.netbeans.modules.versioning.system.cvss.ui.actions.tag.Bundle",
157: "CTL_BranchForm_BranchName"));
158: }
159: return _lblBranchName;
160: }
161:
162: /** Tries to find Branch Name JTextField in this dialog.
163: * @return JTextFieldOperator
164: */
165: public JTextFieldOperator txtBranchName() {
166: if (_txtBranchName == null) {
167: _txtBranchName = new JTextFieldOperator(
168: (JTextField) lblBranchName().getLabelFor());
169: }
170: return _txtBranchName;
171: }
172:
173: /** Tries to find "Browse..." JButton in this dialog.
174: * @return JButtonOperator
175: */
176: public JButtonOperator btBrowse() {
177: if (_btBrowse == null) {
178: _btBrowse = new JButtonOperator(
179: this ,
180: Bundle
181: .getStringTrimmed(
182: "org.netbeans.modules.versioning.system.cvss.ui.actions.tag.Bundle",
183: "CTL_BranchForm_BrowseBranch"));
184: }
185: return _btBrowse;
186: }
187:
188: /** Tries to find "Tag Name:" JLabel in this dialog.
189: * @return JLabelOperator
190: */
191: public JLabelOperator lblTagName() {
192: if (_lblTagName == null) {
193: _lblTagName = new JLabelOperator(
194: this ,
195: Bundle
196: .getStringTrimmed(
197: "org.netbeans.modules.versioning.system.cvss.ui.actions.tag.Bundle",
198: "CTL_BranchForm_BaseTagName"));
199: }
200: return _lblTagName;
201: }
202:
203: /** Tries to find null JTextField in this dialog.
204: * @return JTextFieldOperator
205: */
206: public JTextFieldOperator txtTagName() {
207: if (_txtTagName == null) {
208: _txtTagName = new JTextFieldOperator(
209: (JTextField) lblTagName().getLabelFor());
210: }
211: return _txtTagName;
212: }
213:
214: /** Tries to find "Branch" JButton in this dialog.
215: * @return JButtonOperator
216: */
217: public JButtonOperator btBranch() {
218: if (_btBranch == null) {
219: _btBranch = new JButtonOperator(
220: this ,
221: Bundle
222: .getStringTrimmed(
223: "org.netbeans.modules.versioning.system.cvss.ui.actions.tag.Bundle",
224: "CTL_BranchDialog_Action_Branch"));
225: }
226: return _btBranch;
227: }
228:
229: //****************************************
230: // Low-level functionality definition part
231: //****************************************
232:
233: /** checks or unchecks given JCheckBox
234: * @param state boolean requested state
235: */
236: public void checkTagBeforeBranching(boolean state) {
237: if (cbTagBeforeBranching().isSelected() != state) {
238: cbTagBeforeBranching().push();
239: }
240: }
241:
242: /** checks or unchecks given JCheckBox
243: * @param state boolean requested state
244: */
245: public void checkSwitchToThisBranchAftewards(boolean state) {
246: if (cbSwitchToThisBranchAftewards().isSelected() != state) {
247: cbSwitchToThisBranchAftewards().push();
248: }
249: }
250:
251: /** gets text for txtBranchName
252: * @return String text
253: */
254: public String getBranchName() {
255: return txtBranchName().getText();
256: }
257:
258: /** sets text for txtBranchName
259: * @param text String text
260: */
261: public void setBranchName(String text) {
262: txtBranchName().clearText();
263: txtBranchName().typeText(text);
264: }
265:
266: /** clicks on "Browse..." JButton and returns BrowseTagsOperator.
267: * @return BrowseTagsOperator instance
268: */
269: public BrowseTagsOperator browse() {
270: btBrowse().pushNoBlock();
271: return new BrowseTagsOperator();
272: }
273:
274: /** gets text for txtTagName
275: * @return String text
276: */
277: public String getTagName() {
278: return txtTagName().getText();
279: }
280:
281: /** sets text for txtTagName
282: * @param text String text
283: */
284: public void setTagName(String text) {
285: txtTagName().clearText();
286: txtTagName().typeText(text);
287: }
288:
289: /** clicks on "Branch" JButton
290: */
291: public void branch() {
292: btBranch().push();
293: }
294:
295: //*****************************************
296: // High-level functionality definition part
297: //*****************************************
298:
299: /** Performs verification of BranchOperator by accessing all its components.
300: */
301: public void verify() {
302: cbTagBeforeBranching();
303: cbSwitchToThisBranchAftewards();
304: lblBranchName();
305: txtBranchName();
306: btBrowse();
307: lblTagName();
308: txtTagName();
309: btBranch();
310: }
311: }
|