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:
042: package org.netbeans.jellytools;
043:
044: import javax.swing.JDialog;
045: import org.netbeans.jellytools.JellyVersion;
046: import org.netbeans.jemmy.operators.JButtonOperator;
047: import org.netbeans.jemmy.operators.JDialogOperator;
048:
049: /**
050: * Handle generic NetBeans dialog. The dialog can include Yes, No, OK,
051: * Cancel, Close or Help buttons. The dialog is identified by its title.
052: */
053: public class NbDialogOperator extends JDialogOperator {
054:
055: private JButtonOperator _btYes;
056: private JButtonOperator _btNo;
057: private JButtonOperator _btOK;
058: private JButtonOperator _btCancel;
059: private JButtonOperator _btClose;
060: private JButtonOperator _btHelp;
061:
062: static {
063: // Checks if you run on correct jemmy version. Writes message to jemmy log if not.
064: JellyVersion.checkJemmyVersion();
065: }
066:
067: /** Waits until dialog with requested title is found. Title is compared
068: * on partial match and case non-sensitive. If dialog is not found, runtime
069: * exception is thrown.
070: * @param title title of window
071: */
072: public NbDialogOperator(String title) {
073: super (title);
074: }
075:
076: /** Created NbDialogOperator with given dialog
077: * @param dialog JDialog instance */
078: public NbDialogOperator(JDialog dialog) {
079: super (dialog);
080: }
081:
082: /** Returns operator of "Yes" button.
083: * @return JButtonOperator instance of "Yes" button
084: */
085: public JButtonOperator btYes() {
086: if (_btYes == null) {
087: String yesCaption = Bundle.getString(
088: "org.netbeans.core.windows.services.Bundle",
089: "YES_OPTION_CAPTION");
090: _btYes = new JButtonOperator(this , yesCaption);
091: }
092: return _btYes;
093: }
094:
095: /** Returns operator of "No" button.
096: * @return JButtonOperator instance of "No" button
097: */
098: public JButtonOperator btNo() {
099: if (_btNo == null) {
100: String noCaption = Bundle.getString(
101: "org.netbeans.core.windows.services.Bundle",
102: "NO_OPTION_CAPTION");
103: _btNo = new JButtonOperator(this , noCaption);
104: }
105: return _btNo;
106: }
107:
108: /** Returns operator of "OK" button.
109: * @return JButtonOperator instance of "OK" button
110: */
111: public JButtonOperator btOK() {
112: if (_btOK == null) {
113: String oKCaption = Bundle.getString(
114: "org.netbeans.core.windows.services.Bundle",
115: "OK_OPTION_CAPTION");
116: _btOK = new JButtonOperator(this , oKCaption);
117: }
118: return _btOK;
119: }
120:
121: /** Returns operator of "Cancel" button.
122: * @return JButtonOperator instance of "Cancel" button
123: */
124: public JButtonOperator btCancel() {
125: if (_btCancel == null) {
126: String cancelCaption = Bundle.getString(
127: "org.netbeans.core.windows.services.Bundle",
128: "CANCEL_OPTION_CAPTION");
129: _btCancel = new JButtonOperator(this , cancelCaption);
130: }
131: return _btCancel;
132: }
133:
134: /** Returns operator of "Close" button.
135: * @return JButtonOperator instance of "Close" button
136: */
137: public JButtonOperator btClose() {
138: if (_btClose == null) {
139: String closeCaption = Bundle.getString(
140: "org.netbeans.core.windows.services.Bundle",
141: "CLOSED_OPTION_CAPTION");
142: _btClose = new JButtonOperator(this , closeCaption);
143: }
144: return _btClose;
145: }
146:
147: /** Returns operator of "Help" button.
148: * @return JButtonOperator instance of "Help" button
149: */
150: public JButtonOperator btHelp() {
151: if (_btHelp == null) {
152: String helpCaption = Bundle.getStringTrimmed(
153: "org.netbeans.core.windows.services.Bundle",
154: "HELP_OPTION_CAPTION");
155: _btHelp = new JButtonOperator(this , helpCaption);
156: }
157: return _btHelp;
158: }
159:
160: /** Pushes "Yes" button. */
161: public void yes() {
162: btYes().push();
163: }
164:
165: /** Pushes "No" button. */
166: public void no() {
167: btNo().push();
168: }
169:
170: /** Pushes "OK" button. */
171: public void ok() {
172: btOK().push();
173: }
174:
175: /** Pushes "Cancel" button. */
176: public void cancel() {
177: btCancel().push();
178: }
179:
180: /** Pushes "Close" button. Using {@link JDialogOperator#close() close()}
181: * will close dialog default way like on demand of a window manager.
182: */
183: public void closeByButton() {
184: btClose().push();
185: }
186:
187: /** Pushes "Help" button. */
188: public void help() {
189: btHelp().push();
190: }
191: }
|