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 javax.swing.tree.TreePath;
045:
046: import org.netbeans.jemmy.operators.*;
047: import org.netbeans.jemmy.*;
048: import org.netbeans.jellytools.*;
049: import org.netbeans.modules.visualweb.gravy.actions.ShowFilesAction;
050: import org.netbeans.modules.visualweb.gravy.actions.ShowProjectsAction;
051: import org.netbeans.modules.visualweb.gravy.actions.BuildProjectAction;
052:
053: import java.awt.*;
054:
055: /** Provides access to Projects window and it's components
056: * @author Alexey Butenko
057: *
058: */
059: public class ProjectNavigatorOperator extends
060: org.netbeans.jellytools.ProjectsTabOperator {
061:
062: public ProjectNavigatorOperator() {
063: super ();
064: }
065:
066: /** Select Path
067: * @param treePath - String path to select
068: */
069: public void selectPath(String treePath) {
070: makeComponentVisible();
071: TreePath path = tree().findPath(treePath);
072: tree().selectPath(path);
073: }
074:
075: /** Opens Projects window
076: */
077: public static ProjectNavigatorOperator showProjectNavigator() {
078: new ShowProjectsAction().perform();
079: new QueueTool().waitEmpty();
080: Util.wait(500);
081: return (new ProjectNavigatorOperator());
082: }
083:
084: /**
085: * Select Node
086: * @param node - Node to select
087: */
088: public static void selectNode(String node) {
089: ProjectNavigatorOperator projectNav = ProjectNavigatorOperator
090: .showProjectNavigator();
091: projectNav.makeComponentVisible();
092: JTreeOperator tree = projectNav.tree();
093: tree.selectPath(tree.findPath(node));
094: }
095:
096: /** Build Project
097: * @param prjName - Name of the project to build
098: */
099: public void buildProject(String prjName) {
100: makeComponentVisible();
101: pressPopupItemOnNode(prjName, Bundle.getStringTrimmed(
102: "com.sun.rave.project.actions.Bundle",
103: "LBL_BuildProject"));
104: }
105:
106: /** Opens Files Tab
107: */
108: public static JTreeOperator switchToFiles() {
109: new ShowFilesAction().perform();
110:
111: ContainerOperator containerOperator = new ContainerOperator(
112: waitTopComponent(null, Bundle.getStringTrimmed(
113: "org.netbeans.modules.project.ui.Bundle",
114: "LBL_projectTab_tc"), 0,
115: new ComponentChooser() {
116: public boolean checkComponent(Component comp) {
117: return comp.getClass().getName()
118: .endsWith("ProjectTab");
119: }
120:
121: public String getDescription() {
122: return "org.netbeans.modules.projects.ui.ProjectTab";
123: }
124: }));
125: Util.wait(1000);
126: JTreeOperator treeOperator = new JTreeOperator(
127: containerOperator);
128: return (treeOperator);
129: }
130:
131: /** Opens Projects Tab
132: */
133: public static ProjectNavigatorOperator switchToProjects() {
134: new ShowProjectsAction().perform();
135: return (new ProjectNavigatorOperator());
136: }
137:
138: /** Press popup item on node
139: * @param path - click for popup on
140: * @param menuItem - item to click in popup window
141: * @param comparator - StringComparator
142: */
143: public static ProjectNavigatorOperator pressPopupItemOnNode(
144: String path, String menuItem, StringComparator comparator) {
145: try {
146: ProjectNavigatorOperator projectNav = ProjectNavigatorOperator
147: .showProjectNavigator();
148: TestUtils.wait(4000);
149: //projectNav.makeComponentVisible();
150: JTreeOperator tree = projectNav.tree();
151: JPopupMenuOperator popup;
152: if (path.equals("ROOT")) {
153: popup = new JPopupMenuOperator(tree
154: .callPopupOnPath(new TreePath(tree.getRoot())));
155: } else {
156: popup = new JPopupMenuOperator(tree
157: .callPopupOnPath(tree.findPath(path, "|")));
158: }
159: new QueueTool().waitEmpty();
160: Util.wait(1000);
161:
162: if (comparator != null) {
163: popup.setComparator(comparator);
164: }
165:
166: popup.pushMenuNoBlock(menuItem, "|");
167: new QueueTool().waitEmpty();
168: Util.wait(1000);
169: return projectNav;
170: } catch (Exception e) {
171: System.out
172: .println("Exception occured in pressPopupItemOnPath function");
173: e.printStackTrace();
174: return null;
175: }
176: }
177:
178: /** Press popup item on node
179: * @param path - click for popup on
180: * @param menuItem - item to click in popup window
181: */
182: public static ProjectNavigatorOperator pressPopupItemOnNode(
183: String path, String menuItem) {
184: return pressPopupItemOnNode(path, menuItem, null);
185: }
186:
187: /**
188: * Add a new page
189: * @param projectName project that a page will be created at
190: * @param pageName page will be created
191: */
192: public void addWebPage(String projectName, String pageName) {
193: String treeNodePath = projectName
194: + "|"
195: + Bundle.getStringTrimmed(
196: "org.netbeans.modules.visualweb.gravy.Bundle",
197: "ProjectNode_WebPages");
198: String popupMenuItem = Bundle.getStringTrimmed(
199: "org.netbeans.modules.visualweb.gravy.Bundle",
200: "ProjectMenuItem_New")
201: + "|"
202: + Bundle.getStringTrimmed(
203: "org.netbeans.modules.visualweb.gravy.Bundle",
204: "ProjectMenuItem_Page");
205: pressPopupItemOnNode(treeNodePath, popupMenuItem);
206:
207: JDialogOperator dialog = new JDialogOperator(Bundle
208: .getStringTrimmed(
209: "org.netbeans.modules.visualweb.gravy.Bundle",
210: "Dialog_NewPage"));
211: Util.wait(1000);
212:
213: JTextFieldOperator textfieldFolderName = new JTextFieldOperator(
214: dialog, 0);
215: textfieldFolderName.setText(pageName);
216: new JButtonOperator(dialog, Bundle.getStringTrimmed(
217: "org.netbeans.modules.visualweb.gravy.Bundle",
218: "Button_Finish")).pushNoBlock();
219: //dialog.waitClosed();
220: Util.wait(1000);
221:
222: }
223:
224: /**
225: * Open a jsp page of current project
226: * @param webPageName
227: */
228: public void openWebPage(String projectName, String webPageName) {
229: String treeNodePath = projectName
230: + "|"
231: + Bundle.getStringTrimmed(
232: "org.netbeans.modules.visualweb.gravy.Bundle",
233: "ProjectNode_WebPages")
234: + "|"
235: + webPageName
236: + Bundle.getStringTrimmed(
237: "org.netbeans.modules.visualweb.gravy.Bundle",
238: "WebPage_extension");
239: String popupMenuItem = Bundle.getStringTrimmed(
240: "org.netbeans.modules.visualweb.gravy.Bundle",
241: "ProjectMenuItem_Open");
242: pressPopupItemOnNode(treeNodePath, popupMenuItem);
243: }
244: }
|