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-2007 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.modules.visualweb.gravy;
043:
044: import java.awt.Component;
045: import java.awt.Container;
046: import javax.swing.JFrame;
047: import org.netbeans.jemmy.ComponentChooser;
048: import org.netbeans.jemmy.ComponentSearcher;
049: import org.netbeans.jemmy.JemmyProperties;
050: import org.netbeans.jemmy.operators.JCheckBoxOperator;
051: import org.netbeans.jemmy.operators.JFrameOperator;
052: import org.netbeans.jemmy.operators.JLabelOperator;
053: import org.netbeans.jemmy.operators.JButtonOperator;
054:
055: /**
056: * This class is used in automated tests, developed for Creator 2.0/2.1, for launching
057: * and shutting down of an application server, included into these products.
058: */
059: public class StartStopDialogOperator extends JFrameOperator {
060: JCheckBoxOperator autoHide;
061:
062: /**
063: * Creates a new instance of this class.
064: */
065: public StartStopDialogOperator() {
066: super (new StartStopDialogFinder());
067: copyEnvironment(Util.getMainWindow());
068: getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout",
069: 600000);
070: getTimeouts().setTimeout(
071: "ComponentOperator.WaitComponentTimeout", 600000);
072: }
073:
074: /**
075: * Initializes and returns a checkbox "Autohide"
076: * @return an object JCheckBoxOperator
077: */
078: public JCheckBoxOperator chbAutoHide() {
079: if (autoHide == null) {
080: autoHide = new JCheckBoxOperator(this ,
081: "Automatically close this window when finished");
082: }
083: return (autoHide);
084: }
085:
086: /**
087: * Marks or unmarks a checkbox "Auto Hide".
088: * @param isAutoHide boolean value, which defines if a checkbox "Auto Hide"
089: * is marked or not.
090: */
091: public void setAutoHide(boolean isAutoHide) {
092: chbAutoHide().changeSelection(isAutoHide);
093: }
094:
095: /**
096: * Waits until the required string appears in the dialog.
097: * @param status string, which is waited in the dialog
098: * @return an object JLabelOperator
099: */
100: public JLabelOperator waitStatus(String status) {
101: return (new JLabelOperator(this , status));
102: }
103:
104: /**
105: * Waits until the string "Completed" appears in the dialog.
106: * @return an object JLabelOperator
107: */
108: public JLabelOperator waitCompleted() {
109: return (waitStatus("Completed"));
110: }
111:
112: /**
113: * Launches an application server.
114: */
115: public void start(String action) {
116: new JButtonOperator(this , "Start Server").push();
117: }
118:
119: /**
120: * Shuts an application server down.
121: */
122: public void stop(String action) {
123: new JButtonOperator(this , "Stop Server").push();
124: }
125:
126: /**
127: * Inner class, which is used for searching of a "Start/Stop-dialog" in
128: * Creator's IDE.
129: */
130: public static class StartStopDialogFinder implements
131: ComponentChooser {
132: /**
133: * Searches a component "Start/Stop-dialog" in Creator's IDE
134: * @return true if dialog is found, otherwise - false.
135: */
136: public boolean checkComponent(Component comp) {
137: ComponentSearcher searcher = new ComponentSearcher(
138: (Container) comp);
139: searcher.setOutput(JemmyProperties.getCurrentOutput()
140: .createErrorOutput());
141: return (comp instanceof JFrame && searcher
142: .findComponent(new ComponentChooser() {
143: public boolean checkComponent(Component comp) {
144: return (comp.getClass().getName()
145: .startsWith("Server Status"));
146: }
147:
148: public String getDescription() {
149: return ("ProgressUI");
150: }
151: }) != null);
152: }
153:
154: public String getDescription() {
155: return ("StartStop dialog");
156: }
157: }
158: }
|