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.model.project;
043:
044: import org.netbeans.modules.visualweb.gravy.Bundle;
045: import org.netbeans.modules.visualweb.gravy.TestUtils;
046: import org.netbeans.modules.visualweb.gravy.ProjectNavigatorOperator;
047:
048: import org.netbeans.jemmy.JemmyException;
049: import org.netbeans.jemmy.operators.Operator;
050: import org.netbeans.jemmy.operators.JButtonOperator;
051: import org.netbeans.jemmy.operators.JDialogOperator;
052: import org.netbeans.jemmy.operators.JTextFieldOperator;
053:
054: import javax.swing.tree.TreePath;
055:
056: /**
057: * Class for web page folders included in Project.
058: */
059:
060: public class WebPageFolder extends Folder {
061:
062: private final static String bundle = "org.netbeans.modules.visualweb.gravy.model.project.Bundle";
063: private final static String popupNew = Bundle.getStringTrimmed(
064: bundle, "New");
065: private final static String popupFolder = Bundle.getStringTrimmed(
066: bundle, "Folder");
067: private final static String popupNewFolder = popupNew + "|"
068: + popupFolder + "...";
069: private final static String dlgNewFolder = popupNew + " "
070: + popupFolder;
071: private final static String popupPage = Bundle.getStringTrimmed(
072: Bundle.getStringTrimmed(bundle, "JSFResBundle"), Bundle
073: .getStringTrimmed(bundle, "Page"));
074: private final static String popupNewPage = popupNew + "|"
075: + popupPage + "...";
076: private final static String dlgNewPage = popupNew + " " + popupPage;
077: private final static String btnFinish = Bundle.getStringTrimmed(
078: bundle, "FinishButton");
079: private final static String btnCancel = Bundle.getStringTrimmed(
080: bundle, "CancelButton");
081:
082: private SourceFolder sf;
083:
084: WebPageFolder(TreePath path, String name, ProjectEntry parent) {
085: super (path, name, parent);
086: if (parent instanceof RootEntry) {
087: RootEntry root = (RootEntry) parent;
088: SourceFolder srf = new SourceFolder(new TreePath(root
089: .getProject().getName()), root.sourcePackagesName,
090: root);
091: SourceFolder sf = new SourceFolder(new TreePath(root
092: .getProject().getName()
093: + "|" + root.sourcePackagesName), root.getProject()
094: .getName().toLowerCase(), srf);
095: srf.childList.add(sf);
096: root.childList.add(srf);
097: this .sf = sf;
098: } else
099: this .sf = ((WebPageFolder) parent).getSourceFolder()
100: .addSourceSubFolder(name);
101: }
102:
103: /**
104: * Add new web page to folder.
105: * @param name Name of new web page.
106: * @return Added web page.
107: */
108: public WebPage addWebPage(String name) {
109: if (getWebPage(name) == null) {
110: ProjectNavigatorOperator prjNav = ProjectNavigatorOperator
111: .showProjectNavigator();
112: TestUtils.wait(4000);
113: String full_path = this .path.toString().substring(1,
114: this .path.toString().length() - 1)
115: + "|" + this .name;
116: try {
117: prjNav
118: .pressPopupItemOnNode(full_path, popupNewPage,
119: new Operator.DefaultStringComparator(
120: true, true));
121: } catch (Exception e) {
122: throw new JemmyException(popupNewPage
123: + " item in popup menu of " + full_path
124: + " node can't be found!", e);
125: }
126: TestUtils.wait(1000);
127: try {
128: JDialogOperator jdo = new JDialogOperator(dlgNewPage);
129: new JTextFieldOperator(jdo, 0).setText(name);
130: TestUtils.wait(500);
131: new JButtonOperator(jdo, btnFinish).pushNoBlock();
132: } catch (Exception e) {
133: throw new JemmyException("Error occurs in "
134: + dlgNewPage + " dialog!", e);
135: }
136: TestUtils.wait(1000);
137: WebPage newWebPage = new WebPage(new TreePath(full_path),
138: name, this );
139: childList.add(newWebPage);
140: return newWebPage;
141: } else
142: return getWebPage(name);
143: }
144:
145: /**
146: * Get web page with specified name.
147: * @param name Name of web page.
148: * @return Web page with specified name.
149: */
150: public WebPage getWebPage(String name) {
151: for (int i = 0; i < childList.size(); i++) {
152: if ((childList.get(i) instanceof WebPage)
153: && ((WebPage) childList.get(i)).getName().equals(
154: name))
155: return ((WebPage) childList.get(i));
156: }
157: if (getParent() instanceof RootEntry && name.equals("Page1")) {
158: String full_path = this .path.toString().substring(1,
159: this .path.toString().length() - 1)
160: + "|" + this .name;
161: WebPage newWebPage = new WebPage(new TreePath(full_path),
162: name, this );
163: childList.add(newWebPage);
164: return newWebPage;
165: }
166: return null;
167: }
168:
169: /**
170: * Add web page folder to folder.
171: * @param name Name of web page folder.
172: * @return Added web page folder.
173: */
174: public WebPageFolder addWebPageSubFolder(String name) {
175: ProjectNavigatorOperator prjNav = ProjectNavigatorOperator
176: .showProjectNavigator();
177: TestUtils.wait(1000);
178: String full_path = this .path.toString().substring(1,
179: this .path.toString().length() - 1)
180: + "|" + this .name;
181: try {
182: prjNav.pressPopupItemOnNode(full_path, popupNewFolder,
183: new Operator.DefaultStringComparator(true, true));
184: } catch (Exception e) {
185: throw new JemmyException(popupNewFolder
186: + " item in popup menu of " + full_path
187: + " node can't be found!", e);
188: }
189: TestUtils.wait(1000);
190: try {
191: JDialogOperator jdo = new JDialogOperator(dlgNewFolder);
192: new JTextFieldOperator(jdo, 0).setText(name);
193: TestUtils.wait(500);
194: new JButtonOperator(jdo, btnFinish).pushNoBlock();
195: } catch (Exception e) {
196: throw new JemmyException("Error occurs in " + dlgNewFolder
197: + " dialog!", e);
198: }
199: TestUtils.wait(1000);
200: WebPageFolder newWebPageFolder = new WebPageFolder(
201: new TreePath(full_path), name, this );
202: childList.add(newWebPageFolder);
203: return newWebPageFolder;
204: }
205:
206: /**
207: * Get web page subfolder with specified name.
208: * @param name Name of web page subfolder.
209: * @return Web page folder with specified name.
210: */
211: public WebPageFolder getWebPageSubFolder(String name) {
212: for (int i = 0; i < childList.size(); i++) {
213: if (childList.get(i) instanceof WebPageFolder
214: && ((WebPageFolder) childList.get(i)).getName()
215: .equals(name))
216: return ((WebPageFolder) childList.get(i));
217: }
218: return null;
219: }
220:
221: /**
222: * Get source folder for this web page folder.
223: * @return Source folder for this web page folder.
224: */
225: public SourceFolder getSourceFolder() {
226: return sf;
227: }
228: }
|