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.*;
045: import java.util.*;
046: import com.sun.rave.designtime.DesignBean;
047: import org.netbeans.jemmy.ComponentChooser;
048: import org.netbeans.jemmy.operators.*;
049: import javax.swing.tree.*;
050:
051: /**
052: * Operator for Outline window.
053: */
054: public class DocumentOutlineOperator extends JComponentOperator {
055: private JTreeOperator structureTree;
056:
057: public DocumentOutlineOperator(ContainerOperator contOper) {
058: super (contOper, new DocumentOutlineChooser());
059: }
060:
061: /** Performs verification by accessing all sub-components */
062: public void verify() {
063: getStructTreeOperator();
064: }
065:
066: /**
067: * Find specified tree path.
068: * @param strTreePath String which represents tree path.
069: * @return TreePath Specified path.
070: */
071: public TreePath findPath(String strTreePath) {
072: verify();
073: return (structureTree.findPath(strTreePath));
074: }
075:
076: /**
077: * Find specified tree path with specified comparator.
078: * @param strTreePath String which represents tree path.
079: * @param nodeIndexes Array of nodes indexes.
080: * @param comparator Comparator to compare tree path with specified string.
081: * @return TreePath Specified path.
082: */
083: public TreePath findPath(String strTreePath, int[] nodeIndexes,
084: Operator.StringComparator comparator) {
085: verify();
086: String[] nodeNames = new Operator.DefaultPathParser("|")
087: .parse(strTreePath);
088: if (nodeIndexes == null) {
089: nodeIndexes = new int[nodeNames.length]; // fill the array in with zero values
090: }
091: System.out
092: .println("+++ DocumentOutlineOperator.findPath(...): nodeNames = "
093: + Arrays.asList(nodeNames));
094: System.out
095: .print("+++ DocumentOutlineOperator.findPath(...): nodeIndexes = [");
096: for (int i = 0; i < nodeIndexes.length; ++i) {
097: System.out.print(nodeIndexes[i]
098: + (i < nodeIndexes.length - 1 ? ", " : ""));
099: }
100: System.out.println("]");
101: TreePath treePath = structureTree.findPath(nodeNames,
102: nodeIndexes, comparator);
103: return treePath;
104: }
105:
106: /**
107: * Click on specified tree path.
108: * @param strTreePath String which represents tree path.
109: */
110: public void clickOnPath(String strTreePath) {
111: structureTree.clickOnPath(findPath(strTreePath));
112: }
113:
114: /**
115: * Expand specified tree path.
116: * @param strTreePath String which represents tree path.
117: */
118: public void expandPath(String strTreePath) {
119: structureTree.expandPath(findPath(strTreePath));
120: }
121:
122: /**
123: * Select specified tree path.
124: * @param strTreePath String which represents tree path.
125: */
126: public void selectPath(String strTreePath) {
127: structureTree.selectPath(findPath(strTreePath));
128: }
129:
130: /**
131: * Click for popup with specified mouse button.
132: * @param i Number of mouse button.
133: */
134: public void clickForPopup(int i) {
135: verify();
136: structureTree.clickForPopup(i);
137: }
138:
139: /**
140: * Get tree which represents structure.
141: * @return JTreeOperator JTree which represents structure.
142: */
143: public JTreeOperator getStructTreeOperator() {
144: if (structureTree == null) {
145: structureTree = new JTreeOperator(this );
146: }
147: return structureTree;
148: }
149:
150: /**
151: * Press button with given title.
152: * @param btName Name of button.
153: */
154: public void pressButton(String btName) {
155: new JButtonOperator(this , btName).pushNoBlock();
156: }
157:
158: /**
159: * Find child with specified name in specified parent.
160: * @param parent Bean where child will be searched.
161: * @param componentName Name of child.
162: * @return DesignBean Found child.
163: */
164: private DesignBean findChild(DesignBean parent, String componentName) {
165: DesignBean lb;
166: if (parent.getInstanceName().equals(componentName)) {
167: return parent;
168: }
169: for (int i = 0; i < parent.getChildBeanCount(); i++) {
170: if ((lb = findChild(parent.getChildBean(i), componentName)) != null) {
171: return lb;
172: }
173: }
174: return null;
175: }
176:
177: /**
178: * Select component with specified name.
179: * @param componentName Name of component.
180: * @return True if component selected.
181: */
182: public boolean selectComponent(String componentName) {
183: DesignBean[] lbs = null;
184: Object rootChild = structureTree.getChildren(structureTree
185: .getRoot())[0];
186: for (int i = 0; i < structureTree.getChildCount(rootChild); i++) {
187: DesignBean lb = (DesignBean) structureTree
188: .getChildren(rootChild)[i];
189: DesignBean res = findChild(lb, componentName);
190: if (res != null) {
191: lbs = new DesignBean[] { res };
192: break;
193: }
194: }
195: if (lbs != null) {
196: TestUtils.wait(500);
197: return true;
198: } else {
199: return false;
200: }
201: }
202:
203: /**
204: * Open page with specified name.
205: * @param page Name of page.
206: */
207: public void openPage(String page) {
208: new JButtonOperator(this , page).clickForPopup();
209: new JPopupMenuOperator()
210: .pushMenu(Bundle
211: .getStringTrimmed(
212: "org.netbeans.modules.visualweb.outline.Bundle",
213: "Open"));
214: }
215:
216: /**
217: * Open source code of page with specified name.
218: * @param page Name of page.
219: */
220: public void openPageSource(String page) {
221: new JButtonOperator(this , page).clickForPopup();
222: new JPopupMenuOperator().pushMenu(Bundle.getStringTrimmed(
223: "org.netbeans.modules.visualweb.outline.Bundle",
224: "ViewBF", new String[] { page }));
225: }
226:
227: public static class DocumentOutlineChooser implements
228: ComponentChooser {
229: public boolean checkComponent(Component comp) {
230: return comp
231: .getClass()
232: .getName()
233: .equalsIgnoreCase(
234: "org.netbeans.modules.visualweb.outline.OutlinePanel");
235: }
236:
237: public String getDescription() {
238: return "Document Outline Operator";
239: }
240: }
241: }
|