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.test.web;
043:
044: import java.io.File;
045: import java.util.Arrays;
046: import javax.swing.JComboBox;
047: import org.netbeans.jellytools.Bundle;
048: import org.netbeans.jellytools.MainWindowOperator;
049: import org.netbeans.jellytools.OptionsOperator;
050: import org.netbeans.jellytools.ProjectsTabOperator;
051: import org.netbeans.jellytools.RuntimeTabOperator;
052: import org.netbeans.jellytools.modules.debugger.BreakpointsWindowOperator;
053: import org.netbeans.jellytools.modules.j2ee.nodes.J2eeServerNode;
054: import org.netbeans.jellytools.nodes.Node;
055: import org.netbeans.jemmy.operators.JComboBoxOperator;
056: import org.netbeans.jemmy.operators.JLabelOperator;
057:
058: /**
059: *
060: * @author lm97939
061: */
062: public class Util {
063:
064: /** Creates a new instance of Util */
065: public Util() {
066: }
067:
068: public static String dumpProjectView(String project) {
069: // TODO replace sleep()
070: try {
071: Thread.currentThread().sleep(3000);
072: } catch (InterruptedException e) {
073: }
074: StringBuffer buff = new StringBuffer();
075: Node node = new ProjectsTabOperator()
076: .getProjectRootNode(project);
077: dumpNode(node, buff, 0);
078: return buff.toString();
079: }
080:
081: private static void dumpNode(Node node, StringBuffer buff, int level) {
082: for (int i = 0; i < level; i++)
083: buff.append(".");
084: buff.append("+ ");
085: // if (!node.isLeaf()) buff.append("+ ");
086: // else buff.append("- ");
087: buff.append(node.getText());
088: if (!node.isLeaf() && node.getText().indexOf('.') < 0) {
089: buff.append(" ");
090: boolean wasCollapsed = node.isCollapsed();
091: buff.append("\n");
092: String nodes[] = node.getChildren();
093: for (int i = 0; i < nodes.length; i++) {
094: //XXX System.out.println("Parent:: " + node.getText() + " - subPath:: " + nodes[i]);
095: Node child = new Node(node, nodes[i]);
096: // prevents infinite loop in case the nodes[i].equals("");
097: if (child.getPath().equals(node.getPath())) {
098: //XXX System.out.println("===Continue===");
099: continue;
100: }
101: dumpNode(child, buff, level + 1);
102: }
103: if (wasCollapsed)
104: node.collapse();
105: } else {
106: buff.append("\n");
107: }
108: }
109:
110: public static String dumpFiles(File file) {
111: // try { Thread.currentThread().sleep(3000); }
112: // catch (InterruptedException e) {}
113: StringBuffer buff = new StringBuffer();
114: dumpFiles(file, buff, 0);
115: return buff.toString();
116: }
117:
118: private static void dumpFiles(File file, StringBuffer buff,
119: int level) {
120: for (int i = 0; i < level; i++)
121: buff.append(".");
122: buff.append(file.getName());
123: buff.append("\n");
124: if (file.isDirectory()) {
125: String files[] = file.list();
126: Arrays.sort(files);
127: for (int i = 0; i < files.length; i++) {
128: dumpFiles(new File(file, files[i]), buff, level + 1);
129: }
130: }
131: }
132:
133: public static void setSwingBrowser() {
134: // Set Swing HTML Browser as default browser
135: OptionsOperator optionsOper = OptionsOperator.invoke();
136: optionsOper.selectGeneral();
137: // "Web Browser:"
138: String webBrowserLabel = Bundle.getStringTrimmed(
139: "org.netbeans.modules.options.general.Bundle",
140: "CTL_Web_Browser");
141: JLabelOperator jloWebBrowser = new JLabelOperator(optionsOper,
142: webBrowserLabel);
143: // "Swing HTML Browser"
144: String swingBrowserLabel = Bundle.getString(
145: "org.netbeans.core.ui.Bundle",
146: "Services/Browsers/SwingBrowser.ser");
147: new JComboBoxOperator((JComboBox) jloWebBrowser.getLabelFor())
148: .selectItem(swingBrowserLabel);
149: optionsOper.ok();
150: }
151:
152: public static void deleteAllBreakpoints() {
153: BreakpointsWindowOperator bwo = BreakpointsWindowOperator
154: .invoke();
155: bwo.deleteAll();
156: bwo.close();
157: }
158:
159: public static void stopTomcat() {
160: getServerNode().stop();
161: ;
162: }
163:
164: public static void startTomcat() {
165: getServerNode().start();
166:
167: }
168:
169: private static final J2eeServerNode getServerNode() {
170: RuntimeTabOperator.invoke();
171: return new J2eeServerNode("Bundled Tomcat");
172: }
173:
174: public static final void cleanStatusBar() {
175: MainWindowOperator.getDefault().setStatusText("STATUS CLEANED");
176: }
177: }
|