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.TagAction;
046: import org.netbeans.jellytools.nodes.Node;
047: import org.netbeans.jemmy.operators.JButtonOperator;
048: import org.netbeans.jemmy.operators.JCheckBoxOperator;
049: import org.netbeans.jemmy.operators.JTextFieldOperator;
050:
051: /** Class implementing all necessary methods for handling "Tag" NbDialog.
052: * dialog. It is opened from main menu or from popup on versioned file.
053: * <br>
054: * Usage:<br>
055: * <pre>
056: * Node node = new Node(new SourcePackagesNode("MyProject"), "mypackage|MyFile");
057: * TagOperator to = TagOperator.invoke(node);
058: * to.setTagName("mytag");
059: * to.checkAvoidTaggingLocallyModifiedFiles(true);
060: * to.checkMoveExistingTag(true);
061: * to.tag();
062: * </pre>
063: *
064: * @see org.netbeans.jellytools.modules.javacvs.actions.TagAction
065: *
066: * @author Jiri.Skrivanek@sun.com
067: */
068: public class TagOperator extends NbDialogOperator {
069:
070: /** Waits for dialog with "Tag" title. */
071: public TagOperator() {
072: super (
073: Bundle
074: .getStringTrimmed(
075: "org.netbeans.modules.versioning.system.cvss.ui.actions.tag.Bundle",
076: "CTL_TagDialog_Title"));
077: }
078:
079: /** Selects nodes and call tag action on them.
080: * @param nodes an array of nodes
081: * @return TagOperator instance
082: */
083: public static TagOperator invoke(Node[] nodes) {
084: new TagAction().perform(nodes);
085: return new TagOperator();
086: }
087:
088: /** Selects node and call merge action on it.
089: * @param node node to be selected
090: * @return TagOperator instance
091: */
092: public static TagOperator invoke(Node node) {
093: return invoke(new Node[] { node });
094: }
095:
096: private JCheckBoxOperator _cbAvoidTaggingLocallyModifiedFilesC;
097: private JCheckBoxOperator _cbMoveExistingTagF;
098: private JTextFieldOperator _txtTagName;
099: private JButtonOperator _btTag;
100: private JButtonOperator _btBrowse;
101:
102: //******************************
103: // Subcomponents definition part
104: //******************************
105:
106: /** Tries to find "avoid tagging locally modified files (-c)" JCheckBox in this dialog.
107: * @return JCheckBoxOperator
108: */
109: public JCheckBoxOperator cbAvoidTaggingLocallyModifiedFiles() {
110: if (_cbAvoidTaggingLocallyModifiedFilesC == null) {
111: _cbAvoidTaggingLocallyModifiedFilesC = new JCheckBoxOperator(
112: this ,
113: Bundle
114: .getStringTrimmed(
115: "org.netbeans.modules.versioning.system.cvss.ui.actions.tag.Bundle",
116: "CTL_TagForm_EnsureUptodate"));
117: }
118: return _cbAvoidTaggingLocallyModifiedFilesC;
119: }
120:
121: /** Tries to find "move existing tag (-F)" JCheckBox in this dialog.
122: * @return JCheckBoxOperator
123: */
124: public JCheckBoxOperator cbMoveExistingTag() {
125: if (_cbMoveExistingTagF == null) {
126: _cbMoveExistingTagF = new JCheckBoxOperator(
127: this ,
128: Bundle
129: .getStringTrimmed(
130: "org.netbeans.modules.versioning.system.cvss.ui.actions.tag.Bundle",
131: "CTL_TagForm_MoveExisting"));
132: }
133: return _cbMoveExistingTagF;
134: }
135:
136: /** Tries to find tag name JTextField in this dialog.
137: * @return JTextFieldOperator
138: */
139: public JTextFieldOperator txtTagName() {
140: if (_txtTagName == null) {
141: _txtTagName = new JTextFieldOperator(this );
142: }
143: return _txtTagName;
144: }
145:
146: /** Returns operator of "Tag" button.
147: * @return JButtonOperator instance of "Tag" button
148: */
149: public JButtonOperator btTag() {
150: if (_btTag == null) {
151: String tagCaption = Bundle
152: .getString(
153: "org.netbeans.modules.versioning.system.cvss.ui.actions.tag.Bundle",
154: "CTL_TagDialog_Action_Tag");
155: _btTag = new JButtonOperator(this , tagCaption);
156: }
157: return _btTag;
158: }
159:
160: /** Returns operator of "Browse" button.
161: * @return JButtonOperator instance of "Browse" button
162: */
163: public JButtonOperator btBrowse() {
164: if (_btBrowse == null) {
165: String browseCaption = Bundle
166: .getStringTrimmed(
167: "org.netbeans.modules.versioning.system.cvss.ui.actions.tag.Bundle",
168: "CTL_BrowseTag");
169: _btBrowse = new JButtonOperator(this , browseCaption);
170: }
171: return _btBrowse;
172: }
173:
174: //****************************************
175: // Low-level functionality definition part
176: //****************************************
177:
178: /** checks or unchecks given JCheckBox
179: * @param state boolean requested state
180: */
181: public void checkAvoidTaggingLocallyModifiedFiles(boolean state) {
182: if (cbAvoidTaggingLocallyModifiedFiles().isSelected() != state) {
183: cbAvoidTaggingLocallyModifiedFiles().push();
184: }
185: }
186:
187: /** checks or unchecks given JCheckBox
188: * @param state boolean requested state
189: */
190: public void checkMoveExistingTag(boolean state) {
191: if (cbMoveExistingTag().isSelected() != state) {
192: cbMoveExistingTag().push();
193: }
194: }
195:
196: /** gets text for txtTagName
197: * @return String text
198: */
199: public String getTagName() {
200: return txtTagName().getText();
201: }
202:
203: /** sets text for txtTagName
204: * @param text String text
205: */
206: public void setTagName(String text) {
207: txtTagName().clearText();
208: txtTagName().typeText(text);
209: }
210:
211: /** Pushes "Tag" button. */
212: public void tag() {
213: btTag().push();
214: }
215:
216: /** Pushes "Browse..." button. */
217: public void browse() {
218: btBrowse().pushNoBlock();
219: }
220:
221: //*****************************************
222: // High-level functionality definition part
223: //*****************************************
224:
225: /** Performs verification of TagOperator by accessing all its components.
226: */
227: public void verify() {
228: cbAvoidTaggingLocallyModifiedFiles();
229: cbMoveExistingTag();
230: txtTagName();
231: btTag();
232: btBrowse();
233: }
234: }
|