KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > web > Util


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.test.web;
21
22 import java.io.File JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import javax.swing.JComboBox JavaDoc;
25 import org.netbeans.jellytools.Bundle;
26 import org.netbeans.jellytools.OptionsOperator;
27 import org.netbeans.jellytools.ProjectsTabOperator;
28 import org.netbeans.jellytools.RuntimeTabOperator;
29 import org.netbeans.jellytools.modules.debugger.BreakpointsWindowOperator;
30 import org.netbeans.jellytools.modules.j2ee.nodes.J2eeServerNode;
31 import org.netbeans.jellytools.nodes.Node;
32 import org.netbeans.jemmy.operators.JComboBoxOperator;
33 import org.netbeans.jemmy.operators.JLabelOperator;
34
35 /**
36  *
37  * @author lm97939
38  */

39 public class Util {
40     
41     /** Creates a new instance of Util */
42     public Util() {
43     }
44     
45     public static String JavaDoc dumpProjectView(String JavaDoc project) {
46         // TODO replace sleep()
47
try { Thread.currentThread().sleep(3000); }
48         catch (InterruptedException JavaDoc e) {}
49         StringBuffer JavaDoc buff = new StringBuffer JavaDoc();
50         Node node = new ProjectsTabOperator().getProjectRootNode(project);
51         dumpNode(node, buff, 0);
52         return buff.toString();
53     }
54     
55     
56     private static void dumpNode(Node node, StringBuffer JavaDoc buff, int level) {
57         for (int i=0; i<level; i++)
58             buff.append(".");
59         buff.append("+ ");
60 // if (!node.isLeaf()) buff.append("+ ");
61
// else buff.append("- ");
62
buff.append(node.getText());
63         if (!node.isLeaf() && node.getText().indexOf('.') < 0) {
64             buff.append(" ");
65             boolean wasCollapsed = node.isCollapsed();
66             buff.append("\n");
67             String JavaDoc nodes[] = node.getChildren();
68             for (int i=0; i<nodes.length; i++) {
69                 //XXX System.out.println("Parent:: " + node.getText() + " - subPath:: " + nodes[i]);
70
Node child = new Node(node, nodes[i]);
71                 // prevents infinite loop in case the nodes[i].equals("");
72
if (child.getPath().equals(node.getPath())) {
73                     //XXX System.out.println("===Continue===");
74
continue;
75                 }
76                 dumpNode(child, buff, level+1);
77             }
78             if (wasCollapsed) node.collapse();
79         } else {
80             buff.append("\n");
81         }
82     }
83     
84     public static String JavaDoc dumpFiles(File JavaDoc file) {
85 // try { Thread.currentThread().sleep(3000); }
86
// catch (InterruptedException e) {}
87
StringBuffer JavaDoc buff = new StringBuffer JavaDoc();
88         dumpFiles(file, buff, 0);
89         return buff.toString();
90     }
91     
92     private static void dumpFiles(File JavaDoc file, StringBuffer JavaDoc buff, int level) {
93          for (int i=0; i<level; i++)
94             buff.append(".");
95          buff.append(file.getName());
96          buff.append("\n");
97          if (file.isDirectory()) {
98              String JavaDoc files[] = file.list();
99              Arrays.sort(files);
100              for (int i=0; i<files.length; i++) {
101                  dumpFiles(new File JavaDoc(file,files[i]), buff, level+1);
102              }
103          }
104     }
105     
106     public static void setSwingBrowser() {
107         // Set Swing HTML Browser as default browser
108
OptionsOperator optionsOper = OptionsOperator.invoke();
109         optionsOper.selectGeneral();
110         // "Web Browser:"
111
String JavaDoc webBrowserLabel = Bundle.getStringTrimmed(
112                 "org.netbeans.modules.options.general.Bundle",
113                 "CTL_Web_Browser");
114         JLabelOperator jloWebBrowser = new JLabelOperator(optionsOper, webBrowserLabel);
115         // "Swing HTML Browser"
116
String JavaDoc swingBrowserLabel = Bundle.getString(
117                 "org.netbeans.core.ui.Bundle",
118                 "Services/Browsers/SwingBrowser.ser");
119         new JComboBoxOperator((JComboBox JavaDoc)jloWebBrowser.getLabelFor()).
120                 selectItem(swingBrowserLabel);
121         optionsOper.ok();
122     }
123     
124     public static void deleteAllBreakpoints() {
125         BreakpointsWindowOperator bwo = BreakpointsWindowOperator.invoke();
126         bwo.deleteAll();
127         bwo.close();
128     }
129     
130     public static void stopTomcat() {
131         getServerNode().stop();;
132     }
133     
134     public static void startTomcat() {
135         getServerNode().start();
136
137     }
138     
139     private static final J2eeServerNode getServerNode() {
140         RuntimeTabOperator.invoke();
141         return new J2eeServerNode("Bundled Tomcat");
142     }
143 }
144
Popular Tags